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 
37  other
38  };
39 
40  explicit operator bool() const { return error_ == 0; }
41 
42  error error_{};
43 };
44 
51 class FZ_PUBLIC_SYMBOL local_filesys final
52 {
53 public:
54  local_filesys() = default;
55  ~local_filesys();
56 
57  local_filesys(local_filesys const&) = delete;
58  local_filesys& operator=(local_filesys const&) = delete;
59 
61  enum type {
62  unknown = -1,
63  file,
64  dir,
65  link
66  };
67 
69  static char const path_separator;
70 
74  static inline bool is_separator(wchar_t c) {
75 #ifdef FZ_WINDOWS
76  return c == '/' || c == '\\';
77 #else
78  return c == '/';
79 #endif
80  }
81 
85  static type get_file_type(native_string const& path, bool follow_links = false);
86 
95  static type get_file_info(native_string const& path, bool &is_link, int64_t* size, datetime* modification_time, int* mode, bool follow_links = true);
96 
98  static int64_t get_size(native_string const& path, bool *is_link = nullptr);
99 
103  result begin_find_files(native_string path, bool dirs_only = false);
104 
107 
117  bool get_next_file(native_string& name, bool &is_link, type & t, int64_t* size, datetime* modification_time, int* mode);
118 
121 
122  static datetime get_modification_time(native_string const& path);
123  static bool set_modification_time(native_string const& path, const datetime& t);
124 
127 
128 private:
129 
130 #ifdef FZ_WINDOWS
131  WIN32_FIND_DATA m_find_data{};
132  HANDLE m_hFind{INVALID_HANDLE_VALUE};
133  native_string m_find_path;
134  bool has_next_{};
135 #else
136  DIR* dir_{};
137 #endif
138 
139  // State for directory enumeration
140  bool dirs_only_{};
141 };
142 
161 result FZ_PUBLIC_SYMBOL mkdir(native_string const& absolute_path, bool recurse, bool current_user_only = false, native_string * last_created = nullptr);
162 
163 }
164 
165 #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:61
fz::file
Lean class for file access.
Definition: file.hpp:26
fz::local_filesys::get_file_type
static type get_file_type(native_string const &path, bool follow_links=false)
get_file_type return the type of the passed path.
fz::local_filesys::end_find_files
void end_find_files()
Ends enumerating files. Automatically called in the destructor.
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::local_filesys::get_next_file
bool get_next_file(native_string &name)
Gets the next file in the directory. Call until it returns false.
fz::local_filesys::get_next_file
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.
fz::result::nodir
@ nodir
Requested dir does not exist or is not a dir.
Definition: local_filesys.hpp:34
fz::local_filesys::begin_find_files
result begin_find_files(native_string path, bool dirs_only=false)
Begins enumerating a directory.
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 char const path_separator
The system's preferred path separator.
Definition: local_filesys.hpp:69
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::local_filesys::get_link_target
static native_string get_link_target(native_string const &path)
Get the target path of a symbolic link.
fz::result
Small class to return filesystem errors.
Definition: local_filesys.hpp:22
fz::local_filesys::get_size
static int64_t get_size(native_string const &path, bool *is_link=nullptr)
Gets size of file, returns -1 on error.
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:74
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:52
fz::datetime
Represents a point of time in wallclock, tracking the timestamps accuracy/precision.
Definition: time.hpp:41
fz
The namespace used by libfilezilla.
Definition: apply.hpp:17
fz::local_filesys::get_file_info
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.