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 /zenstore | |
| 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 'zenstore')
| -rw-r--r-- | zenstore/basicfile.cpp | 9 | ||||
| -rw-r--r-- | zenstore/filecas.cpp | 9 |
2 files changed, 15 insertions, 3 deletions
diff --git a/zenstore/basicfile.cpp b/zenstore/basicfile.cpp index 038d83493..1b6080379 100644 --- a/zenstore/basicfile.cpp +++ b/zenstore/basicfile.cpp @@ -75,12 +75,16 @@ BasicFile::Open(std::filesystem::path FileName, bool IsCreate, std::error_code& int OpenFlags = O_RDWR | O_CLOEXEC; OpenFlags |= IsCreate ? O_CREAT | O_TRUNC : 0; - int Fd = open(FileName.c_str(), OpenFlags, 0666); + int Fd = open(FileName.c_str(), OpenFlags); if (Fd < 0) { Ec = zen::MakeErrorCodeFromLastError(); return; } + if (IsCreate) + { + fchmod(Fd, 0666); + } void* FileHandle = (void*)(uintptr_t(Fd)); #endif @@ -366,12 +370,13 @@ LockFile::Create(std::filesystem::path FileName, CbObject Payload, std::error_co return; } #elif ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC - int Fd = open(FileName.c_str(), O_RDWR | O_CREAT | O_CLOEXEC, 0666); + int Fd = open(FileName.c_str(), O_RDWR | O_CREAT | O_CLOEXEC); if (Fd < 0) { Ec = zen::MakeErrorCodeFromLastError(); return; } + fchmod(Fd, 0666); int LockRet = flock(Fd, LOCK_EX | LOCK_NB); if (LockRet < 0) diff --git a/zenstore/filecas.cpp b/zenstore/filecas.cpp index f2f4465cc..5c7edef29 100644 --- a/zenstore/filecas.cpp +++ b/zenstore/filecas.cpp @@ -388,7 +388,14 @@ FileCasStrategy::InsertChunk(const void* const ChunkData, const size_t ChunkSize } #else // Attempt to exclusively create the file. - auto InternalCreateFile = [&] { return open(Name.ShardedPath.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0666); }; + auto InternalCreateFile = [&] { + int Fd = open(Name.ShardedPath.c_str(), O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC); + if (Fd >= 0) + { + fchmod(Fd, 0666); + } + return Fd; + }; int Fd = InternalCreateFile(); if (Fd < 0) { |