diff --git a/app/actions.cpp b/app/actions.cpp index d8c91ddd..0e0166ad 100644 --- a/app/actions.cpp +++ b/app/actions.cpp @@ -83,7 +83,6 @@ namespace { public: //! C'tor Timestamp() = default; - //! Read the timestamp of a file int read(const std::string& path); //! Read the timestamp from a broken-down time in buffer \em tm. int read(struct tm* tm); @@ -2046,14 +2045,7 @@ namespace { std::cout << std::endl; } - // Workaround for MinGW rename which does not overwrite existing files - remove(newPath.c_str()); - if (std::rename(path.c_str(), newPath.c_str()) == -1) { - std::cerr << Params::instance().progname() << ": " << _("Failed to rename") << " " << path << " " << _("to") - << " " << newPath << ": " << Exiv2::strError() << "\n"; - return 1; - } - + fs::rename(path, newPath); return 0; } diff --git a/src/basicio.cpp b/src/basicio.cpp index 3cd52c47..f38436ae 100644 --- a/src/basicio.cpp +++ b/src/basicio.cpp @@ -34,18 +34,22 @@ #include "image_int.hpp" // + standard includes -#include -#include -#include -#include // std::memcpy +#include // _O_BINARY in FileIo::FileIo +#include // for stat, chmod +#include // for stat, chmod + #include -#include // write the temporary file -#include // _O_BINARY in FileIo::FileIo -#include // for remove, rename -#include // for alloc, realloc, free -#include // timestamp for the name of temporary file -#include // for stat, chmod -#include // for stat, chmod +#include // for remove, rename +#include // for alloc, realloc, free +#include // std::memcpy +#include // timestamp for the name of temporary file +#include +#include // write the temporary file +#include +#include +#include + +namespace fs = std::filesystem; #ifdef EXV_HAVE_SYS_MMAN_H # include // for mmap and munmap @@ -535,9 +539,7 @@ namespace Exiv2 { BOOL ret = pfcn_ReplaceFileA(pf, fileIo->path().c_str(), NULL, REPLACEFILE_IGNORE_MERGE_ERRORS, NULL, NULL); if (ret == 0) { if (GetLastError() == ERROR_FILE_NOT_FOUND) { - if (::rename(fileIo->path().c_str(), pf) == -1) { - throw Error(kerFileRenameFailed, fileIo->path(), pf, strError()); - } + fs::rename(fileIo->path().c_str(), pf); ::remove(fileIo->path().c_str()); } else { @@ -549,9 +551,7 @@ namespace Exiv2 { if (fileExists(pf) && ::remove(pf) != 0) { throw Error(kerCallFailed, pf, strError(), "::remove"); } - if (::rename(fileIo->path().c_str(), pf) == -1) { - throw Error(kerFileRenameFailed, fileIo->path(), pf, strError()); - } + fs::rename(fileIo->path().c_str(), pf); ::remove(fileIo->path().c_str()); } } @@ -559,9 +559,7 @@ namespace Exiv2 { if (fileExists(pf) && ::remove(pf) != 0) { throw Error(kerCallFailed, pf, strError(), "::remove"); } - if (::rename(fileIo->path().c_str(), pf) == -1) { - throw Error(kerFileRenameFailed, fileIo->path(), pf, strError()); - } + fs::rename(fileIo->path().c_str(), pf); ::remove(fileIo->path().c_str()); #endif // Check permissions of new file @@ -1130,11 +1128,8 @@ namespace Exiv2 { ReplaceStringInPlace(currentPath, XPathIo::TEMP_FILE_EXT, XPathIo::GEN_FILE_EXT); setPath(currentPath); - // rename the file tempFilePath_ = path(); - if (rename(currentPath.c_str(), tempFilePath_.c_str()) != 0) { - // printf("Warning: Failed to rename the temp file. \n"); - } + fs::rename(currentPath, tempFilePath_); isTemp_ = false; // call super class method FileIo::transfer(src);