libfilezilla
local_filesys.hpp
Go to the documentation of this file.
1#ifndef LIBFILEZILLA_LOCAL_FILESYS_HEADER
2#define LIBFILEZILLA_LOCAL_FILESYS_HEADER
3
4#include "libfilezilla.hpp"
5#include "time.hpp"
6
7#ifdef FZ_WINDOWS
8#include "glue/windows.hpp"
9#else
10#include <dirent.h>
11#endif
12
16namespace fz {
17
21class FZ_PUBLIC_SYMBOL result final
22{
23public:
24 enum error {
25 ok,
26
29
32
35
38
40 other
41 };
42
43 explicit operator bool() const { return error_ == 0; }
44
45 error error_{};
46};
47
54class FZ_PUBLIC_SYMBOL local_filesys final
55{
56public:
57 local_filesys() = default;
59
60 local_filesys(local_filesys const&) = delete;
61 local_filesys& operator=(local_filesys const&) = delete;
62
64 enum type {
65 unknown = -1,
66 file,
67 dir,
68 link
69 };
70
72 static char const path_separator;
73
77 static inline bool is_separator(wchar_t c) {
78#ifdef FZ_WINDOWS
79 return c == '/' || c == '\\';
80#else
81 return c == '/';
82#endif
83 }
84
88 static type get_file_type(native_string const& path, bool follow_links = false);
89
98 static type get_file_info(native_string const& path, bool &is_link, int64_t* size, datetime* modification_time, int* mode, bool follow_links = true);
99
101 static int64_t get_size(native_string const& path, bool *is_link = nullptr);
102
106 result begin_find_files(native_string path, bool dirs_only = false);
107
110
120 bool get_next_file(native_string& name, bool &is_link, type & t, int64_t* size, datetime* modification_time, int* mode);
121
124
125 static datetime get_modification_time(native_string const& path);
126 static bool set_modification_time(native_string const& path, const datetime& t);
127
130
131private:
132
133#ifdef FZ_WINDOWS
134 WIN32_FIND_DATA m_find_data{};
135 HANDLE m_hFind{INVALID_HANDLE_VALUE};
136 native_string m_find_path;
137 bool has_next_{};
138#else
139 DIR* dir_{};
140#endif
141
142 // State for directory enumeration
143 bool dirs_only_{};
144};
145
147{
150 normal,
151
153 cur_user,
154
157};
158
176result FZ_PUBLIC_SYMBOL mkdir(native_string const& absolute_path, bool recurse, mkdir_permissions permissions = mkdir_permissions::normal, native_string * last_created = nullptr);
177
192result FZ_PUBLIC_SYMBOL rename_file(native_string const& source, native_string const& dest, bool allow_copy = true);
193
194}
195
196#endif
Represents a point of time in wallclock, tracking the timestamps accuracy/precision.
Definition: time.hpp:41
Lean class for file access.
Definition: file.hpp:26
This class can be used to enumerate the contents of local directories and to query the metadata of fi...
Definition: local_filesys.hpp:55
static type get_file_info(native_string const &path, bool &is_link, int64_t *size, datetime *modification_time, int *mode, bool follow_links=true)
Gets the info for the passed arguments.
static type get_file_type(native_string const &path, bool follow_links=false)
get_file_type return the type of the passed path.
bool get_next_file(native_string &name, bool &is_link, type &t, int64_t *size, datetime *modification_time, int *mode)
Gets the next file in the directory. Call until it returns false.
result begin_find_files(native_string path, bool dirs_only=false)
Begins enumerating a directory.
static int64_t get_size(native_string const &path, bool *is_link=nullptr)
Gets size of file, returns -1 on error.
void end_find_files()
Ends enumerating files. Automatically called in the destructor.
static char const path_separator
The system's preferred path separator.
Definition: local_filesys.hpp:72
type
Types of files. While 'everything is a file', a filename can refer to a file proper,...
Definition: local_filesys.hpp:64
static bool is_separator(wchar_t c)
Checks whether given character is a path separator.
Definition: local_filesys.hpp:77
static native_string get_link_target(native_string const &path)
Get the target path of a symbolic link.
bool get_next_file(native_string &name)
Gets the next file in the directory. Call until it returns false.
Small class to return filesystem errors.
Definition: local_filesys.hpp:22
error
Definition: local_filesys.hpp:24
@ noperm
Permission denied.
Definition: local_filesys.hpp:28
@ nofile
Requested file does not exist or is not a file.
Definition: local_filesys.hpp:31
@ nospace
Out of disk space.
Definition: local_filesys.hpp:37
@ nodir
Requested dir does not exist or is not a dir.
Definition: local_filesys.hpp:34
Sets some global macros and further includes string.hpp.
The namespace used by libfilezilla.
Definition: apply.hpp:17
mkdir_permissions
Definition: local_filesys.hpp:147
@ cur_user_and_admins
Only current user and administrators.
@ cur_user
Only current user.
std::wstring native_string
A string in the system's native character type and encoding. Note: This typedef changes depending on...
Definition: string.hpp:33
result rename_file(native_string const &source, native_string const &dest, bool allow_copy=true)
Rename/move the passed file or directory.
result mkdir(native_string const &absolute_path, bool recurse, mkdir_permissions permissions=mkdir_permissions::normal, native_string *last_created=nullptr)
Creates directory if it doesn't yet exist.
Assorted classes dealing with time.