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 
24 class FZ_PUBLIC_SYMBOL local_filesys final
25 {
26 public:
27  local_filesys() = default;
28  ~local_filesys();
29 
30  local_filesys(local_filesys const&) = delete;
31  local_filesys& operator=(local_filesys const&) = delete;
32 
34  enum type {
35  unknown = -1,
36  file,
37  dir,
38  link
39  };
40 
42  static char const path_separator;
43 
47  static inline bool is_separator(wchar_t c) {
48 #ifdef FZ_WINDOWS
49  return c == '/' || c == '\\';
50 #else
51  return c == '/';
52 #endif
53  }
54 
58  static type get_file_type(native_string const& path, bool follow_links = false);
59 
62  static type get_file_info(native_string const& path, bool &is_link, int64_t* size, datetime* modification_time, int* mode);
63 
65  static int64_t get_size(native_string const& path, bool *is_link = nullptr);
66 
70  bool begin_find_files(native_string path, bool dirs_only = false);
71 
73  bool get_next_file(native_string& name);
74 
78  bool get_next_file(native_string& name, bool &is_link, bool &is_dir, int64_t* size, datetime* modification_time, int* mode);
79 
81  void end_find_files();
82 
83  static datetime get_modification_time(native_string const& path);
84  static bool set_modification_time(native_string const& path, const datetime& t);
85 
87  static native_string get_link_target(native_string const& path);
88 
89 private:
90 #ifndef FZ_WINDOWS
91  void alloc_path_buffer(char const* filename); // Ensures m_raw_path is large enough to hold path and filename
92 #endif
93 
94  // State for directory enumeration
95  bool dirs_only_{};
96 
97 #ifdef FZ_WINDOWS
98  WIN32_FIND_DATA m_find_data{};
99  HANDLE m_hFind{INVALID_HANDLE_VALUE};
100  bool has_next_{};
101  native_string m_find_path;
102 #else
103  char* m_raw_path{};
104  char* m_file_part{}; // Points into m_raw_path past the trailing slash of the path part
105  int m_buffer_length{};
106  DIR* dir_{};
107 #endif
108 };
109 
110 }
111 
112 #endif
Represents a point of time in wallclock, tracking the timestamps accuracy/precision.
Definition: time.hpp:40
Assorted classes dealing with time.
static char const path_separator
The system&#39;s preferred path separator.
Definition: local_filesys.hpp:42
This class can be used to enumerate the contents of local directories and to query the metadata of fi...
Definition: local_filesys.hpp:24
std::wstring native_string
A string in the system&#39;s native character type and encoding. Note: This typedef changes depending on...
Definition: string.hpp:32
The namespace used by libfilezilla.
Definition: apply.hpp:16
Lean class for file access.
Definition: file.hpp:25
static bool is_separator(wchar_t c)
Checks whether given character is a path separator.
Definition: local_filesys.hpp:47
Sets some global macros and further includes string.hpp.
type
Types of files. While &#39;everything is a file&#39;, a filename can refer to a file proper, a directory or a symbolic link.
Definition: local_filesys.hpp:34