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 "private/windows.hpp"
9 #else
10 #include <dirent.h>
11 #endif
12 
16 namespace fz {
17 
21 class FZ_PUBLIC_SYMBOL result final
22 {
23 public:
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 
54 class FZ_PUBLIC_SYMBOL local_filesys final
55 {
56 public:
57  local_filesys() = default;
58  ~local_filesys();
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 
109  bool get_next_file(native_string& name);
110 
120  bool get_next_file(native_string& name, bool &is_link, type & t, int64_t* size, datetime* modification_time, int* mode);
121 
123  void end_find_files();
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 
129  static native_string get_link_target(native_string const& path);
130 
131 private:
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 
164 result FZ_PUBLIC_SYMBOL mkdir(native_string const& absolute_path, bool recurse, bool current_user_only = false, native_string * last_created = nullptr);
165 
166 }
167 
168 #endif
fz::local_filesys::type
type
Types of files. While 'everything is a file', a filename can refer to a file proper,...
Definition: local_filesys.hpp:64
fz::file
Lean class for file access.
Definition: file.hpp:25
fz::mkdir
result mkdir(native_string const &absolute_path, bool recurse, bool current_user_only=false, native_string *last_created=nullptr)
Creates directory if it doesn't yet exist.
fz::result::nodir
@ nodir
Requested dir does not exist or is not a dir.
Definition: local_filesys.hpp:34
fz::result::nospace
@ nospace
Out of disk space.
Definition: local_filesys.hpp:37
fz::result::nofile
@ nofile
Requested file does not exist or is not a file.
Definition: local_filesys.hpp:31
fz::local_filesys::path_separator
static const char path_separator
The system's preferred path separator.
Definition: local_filesys.hpp:72
fz::native_string
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
fz::result
Small class to return filesystem errors.
Definition: local_filesys.hpp:21
fz::result::error
error
Definition: local_filesys.hpp:24
time.hpp
Assorted classes dealing with time.
fz::result::noperm
@ noperm
Permission denied.
Definition: local_filesys.hpp:28
libfilezilla.hpp
Sets some global macros and further includes string.hpp.
fz::local_filesys::is_separator
static bool is_separator(wchar_t c)
Checks whether given character is a path separator.
Definition: local_filesys.hpp:77
fz::local_filesys
This class can be used to enumerate the contents of local directories and to query the metadata of fi...
Definition: local_filesys.hpp:54
fz::datetime
Represents a point of time in wallclock, tracking the timestamps accuracy/precision.
Definition: time.hpp:40
fz
The namespace used by libfilezilla.
Definition: apply.hpp:17