diff options
| author | Martin Ridgers <[email protected]> | 2022-02-21 12:53:47 +0100 |
|---|---|---|
| committer | Martin Ridgers <[email protected]> | 2022-02-21 12:53:47 +0100 |
| commit | f3722e2c7e27131be8395dedc9fcbb6a73cda80d (patch) | |
| tree | f363e44b32191779ba19b5b648362281dc89e1ae /zencore/filesystem.cpp | |
| parent | Allow all users and groups to read/write files (POSIX) (diff) | |
| download | zen-f3722e2c7e27131be8395dedc9fcbb6a73cda80d.tar.xz zen-f3722e2c7e27131be8395dedc9fcbb6a73cda80d.zip | |
Explicitly set access permissions so we're not affected by process' umask
Diffstat (limited to 'zencore/filesystem.cpp')
| -rw-r--r-- | zencore/filesystem.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp index f6ea4824a..7cd71e4b4 100644 --- a/zencore/filesystem.cpp +++ b/zencore/filesystem.cpp @@ -436,11 +436,12 @@ CloneFile(std::filesystem::path FromPath, std::filesystem::path ToPath) ScopedFd $From = { FromFd }; // The 'to' file - int ToFd = open(ToPath.c_str(), O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0666); + int ToFd = open(ToPath.c_str(), O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC); if (ToFd < 0) { return false; } + fchmod(ToFd, 0666); ScopedFd $To = { FromFd }; ioctl(ToFd, FICLONE, FromFd); @@ -502,11 +503,12 @@ CopyFile(std::filesystem::path FromPath, std::filesystem::path ToPath, const Cop ScopedFd $From = {FromFd}; // To file - int ToFd = open(ToPath.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0666); + int ToFd = open(ToPath.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC); if (ToFd < 0) { ThrowLastError(fmt::format("failed to create file {}", ToPath)); } + fchmod(ToFd, 0666); ScopedFd $To = {ToFd}; // Copy impl @@ -558,17 +560,19 @@ WriteFile(std::filesystem::path Path, const IoBuffer* const* Data, size_t Buffer #else int OpenFlags = O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC; - int Fd = open(Path.c_str(), OpenFlags, 0666); + int Fd = open(Path.c_str(), OpenFlags); if (Fd < 0) { zen::CreateDirectories(Path.parent_path()); - Fd = open(Path.c_str(), OpenFlags, 0666); + Fd = open(Path.c_str(), OpenFlags); } if (Fd < 0) { ThrowLastError(fmt::format("File open failed for '{}'", Path)); } + + fchmod(Fd, 0666); #endif // TODO: this should be block-enlightened |