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 "fsresult.hpp"
5 #include "libfilezilla.hpp"
6 #include "time.hpp"
7 
8 #ifdef FZ_WINDOWS
9 #include "glue/windows.hpp"
10 #else
11 #include <dirent.h>
12 #endif
13 
17 namespace fz {
18 
25 class FZ_PUBLIC_SYMBOL local_filesys final
26 {
27 public:
28  local_filesys() = default;
29  ~local_filesys();
30 
31  local_filesys(local_filesys const&) = delete;
32  local_filesys& operator=(local_filesys const&) = delete;
33 
34  local_filesys(local_filesys &&) noexcept;
35  local_filesys& operator=(local_filesys &&) noexcept;
36 
38  enum type {
39  unknown = -1,
40  file,
41  dir,
42  link
43  };
44 
46  static char const path_separator;
47 
51  static inline bool is_separator(wchar_t c) {
52 #ifdef FZ_WINDOWS
53  return c == '/' || c == '\\';
54 #else
55  return c == '/';
56 #endif
57  }
58 
62  static type get_file_type(native_string const& path, bool follow_links = false);
63 
72  static type get_file_info(native_string const& path, bool &is_link, int64_t* size, datetime* modification_time, int* mode, bool follow_links = true);
73 
75  static int64_t get_size(native_string const& path, bool *is_link = nullptr);
76 
80  result begin_find_files(native_string path, bool dirs_only = false, bool query_symlink_targets = true);
81 
82 #if FZ_WINDOWS
88  result begin_find_files(HANDLE dir, bool dirs_only = false, bool query_symlink_targets = true);
89 #else
95  result begin_find_files(int fd, bool dirs_only = false, bool query_symlink_targets = true);
96 #endif
97 
100 
110  bool get_next_file(native_string& name, bool &is_link, type & t, int64_t* size, datetime* modification_time, int* mode);
111 
114 
115  static datetime get_modification_time(native_string const& path);
116  static bool set_modification_time(native_string const& path, const datetime& t);
117 
120 
121 private:
122 #ifdef FZ_WINDOWS
123  bool FZ_PRIVATE_SYMBOL check_buffer();
124  std::vector<unsigned char> buffer_;
125  unsigned char* cur_{};
126  HANDLE dir_{INVALID_HANDLE_VALUE};
127 #else
128  DIR* dir_{};
129 #endif
130 
131  // State for directory enumeration
132  bool dirs_only_{};
133  bool query_symlink_targets_{true};
134 };
135 
137 {
140  normal,
141 
143  cur_user,
144 
147 };
148 
166 result FZ_PUBLIC_SYMBOL mkdir(native_string const& absolute_path, bool recurse, mkdir_permissions permissions = mkdir_permissions::normal, native_string * last_created = nullptr);
167 
172 result FZ_PUBLIC_SYMBOL remove_dir(native_string const& absolute_path);
173 
188 result FZ_PUBLIC_SYMBOL rename_file(native_string const& source, native_string const& dest, bool allow_copy = true);
189 
190 }
191 
192 #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:29
This class can be used to enumerate the contents of local directories and to query the metadata of fi...
Definition: local_filesys.hpp:26
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.
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.
result begin_find_files(HANDLE dir, bool dirs_only=false, bool query_symlink_targets=true)
Begin enumerating a directory represented by a HANDLE.
static char const path_separator
The system's preferred path separator.
Definition: local_filesys.hpp:46
type
Types of files. While 'everything is a file', a filename can refer to a file proper,...
Definition: local_filesys.hpp:38
static bool is_separator(wchar_t c)
Checks whether given character is a path separator.
Definition: local_filesys.hpp:51
static native_string get_link_target(native_string const &path)
Get the target path of a symbolic link.
result begin_find_files(native_string path, bool dirs_only=false, bool query_symlink_targets=true)
Begins enumerating a directory.
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: fsresult.hpp:26
fz::result and fz::rwresult wrappers for dealing with file system errors.
Sets some global macros and further includes string.hpp.
The namespace used by libfilezilla.
Definition: apply.hpp:17
mkdir_permissions
Definition: local_filesys.hpp:137
@ 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:34
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.
result remove_dir(native_string const &absolute_path)
Removes sempty directory.
Assorted classes dealing with time.