File fail on overwrite#2842
Conversation
|
How about, instead of using a bool parameter, using an options parameter with a FAIL_ON_OVERWRITE flag? Would make the code much more readable. I know we have used bool parameters in way too many places in Poco already, but better late then never to start making it right. Something like: |
|
I could change it to an Option Parameter like you showed if you want. |
|
Just put the Options enum inside the File class definition in File.h: |
…i/poco into feature/FileFailOnOverwrite
|
So i have added the Options Advice. Pls take a look and say if it's okay so =) |
obiltschnig
left a comment
There was a problem hiding this comment.
Looks good, but please fix the comments still mentioning the failOnOverwrite param.
obiltschnig
left a comment
There was a problem hiding this comment.
I have some more comments/requests for change, unfortunately.
Foundation/include/Poco/File_WINCE.h
Outdated
| void setExecutableImpl(bool flag = true); | ||
| void copyToImpl(const std::string& path) const; | ||
| void renameToImpl(const std::string& path); | ||
| void copyToImpl(const std::string& path, bool failOnOverwrite = false) const; |
Foundation/src/File_WINCE.cpp
Outdated
|
|
||
|
|
||
| void FileImpl::copyToImpl(const std::string& path) const | ||
| void FileImpl::copyToImpl(const std::string& path, bool failOnOverwrite) const |
Foundation/include/Poco/File_WINCE.h
Outdated
| void copyToImpl(const std::string& path) const; | ||
| void renameToImpl(const std::string& path); | ||
| void copyToImpl(const std::string& path, bool failOnOverwrite = false) const; | ||
| void renameToImpl(const std::string& path, bool failOnOverwrite = false); |
Foundation/src/File_UNIX.cpp
Outdated
|
|
||
| int dd = open(path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, st.st_mode); | ||
| int dd; | ||
| if (options == 1) { |
There was a problem hiding this comment.
better check would be options & File::OPT_FAIL_ON_OVERWRITE (in case we add another option)
There was a problem hiding this comment.
So i have to include the File.h Header inside the File_UNIX.cpp?
Which seems like a circle include because File_UNIX already included inside the File.h
Foundation/src/File_VX.cpp
Outdated
|
|
||
| int dd = open(path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, st.st_mode & S_IRWXU); | ||
| int dd; | ||
| if (options == 1) { |
There was a problem hiding this comment.
options & File::OPT_FAIL_ON_OVERWRITE
Foundation/src/File_WIN32.cpp
Outdated
| poco_assert (!_path.empty()); | ||
|
|
||
| if (CopyFileA(_path.c_str(), path.c_str(), FALSE) == 0) | ||
| if (CopyFileA(_path.c_str(), path.c_str(), options == 1) == 0) |
There was a problem hiding this comment.
(options & File::OPT_FAIL_ON_OVERWRITE) != 0
Foundation/src/File_WIN32.cpp
Outdated
|
|
||
| if (MoveFileExA(_path.c_str(), path.c_str(), MOVEFILE_REPLACE_EXISTING) == 0) | ||
| handleLastErrorImpl(_path); | ||
| if (options == 1) { |
There was a problem hiding this comment.
options & File::OPT_FAIL_ON_OVERWRITE
Foundation/src/File_WIN32U.cpp
Outdated
| std::wstring upath; | ||
| convertPath(path, upath); | ||
| if (CopyFileW(_upath.c_str(), upath.c_str(), FALSE) == 0) | ||
| if (CopyFileW(_upath.c_str(), upath.c_str(), options == 1) == 0) |
There was a problem hiding this comment.
(options & File::OPT_FAIL_ON_OVERWRITE) != 0
Foundation/src/File_WIN32U.cpp
Outdated
| convertPath(path, upath); | ||
| if (MoveFileExW(_upath.c_str(), upath.c_str(), MOVEFILE_REPLACE_EXISTING) == 0) | ||
| handleLastErrorImpl(_path); | ||
| if (options == 1) { |
There was a problem hiding this comment.
options & File::OPT_FAIL_ON_OVERWRITE
|
So i have to include the |
|
Yeah, good point. In the other places we have actually defined the enum in the Impl classes (like |
|
Btw, an example for how it's done properly is the Thread class. |
|
I have added the remarks like it was implemented inside the Thread Class. Currently i done it for the Unix and Win32U File Implementation. Please take a look if it is ok so. If its ok i will made the changes for the missing ones. |
|
Looks good, but please also fix the checks for |
|
Yes i will fix them i just want to ask if its okay the way i did it now |
…nto feature/FileFailOnOverwrite
|
I have made the changes to the other File Impls |
With the optional Parameter
failOnOverwriteit's possible to get an exception if the destination File exists on copy/move/rename. In some cases it is usefull to get the Information if the Copy/Move/Rename fail because of an existing File.