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 #include "file.hpp"
8 
9 #ifdef FZ_WINDOWS
10 #include "glue/windows.hpp"
11 #else
12 #include <dirent.h>
13 #endif
14 
18 namespace fz {
19 
26 class FZ_PUBLIC_SYMBOL local_filesys final
27 {
28 public:
29  local_filesys() = default;
30  ~local_filesys();
31 
32  local_filesys(local_filesys const&) = delete;
33  local_filesys& operator=(local_filesys const&) = delete;
34 
35  local_filesys(local_filesys &&) noexcept;
36  local_filesys& operator=(local_filesys &&) noexcept;
37 
39  enum type {
40  unknown = -1,
41  file,
42  dir,
43  link
44  };
45 
47  static char const path_separator;
48 
52  static inline bool is_separator(wchar_t c) {
53 #ifdef FZ_WINDOWS
54  return c == '/' || c == '\\';
55 #else
56  return c == '/';
57 #endif
58  }
59 
63  static type get_file_type(native_string const& path, bool follow_links = false);
64 
73  static type get_file_info(native_string const& path, bool& is_link, int64_t* size, datetime* modification_time, int* mode, bool follow_links = true);
74 
83  static result get_file_info(native_string const& path, bool& is_link, type& type, int64_t* size, datetime* modification_time, int* mode, bool follow_links = true);
84 
86  static int64_t get_size(native_string const& path, bool *is_link = nullptr);
87 
91  result begin_find_files(native_string path, bool dirs_only = false, bool query_symlink_targets = true);
92 
98  result begin_find_files(file::file_t fd, bool dirs_only = false, bool query_symlink_targets = true);
99 
101  bool get_next_file(native_string& name);
102 
112  bool get_next_file(native_string& name, bool &is_link, type & t, int64_t* size, datetime* modification_time, int* mode);
113 
115  void end_find_files();
116 
117  static datetime get_modification_time(native_string const& path);
118  static result set_modification_time(native_string const& path, const datetime& t);
119 
123  static native_string get_link_target(native_string const& path);
124 
129  static native_string get_final_link_target(native_string const& path);
130 
132  file::file_t fd();
133 
134 private:
135 #ifdef FZ_WINDOWS
136  bool FZ_PRIVATE_SYMBOL check_buffer();
137  std::vector<unsigned char> buffer_;
138  unsigned char* cur_{};
139  HANDLE dir_{INVALID_HANDLE_VALUE};
140 #else
141  DIR* dir_{};
142 #endif
143 
144  // State for directory enumeration
145  bool dirs_only_{};
146  bool query_symlink_targets_{true};
147 };
148 
150 {
153  normal,
154 
156  cur_user,
157 
160 };
161 
181 result FZ_PUBLIC_SYMBOL mkdir(native_string const& absolute_path, bool recurse, mkdir_permissions permissions = mkdir_permissions::normal, native_string * last_created = nullptr);
182 
187 result FZ_PUBLIC_SYMBOL remove_dir(native_string const& absolute_path, bool missing_dir_is_error);
188 
203 result FZ_PUBLIC_SYMBOL rename_file(native_string const& source, native_string const& dest, bool allow_copy = true);
204 
205 }
206 
207 #endif
Only current user and administrators.
result rename_file(native_string const &source, native_string const &dest, bool allow_copy=true)
Rename/move the passed file or directory.
fz::result and fz::rwresult wrappers for dealing with file system errors.
File handling.
Represents a point of time in wallclock, tracking the timestamps accuracy/precision.
Definition: time.hpp:40
Assorted classes dealing with time.
Small class to return filesystem errors.
Definition: fsresult.hpp:25
static char const path_separator
The system's preferred path separator.
Definition: local_filesys.hpp:47
This class can be used to enumerate the contents of local directories and to query the metadata of fi...
Definition: local_filesys.hpp:26
std::wstring native_string
A string in the system's native character type and encoding. Note: This typedef changes depending on...
Definition: string.hpp:69
The namespace used by libfilezilla.
Definition: apply.hpp:17
Lean class for file access.
Definition: file.hpp:28
mkdir_permissions
Definition: local_filesys.hpp:149
static bool is_separator(wchar_t c)
Checks whether given character is a path separator.
Definition: local_filesys.hpp:52
Sets some global macros and further includes string.hpp.
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.
type
Types of files. While 'everything is a file', a filename can refer to a file proper, a directory or a symbolic link.
Definition: local_filesys.hpp:39
result remove_dir(native_string const &absolute_path, bool missing_dir_is_error)
Removes empty directory.