Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
filesystem.hpp
Go to the documentation of this file.
1#pragma once
2#include <utility>
3#include <memory>
4
5#include <fc/string.hpp>
7#include <fc/fwd.hpp>
8
9namespace boost {
10 namespace filesystem {
11 class path;
12 class directory_iterator;
13 class recursive_directory_iterator;
14 }
15}
16
17
18namespace fc {
28 class path {
29 public:
30 path();
31 ~path();
32 path( const boost::filesystem::path& );
33 path( const std::string& p );
35 path(const std::wstring& p);
36 path( const char* );
37 path( const path& p );
38 path( path&& p );
39 path& operator =( const path& );
40 path& operator =( path&& );
41
42 path& operator /=( const fc::path& );
43 friend path operator /( const fc::path& p, const fc::path& );
44 friend bool operator ==( const fc::path& p, const fc::path& );
45 friend bool operator !=( const fc::path& p, const fc::path& );
46 friend bool operator < ( const fc::path& p, const fc::path& );
47
48 operator boost::filesystem::path& ();
49 operator const boost::filesystem::path& ()const;
50
51 void replace_extension( const fc::path& e );
52 fc::path stem()const;
53 fc::path extension()const;
54 fc::path filename()const;
55 fc::path parent_path()const;
56 std::string string()const;
57 std::string generic_string()const;
61 std::string preferred_string() const;
62
63 std::wstring wstring() const;
64 std::wstring generic_wstring() const;
65 std::wstring preferred_wstring() const;
66
72 std::string to_native_ansi_path() const;
73
79 std::string windows_string()const;
80
81 bool is_relative()const;
82 bool is_absolute()const;
83 bool empty() const;
84
85 static char separator_char;
86
87 private:
88 #ifdef _WIN64
90 #else
92 #endif
93 };
94
95 namespace detail
96 {
98 {
99 public:
101 _path(p)
102 {
103 }
104 const path* operator->() const
105 {
106 return &_path;
107 }
108 private:
109 path _path;
110 };
111 }
112
114 public:
115 directory_iterator( const fc::path& p );
118
119 fc::path operator*()const;
123
124 friend bool operator==( const directory_iterator&, const directory_iterator& );
125 friend bool operator!=( const directory_iterator&, const directory_iterator& );
126 private:
128 };
147
148 bool exists( const path& p );
149 bool is_directory( const path& p );
150 bool is_regular_file( const path& p );
151 void create_directories( const path& p );
152 void remove_all( const path& p );
153 path absolute( const path& p );
154 path make_relative(const path& from, const path& to);
155 path canonical( const path& p );
156 uint64_t file_size( const path& p );
157 uint64_t directory_size( const path& p );
158 bool remove( const path& p );
159 void copy( const path& from, const path& to );
160 void rename( const path& from, const path& to );
161 void resize_file( const path& file, size_t s );
162
163 // setuid, setgid not implemented.
164 // translates octal permission like 0755 to S_ stuff defined in sys/stat.h
165 // no-op on Windows.
166 void chmod( const path& p, int perm );
167
168 void create_hard_link( const path& from, const path& to );
169
172
174 const path& home_path();
175
179 const path& app_path();
180
182 const fc::path& current_path();
183
184 class variant;
185 void to_variant( const fc::path&, fc::variant& );
186 void from_variant( const fc::variant& , fc::path& );
187
188 template<> struct get_typename<path> { static const char* name() { return "path"; } };
189
194 {
195 public:
196 inline ~temp_file_base() { remove(); }
197 inline operator bool() const { return _path.has_value(); }
198 inline bool operator!() const { return !_path.has_value(); }
199 const fc::path& path() const;
200 void remove();
201 void release();
202 protected:
203 typedef std::optional<fc::path> path_t;
204 inline temp_file_base(const path_t& path) : _path(path) {}
205 inline temp_file_base(path_t&& path) : _path(std::move(path)) {}
207 };
208
213 {
214 public:
215 temp_file(temp_file&& other);
216 temp_file& operator=(temp_file&& other);
217 temp_file(const fc::path& tempFolder = fc::temp_directory_path(), bool create = false);
218 };
219
224 {
225 public:
228 temp_directory(const fc::path& tempFolder = fc::temp_directory_path());
229 };
230
231
232#if !defined(__APPLE__)
233 // this code is known to work on linux and windows. It may work correctly on mac,
234 // or it may need slight tweaks or extra includes. It's disabled now to avoid giving
235 // a false sense of security.
236# define FC_HAS_SIMPLE_FILE_LOCK
237#endif
238#ifdef FC_HAS_SIMPLE_FILE_LOCK
251 {
252 public:
253 simple_lock_file(const path& lock_file_path);
255 bool try_lock();
256 void unlock();
257 private:
258 class impl;
259 std::unique_ptr<impl> my;
260 };
261#endif // FC_HAS_SIMPLE_FILE_LOCK
262
263}
264
const mie::Vuint & p
Definition bn.cpp:27
const path * operator->() const
directory_iterator & operator++()
friend bool operator!=(const directory_iterator &, const directory_iterator &)
fc::path operator*() const
friend bool operator==(const directory_iterator &, const directory_iterator &)
detail::path_wrapper operator->() const
Used to forward declare value types.
Definition fwd.hpp:11
wraps boost::filesystem::path to provide platform independent path manipulation.
std::wstring generic_wstring() const
std::wstring preferred_wstring() const
fc::path parent_path() const
std::string windows_string() const
replaces '/' with '\' in the result of generic_string()
fc::path filename() const
std::wstring wstring() const
bool empty() const
static char separator_char
fc::path stem() const
friend path operator/(const fc::path &p, const fc::path &)
path & operator=(const path &)
friend bool operator==(const fc::path &p, const fc::path &)
std::string preferred_string() const
std::string to_native_ansi_path() const
std::string string() const
fc::path extension() const
std::string generic_string() const
path & operator/=(const fc::path &)
bool is_absolute() const
friend bool operator!=(const fc::path &p, const fc::path &)
friend bool operator<(const fc::path &p, const fc::path &)
void replace_extension(const fc::path &e)
bool is_relative() const
friend bool operator!=(const recursive_directory_iterator &, const recursive_directory_iterator &)
friend bool operator==(const recursive_directory_iterator &, const recursive_directory_iterator &)
recursive_directory_iterator & operator++()
simple_lock_file(const path &lock_file_path)
temp_directory(temp_directory &&other)
temp_directory & operator=(temp_directory &&other)
temp_file_base(path_t &&path)
const fc::path & path() const
std::optional< fc::path > path_t
bool operator!() const
temp_file_base(const path_t &path)
temp_file(temp_file &&other)
temp_file & operator=(temp_file &&other)
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
namespace sysio::chain
Definition authority.cpp:3
void rename(const path &from, const path &to)
bool remove(const path &p)
const path & app_path()
bool exists(const path &p)
void remove_all(const path &p)
const path & home_path()
bool is_regular_file(const path &p)
const fc::path & current_path()
void create_directories(const path &p)
void copy(const path &from, const path &to)
path unique_path()
void create_hard_link(const path &from, const path &to)
path make_relative(const path &from, const path &to)
uint64_t file_size(const path &p)
bool is_directory(const path &p)
void resize_file(const path &file, size_t s)
uint64_t directory_size(const path &p)
path absolute(const path &p)
path canonical(const path &p)
void from_variant(const fc::variant &v, sysio::chain::chain_id_type &cid)
void chmod(const path &p, int perm)
void to_variant(const sysio::chain::shared_public_key &var, fc::variant &vo)
Definition authority.cpp:4
path temp_directory_path()
Definition name.hpp:106
unsigned __int64 uint64_t
Definition stdint.h:136
static const char * name()
char * s