From 6c662bfb4a4c78199380cca8e6792bdec200abb5 Mon Sep 17 00:00:00 2001 From: KevDi Date: Mon, 18 Nov 2019 18:24:36 +0100 Subject: [PATCH 1/2] Fixed File on Unix to pass the Rename Tests --- Foundation/src/File_UNIX.cpp | 5 +++++ Foundation/src/File_VX.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/Foundation/src/File_UNIX.cpp b/Foundation/src/File_UNIX.cpp index 5bf78e6da..83f0c9ff4 100644 --- a/Foundation/src/File_UNIX.cpp +++ b/Foundation/src/File_UNIX.cpp @@ -384,6 +384,11 @@ void FileImpl::renameToImpl(const std::string& path, bool failOnOverwrite) { poco_assert (!_path.empty()); + struct stat st; + + if (stat(path.c_str(), &st) == 0) + throw FileExistsException(path, EEXIST); + if (rename(_path.c_str(), path.c_str()) != 0) handleLastErrorImpl(_path); } diff --git a/Foundation/src/File_VX.cpp b/Foundation/src/File_VX.cpp index eeac49143..b6d98748f 100644 --- a/Foundation/src/File_VX.cpp +++ b/Foundation/src/File_VX.cpp @@ -286,6 +286,11 @@ void FileImpl::renameToImpl(const std::string& path, bool failOnOverwrite) { poco_assert (!_path.empty()); + struct stat st; + + if (stat(path.c_str(), &st) == 0) + throw FileExistsException(path, EEXIST); + if (rename(_path.c_str(), path.c_str()) != 0) handleLastErrorImpl(_path); } From 936441df93cd33fb8ae927fd523c3992d126b569 Mon Sep 17 00:00:00 2001 From: KevDi Date: Mon, 18 Nov 2019 18:43:34 +0100 Subject: [PATCH 2/2] Fixed missing failOnOverwrite check --- Foundation/src/File_UNIX.cpp | 2 +- Foundation/src/File_VX.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Foundation/src/File_UNIX.cpp b/Foundation/src/File_UNIX.cpp index 83f0c9ff4..e44b843d5 100644 --- a/Foundation/src/File_UNIX.cpp +++ b/Foundation/src/File_UNIX.cpp @@ -386,7 +386,7 @@ void FileImpl::renameToImpl(const std::string& path, bool failOnOverwrite) struct stat st; - if (stat(path.c_str(), &st) == 0) + if (stat(path.c_str(), &st) == 0 && failOnOverwrite) throw FileExistsException(path, EEXIST); if (rename(_path.c_str(), path.c_str()) != 0) diff --git a/Foundation/src/File_VX.cpp b/Foundation/src/File_VX.cpp index b6d98748f..f7a8963e1 100644 --- a/Foundation/src/File_VX.cpp +++ b/Foundation/src/File_VX.cpp @@ -288,7 +288,7 @@ void FileImpl::renameToImpl(const std::string& path, bool failOnOverwrite) struct stat st; - if (stat(path.c_str(), &st) == 0) + if (stat(path.c_str(), &st) == 0 && failOnOverwrite) throw FileExistsException(path, EEXIST); if (rename(_path.c_str(), path.c_str()) != 0)