Poco::File create path (#4873) (#4959)

* #4202 Checked if the path exists, create one if not

* Addressed comments

* fix(Poco::File): resolve compile errors related to createfile.

---------

Co-authored-by: capak07 <69026837+capak07@users.noreply.github.com>
This commit is contained in:
Matej Kenda
2025-05-29 10:50:58 +02:00
committed by GitHub
parent 733f0c34e0
commit 7b58bc10e7
6 changed files with 20 additions and 6 deletions

View File

@@ -62,7 +62,7 @@ protected:
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;

View File

@@ -61,7 +61,7 @@ protected:
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;

View File

@@ -62,7 +62,7 @@ protected:
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;

View File

@@ -459,10 +459,15 @@ void FileImpl::removeImpl()
}
bool FileImpl::createFileImpl()
bool FileImpl::createFileImpl(bool createDirectories)
{
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)
{

View File

@@ -321,10 +321,14 @@ void FileImpl::removeImpl()
}
bool FileImpl::createFileImpl()
bool FileImpl::createFileImpl(bool createDirectories)
{
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)
{

View File

@@ -377,10 +377,15 @@ void FileImpl::removeImpl()
}
bool FileImpl::createFileImpl()
bool FileImpl::createFileImpl(bool createDirectories)
{
poco_assert (!_path.empty());
if(createDirectories) {
Path p(_path);
p.makeDirectory();
}
HANDLE hFile = CreateFileW(_upath.c_str(), GENERIC_WRITE, 0, 0, CREATE_NEW, 0, 0);
if (hFile != INVALID_HANDLE_VALUE)
{