From 10d816e14f8c58ba1291078763a7c952c60e1c99 Mon Sep 17 00:00:00 2001 From: capak07 <69026837+capak07@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:43:54 -0400 Subject: [PATCH 1/2] #4202 Checked if the path exists, create one if not --- Foundation/src/File_WIN32U.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Foundation/src/File_WIN32U.cpp b/Foundation/src/File_WIN32U.cpp index f4cab98d6c..2309ea0c7e 100644 --- a/Foundation/src/File_WIN32U.cpp +++ b/Foundation/src/File_WIN32U.cpp @@ -381,6 +381,12 @@ bool FileImpl::createFileImpl() { poco_assert (!_path.empty()); + if (!existsImpl()) + { + if (!createDirectoryImpl()) + return false; + } + HANDLE hFile = CreateFileW(_upath.c_str(), GENERIC_WRITE, 0, 0, CREATE_NEW, 0, 0); if (hFile != INVALID_HANDLE_VALUE) { From 35f81a5b01ab0f470b2b67b29e86248e759a6372 Mon Sep 17 00:00:00 2001 From: capak07 <69026837+capak07@users.noreply.github.com> Date: Wed, 27 Nov 2024 20:44:45 -0400 Subject: [PATCH 2/2] Addressed comments --- Foundation/include/Poco/File_WIN32U.h | 2 +- Foundation/src/File_UNIX.cpp | 7 ++++++- Foundation/src/File_VX.cpp | 6 +++++- Foundation/src/File_WIN32U.cpp | 9 ++++----- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Foundation/include/Poco/File_WIN32U.h b/Foundation/include/Poco/File_WIN32U.h index a88d8334cd..4c7c6f1c28 100644 --- a/Foundation/include/Poco/File_WIN32U.h +++ b/Foundation/include/Poco/File_WIN32U.h @@ -62,7 +62,7 @@ class Foundation_API FileImpl void renameToImpl(const std::string& path, int options = 0); void linkToImpl(const std::string& path, int type) const; void removeImpl(); - bool createFileImpl(); + bool createFileImpl(bool createDirectories = false); bool createDirectoryImpl(); FileSizeImpl totalSpaceImpl() const; FileSizeImpl usableSpaceImpl() const; diff --git a/Foundation/src/File_UNIX.cpp b/Foundation/src/File_UNIX.cpp index 9261a9a367..2039c1d658 100644 --- a/Foundation/src/File_UNIX.cpp +++ b/Foundation/src/File_UNIX.cpp @@ -459,10 +459,15 @@ void FileImpl::removeImpl() } -bool FileImpl::createFileImpl() +bool FileImpl::createFileImpl(bool createDirectories = false) { poco_assert (!_path.empty()); + if(createDirectories) { + Path p(_path); + p.makeDirectory(); + } + int n = open(_path.c_str(), O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (n != -1) { diff --git a/Foundation/src/File_VX.cpp b/Foundation/src/File_VX.cpp index ce23993773..6875326ee2 100644 --- a/Foundation/src/File_VX.cpp +++ b/Foundation/src/File_VX.cpp @@ -321,10 +321,14 @@ void FileImpl::removeImpl() } -bool FileImpl::createFileImpl() +bool FileImpl::createFileImpl(bool createDirectories = false) { poco_assert (!_path.empty()); + if(createDirectories) { + Path p(_path); + p.makeDirectory(); + } int n = open(_path.c_str(), O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (n != -1) { diff --git a/Foundation/src/File_WIN32U.cpp b/Foundation/src/File_WIN32U.cpp index 2309ea0c7e..ef01d08eb3 100644 --- a/Foundation/src/File_WIN32U.cpp +++ b/Foundation/src/File_WIN32U.cpp @@ -377,14 +377,13 @@ void FileImpl::removeImpl() } -bool FileImpl::createFileImpl() +bool FileImpl::createFileImpl(bool createDirectories = false) { poco_assert (!_path.empty()); - if (!existsImpl()) - { - if (!createDirectoryImpl()) - return false; + if(createDirectories) { + Path p(_path); + p.makeDirectory(); } HANDLE hFile = CreateFileW(_upath.c_str(), GENERIC_WRITE, 0, 0, CREATE_NEW, 0, 0);