diff options
Diffstat (limited to 'zen/file_access.cpp')
-rw-r--r-- | zen/file_access.cpp | 52 |
1 files changed, 37 insertions, 15 deletions
diff --git a/zen/file_access.cpp b/zen/file_access.cpp index 11f61291..c2072a26 100644 --- a/zen/file_access.cpp +++ b/zen/file_access.cpp @@ -309,6 +309,28 @@ VolumeId zen::getVolumeId(const Zstring& itemPath) //throw FileError } +Zstring zen::getTempFolderPath() //throw FileError +{ +#ifdef ZEN_WIN + const DWORD bufSize = MAX_PATH + 1; //MSDN: maximum value + std::vector<wchar_t> buf(bufSize); + const DWORD rv = ::GetTempPath(bufSize, //_In_ DWORD nBufferLength, + &buf[0]); //_Out_ LPTSTR lpBuffer + if (rv == 0) + THROW_LAST_FILE_ERROR(_("Cannot get process information."), L"GetTempPath"); + if (rv >= bufSize) + throw FileError(_("Cannot get process information."), L"GetTempPath: insufficient buffer size."); + return &buf[0]; + +#elif defined ZEN_LINUX || defined ZEN_MAC + const char* buf = ::getenv("TMPDIR"); //no extended error reporting + if (!buf) + throw FileError(_("Cannot get process information."), L"getenv: TMPDIR not found."); + return buf; +#endif +} + + bool zen::removeFile(const Zstring& filePath) //throw FileError { #ifdef ZEN_WIN @@ -738,9 +760,9 @@ void setFileTimeByHandle(HANDLE hFile, //throw FileError //add more meaningful message: FAT accepts only a subset of the NTFS date range #ifdef ZEN_WIN_VISTA_AND_LATER - if (ec == ERROR_INVALID_PARAMETER && isFatDrive(hFile)) + if (ec == ERROR_INVALID_PARAMETER && isFatDrive(hFile)) #else - if (ec == ERROR_INVALID_PARAMETER && isFatDrive(filePath)) + if (ec == ERROR_INVALID_PARAMETER && isFatDrive(filePath)) #endif { //let's not fail due to an invalid creation time on FAT: http://www.freefilesync.org/forum/viewtopic.php?t=2278 @@ -961,7 +983,7 @@ void setWriteTimeNative(const Zstring& filePath, std::int64_t modTime, ProcSymli //=> using open()/futimens() for regular files and utimensat(AT_SYMLINK_NOFOLLOW) for symlinks is consistent with "cp" and "touch"! if (procSl == ProcSymlink::FOLLOW) { - const int fdFile = ::open(filePath.c_str(), O_WRONLY, 0); //"if O_CREAT is not specified, then mode is ignored" + const int fdFile = ::open(filePath.c_str(), O_WRONLY); if (fdFile == -1) { if (errno == EACCES) //bullshit, access denied even with 0777 permissions! => utimes should work! @@ -1099,16 +1121,16 @@ void zen::setFileTime(const Zstring& filePath, std::int64_t modTime, ProcSymlink } -bool zen::supportsPermissions(const Zstring& dirpath) //throw FileError +bool zen::supportsPermissions(const Zstring& dirPath) //throw FileError { #ifdef ZEN_WIN const DWORD bufferSize = MAX_PATH + 1; std::vector<wchar_t> buffer(bufferSize); - if (!::GetVolumePathName(dirpath.c_str(), //__in LPCTSTR lpszFileName, + if (!::GetVolumePathName(dirPath.c_str(), //__in LPCTSTR lpszFileName, &buffer[0], //__out LPTSTR lpszVolumePathName, bufferSize)) //__in DWORD cchBufferLength - THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot read file attributes of %x."), L"%x", fmtPath(dirpath)), L"GetVolumePathName"); + THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot read file attributes of %x."), L"%x", fmtPath(dirPath)), L"GetVolumePathName"); const Zstring volumePath = appendSeparator(&buffer[0]); @@ -1121,7 +1143,7 @@ bool zen::supportsPermissions(const Zstring& dirpath) //throw FileError &fsFlags, //__out_opt LPDWORD lpFileSystemFlags, nullptr, //__out LPTSTR lpFileSystemNameBuffer, 0)) //__in DWORD nFileSystemNameSize - THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot read file attributes of %x."), L"%x", fmtPath(dirpath)), L"GetVolumeInformation"); + THROW_LAST_FILE_ERROR(replaceCpy(_("Cannot read file attributes of %x."), L"%x", fmtPath(dirPath)), L"GetVolumeInformation"); return (fsFlags & FILE_PERSISTENT_ACLS) != 0; @@ -1422,12 +1444,12 @@ void makeDirectoryRecursivelyImpl(const Zstring& directory) //FileError } -void zen::makeDirectoryRecursively(const Zstring& dirpath) //throw FileError +void zen::makeDirectoryRecursively(const Zstring& dirPath) //throw FileError { //remove trailing separator (even for C:\ root directories) - const Zstring dirFormatted = endsWith(dirpath, FILE_NAME_SEPARATOR) ? - beforeLast(dirpath, FILE_NAME_SEPARATOR, IF_MISSING_RETURN_NONE) : - dirpath; + const Zstring dirFormatted = endsWith(dirPath, FILE_NAME_SEPARATOR) ? + beforeLast(dirPath, FILE_NAME_SEPARATOR, IF_MISSING_RETURN_NONE) : + dirPath; makeDirectoryRecursivelyImpl(dirFormatted); //FileError } @@ -1727,10 +1749,10 @@ bool canCopyAsSparse(DWORD fileAttrSource, Function getTargetFsFlags) //throw () DWORD targetFsFlags = 0; if (!getTargetFsFlags(targetFsFlags)) - { - assert(false); - return false; - } + { + assert(false); + return false; + } assert(targetFsFlags != 0); return (targetFsFlags & FILE_SUPPORTS_SPARSE_FILES) != 0; |