Repository navigation
kvs: atomic file operations, file permissions - #503
Conversation
License Check Results🚀 The license check job ran with the Bazel command: bazel run --lockfile_mode=error //:license-checkStatus: Click to expand output |
|
Documentation preview for this pull request is available at: |
aafd1a3 to
bd60c4c
Compare
bd60c4c to
cc0c1ed
Compare
| } | ||
|
|
||
| // Set permissions on a file already opened. | ||
| using score::filesystem::Perms; |
There was a problem hiding this comment.
I still see race condition here
We need to check if baselibs providing open,fopen APIs to avoid this race condition
Expectation to have something like following :
#include
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
auto file_deleter = [](std::FILE* f) {
if (f != nullptr) {
(void)std::fclose(f);
}
};
using FilePtr = std::unique_ptr<std::FILE, decltype(file_deleter)>;
const int fd = ::open(
path.Native().c_str(),
O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC,
S_IRUSR | S_IWUSR | S_IRGRP); // 0640
if (fd == -1) {
logger_->LogError() << "Failed to open file " << path;
return score::MakeUnexpected(ErrorCode::PhysicalStorageFailure);
}
std::FILE* raw_file = ::fdopen(fd, "wb");
if (raw_file == nullptr) {
(void)::close(fd);
logger_->LogError() << "Failed to create file stream " << path;
return score::MakeUnexpected(ErrorCode::PhysicalStorageFailure);
}
FilePtr file{raw_file, file_deleter};
|
I shifted the focus from permissions to atomic operation.
|
i would say having single file contains hash and kvs data is a good idea , let us try to discuss this topic coming meeting. |
cc0c1ed to
f4cb11e
Compare
f4cb11e to
1315019
Compare
PandaeDo
left a comment
There was a problem hiding this comment.
Fine for me from perspective of safety&quality
1315019 to
c40e2bc
Compare
c40e2bc to
feb431a
Compare
Ahmed-Elsaka-JC
left a comment
There was a problem hiding this comment.
from CPP prespective LGFM
- Set permissions of stored files to 640. - Make store operation atomic per file. - Temp file + fsync + rename.
feb431a to
ba6e364
Compare
afa3367
Resolves #412