mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-12 18:20:26 +01:00
Changed Options Check in remaining File Impl Classes
This commit is contained in:
parent
f6f8ef8681
commit
fa20e056dd
@ -27,6 +27,11 @@ namespace Poco {
|
||||
class FileImpl
|
||||
{
|
||||
protected:
|
||||
|
||||
enum Options {
|
||||
OPT_FAIL_ON_OVERWRITE_IMPL = 0x01
|
||||
};
|
||||
|
||||
typedef UInt64 FileSizeImpl;
|
||||
|
||||
FileImpl();
|
||||
|
@ -28,6 +28,11 @@ namespace Poco {
|
||||
class Foundation_API FileImpl
|
||||
{
|
||||
protected:
|
||||
|
||||
enum Options {
|
||||
OPT_FAIL_ON_OVERWRITE_IMPL = 0x01
|
||||
};
|
||||
|
||||
typedef UInt64 FileSizeImpl;
|
||||
|
||||
FileImpl();
|
||||
|
@ -28,6 +28,11 @@ namespace Poco {
|
||||
class Foundation_API FileImpl
|
||||
{
|
||||
protected:
|
||||
|
||||
enum Options {
|
||||
OPT_FAIL_ON_OVERWRITE_IMPL = 0x01
|
||||
};
|
||||
|
||||
typedef UInt64 FileSizeImpl;
|
||||
|
||||
FileImpl();
|
||||
@ -52,8 +57,8 @@ protected:
|
||||
void setSizeImpl(FileSizeImpl size);
|
||||
void setWriteableImpl(bool flag = true);
|
||||
void setExecutableImpl(bool flag = true);
|
||||
void copyToImpl(const std::string& path, bool failOnOverwrite = false) const;
|
||||
void renameToImpl(const std::string& path, bool failOnOverwrite = false);
|
||||
void copyToImpl(const std::string& path, int options = 0) const;
|
||||
void renameToImpl(const std::string& path, int options = 0);
|
||||
void linkToImpl(const std::string& path, int type) const;
|
||||
void removeImpl();
|
||||
bool createFileImpl();
|
||||
|
@ -248,7 +248,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 & S_IRWXU);
|
||||
} else {
|
||||
dd = open(path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, st.st_mode & S_IRWXU);
|
||||
@ -288,7 +288,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)
|
||||
|
@ -292,7 +292,7 @@ void FileImpl::copyToImpl(const std::string& path, int options) const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
if (CopyFileA(_path.c_str(), path.c_str(), options == 1) == 0)
|
||||
if (CopyFileA(_path.c_str(), path.c_str(), (options & OPT_FAIL_ON_OVERWRITE_IMPL) != 0) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
@ -301,7 +301,7 @@ void FileImpl::renameToImpl(const std::string& path, int options)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
if (options == 1) {
|
||||
if (options & OPT_FAIL_ON_OVERWRITE_IMPL) {
|
||||
if (MoveFileExA(_path.c_str(), path.c_str(), NULL) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
} else {
|
||||
|
@ -277,25 +277,31 @@ void FileImpl::setExecutableImpl(bool flag)
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::copyToImpl(const std::string& path, bool failOnOverwrite) const
|
||||
void FileImpl::copyToImpl(const std::string& path, int options) const
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
std::wstring upath;
|
||||
convertPath(path, upath);
|
||||
if (CopyFileW(_upath.c_str(), upath.c_str(), failOnOverwrite) == 0)
|
||||
if (CopyFileW(_upath.c_str(), upath.c_str(), (options & OPT_FAIL_ON_OVERWRITE_IMPL) != 0) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
|
||||
void FileImpl::renameToImpl(const std::string& path, bool failOnOverwrite)
|
||||
void FileImpl::renameToImpl(const std::string& path, int options)
|
||||
{
|
||||
poco_assert (!_path.empty());
|
||||
|
||||
std::wstring upath;
|
||||
convertPath(path, upath);
|
||||
if (MoveFileW(_upath.c_str(), upath.c_str()) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
if (options & OPT_FAIL_ON_OVERWRITE_IMPL) {
|
||||
if (MoveFileW(_upath.c_str(), upath.c_str()) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
} else {
|
||||
if (MoveFileW(_upath.c_str(), upath.c_str(), MOVEFILE_REPLACE_EXISTING) == 0)
|
||||
handleLastErrorImpl(_path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user