10 #include <boost/config.hpp>
11 #include <boost/filesystem.hpp>
18 #include <sys/types.h>
21 # ifdef FC_HAS_SIMPLE_FILE_LOCK
32 std::string utf8_string;
34 variant_output = utf8_string;
39 std::wstring wide_string;
41 path_output =
path(wide_string);
45 char path::separator_char =
static_cast<char>(boost::filesystem::path(
"/").make_preferred().native()[0]);
71 *_p = std::move( *p._p );
89 path::operator boost::filesystem::path& () {
92 path::operator
const boost::filesystem::path& ()
const {
96 return _p->generic_string();
101 return boost::filesystem::path(*_p).make_preferred().string();
106 return _p->wstring();
111 return _p->generic_wstring();
116 return boost::filesystem::path(*_p).make_preferred().wstring();
124 const size_t maxPath = 32*1024;
125 std::vector<wchar_t> short_path;
126 short_path.resize(maxPath + 1);
128 wchar_t* buffer = short_path.data();
129 DWORD res = GetShortPathNameW(
path.c_str(), buffer, maxPath);
133 std::string filePath;
143 std::string result = _p->generic_string();
144 std::replace(result.begin(), result.end(),
'/',
'\\');
152 return _p->filename();
155 _p->replace_extension(e);
158 return _p->extension();
164 return _p->parent_path();
181 return *r._p == *l._p;
184 return *r._p != *l._p;
202 return *r._p == *l._p;
205 return *r._p != *l._p;
243 boost::system::error_code ec;
247 FC_THROW(
"Copy from ${srcfile} to ${dstfile} failed because ${code} : ${message}",
248 (
"srcfile",f)(
"dstfile",t)(
"code",ec.value())(
"message",ec.message()) );
250 }
catch ( boost::system::system_error& e ) {
251 FC_THROW(
"Copy from ${srcfile} to ${dstfile} failed because ${reason}",
252 (
"srcfile",f)(
"dstfile",t)(
"reason",std::string(e.what()) ) );
254 FC_THROW(
"Copy from ${srcfile} to ${dstfile} failed",
263 catch ( boost::system::system_error& e )
265 FC_THROW(
"Resize file '${f}' to size ${s} failed: ${reason}",
266 (
"f",f)(
"s",t)(
"reason", std::string(e.what()) ) );
270 FC_THROW(
"Resize file '${f}' to size ${s} failed: ${reason}",
282 ((perm & 0400) ? S_IRUSR : 0)
283 | ((perm & 0200) ? S_IWUSR : 0)
284 | ((perm & 0100) ? S_IXUSR : 0)
286 | ((perm & 0040) ? S_IRGRP : 0)
287 | ((perm & 0020) ? S_IWGRP : 0)
288 | ((perm & 0010) ? S_IXGRP : 0)
290 | ((perm & 0004) ? S_IROTH : 0)
291 | ((perm & 0002) ? S_IWOTH : 0)
292 | ((perm & 0001) ? S_IXOTH : 0)
297 FC_THROW(
"chmod operation failed on ${p}", (
"p",p) );
305 }
catch ( boost::system::system_error& er ) {
311 "Rename from ${srcfile} to ${dstfile} failed due to ${reason}, trying to copy then remove",
312 (
"srcfile",f)(
"dstfile",t)(
"reason",std::string(er.what())) );
315 FC_THROW(
"Rename from ${srcfile} to ${dstfile} failed",
323 FC_THROW(
"Unable to create hard link from '${from}' to '${to}'",
349 boost::filesystem::path ret;
350 boost::filesystem::path::const_iterator itrFrom(a_From.begin()), itrTo(a_To.begin());
352 for( boost::filesystem::path::const_iterator toEnd( a_To.end() ), fromEnd( a_From.end() ) ; itrFrom != fromEnd && itrTo != toEnd && *itrFrom == *itrTo; ++itrFrom, ++itrTo );
354 for( boost::filesystem::path::const_iterator fromEnd( a_From.end() ); itrFrom != fromEnd; ++itrFrom ) {
355 if( (*itrFrom) !=
"." )
359 for (; itrTo != a_To.end(); ++itrTo)
388 _path = std::move(other._path);
413 _path = std::move(other._path);
422 FC_THROW(
"Temporary directory has been released." );
454 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &access_token))
455 FC_ASSERT(
false,
"Unable to open an access token for the current process");
456 wchar_t user_profile_dir[MAX_PATH];
457 DWORD user_profile_dir_len =
sizeof(user_profile_dir);
458 BOOL success = GetUserProfileDirectoryW(access_token, user_profile_dir, &user_profile_dir_len);
459 CloseHandle(access_token);
461 FC_ASSERT(
false,
"Unable to get the user profile directory");
462 return fc::path(std::wstring(user_profile_dir));
464 char* home = getenv(
"HOME" );
465 if(
nullptr == home )
467 struct passwd* pwd = getpwuid(getuid());
470 return fc::path( std::string( pwd->pw_dir ) );
472 FC_ASSERT( home !=
nullptr,
"The HOME environment variable is not set" );
474 return fc::path( std::string(home) );
483 static fc::path appdir = [](){
return home_path() /
"Library" /
"Application Support"; }();
484 #elif defined( WIN32 )
486 wchar_t app_data_dir[MAX_PATH];
488 if (!SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, app_data_dir)))
489 FC_ASSERT(
false,
"Unable to get the current AppData directory");
490 return fc::path(std::wstring(app_data_dir));
501 return appCurrentPath;