diff --git a/ucm/store/pcstore/cc/domain/file/posix_file.cc b/ucm/store/pcstore/cc/domain/file/posix_file.cc index b550c0a4..2fffcdcc 100644 --- a/ucm/store/pcstore/cc/domain/file/posix_file.cc +++ b/ucm/store/pcstore/cc/domain/file/posix_file.cc @@ -37,18 +37,17 @@ PosixFile::~PosixFile() { this->Close(); } Status PosixFile::MkDir() { - constexpr auto permission = (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IROTH); + constexpr auto permission = (S_IRWXU | S_IRWXG | S_IROTH); auto ret = mkdir(this->Path().c_str(), permission); auto eno = errno; if (ret != 0) { - if (eno == EEXIST) { - return Status::DuplicateKey(); - } else { - UC_ERROR("Failed to create directory, path: {}, errcode: {}, errno: {}.", this->Path(), - ret, eno); - return Status::OsApiError(); - } + if (eno == EEXIST) { return Status::DuplicateKey(); } + UC_ERROR("Failed({},{}) to create dir({}).", ret, eno, this->Path()); + return Status::OsApiError(); } + ret = chmod(this->Path().c_str(), permission); + eno = errno; + if (ret != 0) { UC_WARN("Failed({},{}) to set perm on dir({}).", ret, eno, this->Path()); } return Status::OK(); } diff --git a/ucm/store/pcstore/cc/domain/trans/share_buffer.cc b/ucm/store/pcstore/cc/domain/trans/share_buffer.cc index 00ab6eb2..e34c6f09 100644 --- a/ucm/store/pcstore/cc/domain/trans/share_buffer.cc +++ b/ucm/store/pcstore/cc/domain/trans/share_buffer.cc @@ -314,13 +314,11 @@ std::shared_ptr ShareBuffer::MakeLocalReader(const std::str UC_ERROR("Failed to make buffer({}) on host.", blockSize_); return nullptr; } - Reader* reader = nullptr; try { - reader = new Reader{block, path, blockSize_, ioDirect_, false, addr.get()}; - return std::shared_ptr(reader, - [addr = std::move(addr)](Reader* reader) { delete reader; }); + return std::shared_ptr( + new Reader{block, path, blockSize_, ioDirect_, false, addr.get()}, + [addr = std::move(addr)](Reader* reader) { delete reader; }); } catch (const std::exception& e) { - if (reader) { delete reader; } UC_ERROR("Failed({}) to create reader.", e.what()); return nullptr; } @@ -331,17 +329,19 @@ std::shared_ptr ShareBuffer::MakeSharedReader(const std::st size_t position) { void* addr = this->BlockAt(position); - Reader* reader = nullptr; + auto reader = new (std::nothrow) Reader(block, path, blockSize_, ioDirect_, true, addr); + if (!reader) [[unlikely]] { + this->ReleaseBlock(position); + UC_ERROR("Failed to create reader."); + return nullptr; + } try { - reader = new Reader{block, path, blockSize_, ioDirect_, true, addr}; return std::shared_ptr(reader, [this, position](Reader* reader) { delete reader; this->ReleaseBlock(position); }); - } catch (...) { - this->ReleaseBlock(position); - if (reader) { delete reader; } - UC_ERROR("Failed to create reader."); + } catch (const std::exception& e) { + UC_ERROR("Failed({}) to create reader.", e.what()); return nullptr; } }