diff options
author | B. Stack <bgstack15@gmail.com> | 2023-09-13 13:49:38 -0400 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2023-09-13 13:49:38 -0400 |
commit | 7ed2158034ef5c26eed7fed9aa3c118d79a06fa8 (patch) | |
tree | 979e6628193f88d2140e722a3893321904869896 /zen/file_access.cpp | |
parent | add extra_log.h (diff) | |
download | FreeFileSync-7ed2158034ef5c26eed7fed9aa3c118d79a06fa8.tar.gz FreeFileSync-7ed2158034ef5c26eed7fed9aa3c118d79a06fa8.tar.bz2 FreeFileSync-7ed2158034ef5c26eed7fed9aa3c118d79a06fa8.zip |
add upstream 13.013.0
Diffstat (limited to 'zen/file_access.cpp')
-rw-r--r-- | zen/file_access.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/zen/file_access.cpp b/zen/file_access.cpp index 4ce66acf..af19df87 100644 --- a/zen/file_access.cpp +++ b/zen/file_access.cpp @@ -273,6 +273,18 @@ void zen::removeDirectoryPlainRecursion(const Zstring& dirPath) //throw FileErro namespace { +std::wstring generateMoveErrorMsg(const Zstring& pathFrom, const Zstring& pathTo) +{ + if (getParentFolderPath(pathFrom) == getParentFolderPath(pathTo)) //pure "rename" + return replaceCpy(replaceCpy(_("Cannot rename %x to %y."), + L"%x", fmtPath(pathFrom)), + L"%y", fmtPath(getItemName(pathTo))); + else //"move" or "move + rename" + return trimCpy(replaceCpy(replaceCpy(_("Cannot move %x to %y."), + L"%x", L'\n' + fmtPath(pathFrom)), + L"%y", L'\n' + fmtPath(pathTo))); +} + /* Usage overview: (avoid circular pattern!) moveAndRenameItem() --> moveAndRenameFileSub() @@ -283,7 +295,7 @@ namespace //wrapper for file system rename function: void moveAndRenameFileSub(const Zstring& pathFrom, const Zstring& pathTo, bool replaceExisting) //throw FileError, ErrorMoveUnsupported, ErrorTargetExisting { - auto getErrorMsg = [&] { return replaceCpy(replaceCpy(_("Cannot move file %x to %y."), L"%x", L'\n' + fmtPath(pathFrom)), L"%y", L'\n' + fmtPath(pathTo)); }; + auto getErrorMsg = [&] { return generateMoveErrorMsg(pathFrom, pathTo); }; //rename() will never fail with EEXIST, but always (atomically) overwrite! //=> equivalent to SetFileInformationByHandle() + FILE_RENAME_INFO::ReplaceIfExists or ::MoveFileEx() + MOVEFILE_REPLACE_EXISTING @@ -338,6 +350,8 @@ void zen::moveAndRenameItem(const Zstring& pathFrom, const Zstring& pathTo, bool } + + namespace { void setWriteTimeNative(const Zstring& itemPath, const timespec& modTime, ProcSymlink procSl) //throw FileError @@ -714,10 +728,7 @@ FileCopyResult zen::copyNewFile(const Zstring& sourceFile, const Zstring& target macOS: https://freefilesync.org/forum/viewtopic.php?t=356 */ setWriteTimeNative(targetFile, sourceInfo.st_mtim, ProcSymlink::follow); //throw FileError } - catch (const FileError& e) - { - errorModTime = FileError(e.toString()); //avoid slicing - } + catch (const FileError& e) { errorModTime = e; /*might slice derived class?*/ } return { |