From 0a9525044d01ae8978d0a37ceee5f9e90e8910b5 Mon Sep 17 00:00:00 2001 From: Jan Kevin Dick Date: Wed, 27 Nov 2019 14:44:55 +0100 Subject: [PATCH] Added Fix to put Options inside the File Impl Classes --- Foundation/include/Poco/File.h | 2 +- Foundation/include/Poco/File_UNIX.h | 5 +++++ Foundation/include/Poco/File_WIN32U.h | 5 +++++ Foundation/src/File_UNIX.cpp | 4 ++-- Foundation/src/File_WIN32U.cpp | 4 ++-- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Foundation/include/Poco/File.h b/Foundation/include/Poco/File.h index 7014dc03f..d62be6fcd 100644 --- a/Foundation/include/Poco/File.h +++ b/Foundation/include/Poco/File.h @@ -73,7 +73,7 @@ public: enum Options /// Options for File Copy/Movement { - OPT_FAIL_ON_OVERWRITE = 0x01 + OPT_FAIL_ON_OVERWRITE = OPT_FAIL_ON_OVERWRITE_IMPL }; File(); diff --git a/Foundation/include/Poco/File_UNIX.h b/Foundation/include/Poco/File_UNIX.h index c595f524f..ced4a9d52 100644 --- a/Foundation/include/Poco/File_UNIX.h +++ b/Foundation/include/Poco/File_UNIX.h @@ -27,6 +27,11 @@ namespace Poco { class FileImpl { protected: + + enum Options { + OPT_FAIL_ON_OVERWRITE_IMPL = 0x01 + }; + typedef UInt64 FileSizeImpl; FileImpl(); diff --git a/Foundation/include/Poco/File_WIN32U.h b/Foundation/include/Poco/File_WIN32U.h index 9d3d77a39..d77e4db8f 100644 --- a/Foundation/include/Poco/File_WIN32U.h +++ b/Foundation/include/Poco/File_WIN32U.h @@ -28,6 +28,11 @@ namespace Poco { class Foundation_API FileImpl { protected: + + enum Options { + OPT_FAIL_ON_OVERWRITE_IMPL = 0x01 + }; + typedef UInt64 FileSizeImpl; FileImpl(); diff --git a/Foundation/src/File_UNIX.cpp b/Foundation/src/File_UNIX.cpp index f6cdf754f..4cccb623e 100644 --- a/Foundation/src/File_UNIX.cpp +++ b/Foundation/src/File_UNIX.cpp @@ -341,7 +341,7 @@ void FileImpl::copyToImpl(const std::string& path, int options) const } const long blockSize = st.st_blksize; int dd; - if (options == 1) { + if (options & OPT_FAIL_ON_OVERWRITE_IMPL) { dd = open(path.c_str(), O_CREAT | O_TRUNC | O_EXCL | O_WRONLY, st.st_mode); } else { dd = open(path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, st.st_mode); @@ -386,7 +386,7 @@ void FileImpl::renameToImpl(const std::string& path, int options) struct stat st; - if (stat(path.c_str(), &st) == 0 && options == 1) + if (stat(path.c_str(), &st) == 0 && (options & OPT_FAIL_ON_OVERWRITE_IMPL)) throw FileExistsException(path, EEXIST); if (rename(_path.c_str(), path.c_str()) != 0) diff --git a/Foundation/src/File_WIN32U.cpp b/Foundation/src/File_WIN32U.cpp index 92c3c2562..75b5da85c 100644 --- a/Foundation/src/File_WIN32U.cpp +++ b/Foundation/src/File_WIN32U.cpp @@ -297,7 +297,7 @@ void FileImpl::copyToImpl(const std::string& path, int options) const std::wstring upath; convertPath(path, upath); - if (CopyFileW(_upath.c_str(), upath.c_str(), options == 1) == 0) + if (CopyFileW(_upath.c_str(), upath.c_str(), (options & OPT_FAIL_ON_OVERWRITE_IMPL) != 0) == 0) handleLastErrorImpl(_path); } @@ -308,7 +308,7 @@ void FileImpl::renameToImpl(const std::string& path, int options) std::wstring upath; convertPath(path, upath); - if (options == 1) { + if (options & OPT_FAIL_ON_OVERWRITE_IMPL) { if (MoveFileExW(_upath.c_str(), upath.c_str(), NULL) == 0) handleLastErrorImpl(_path); } else {