Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion capio/server/include/storage/manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class StorageManager {
* @return A direct reference to the associated CapioFile object.
* @throws std::runtime_error If the file associated with the path is not present in storage.
*/
CapioFile &get(const std::filesystem::path &path) const;
CapioFile &get(const std::filesystem::path &path);

/**
* @brief Retrieves a reference to a CapioFile object from storage.
Expand Down
16 changes: 12 additions & 4 deletions capio/server/src/storage_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,21 @@ StorageManager::tryGet(const std::filesystem::path &path) const {
return {const_cast<CapioFile &>(it->second)};
}
}
CapioFile &StorageManager::get(const std::filesystem::path &path) const {
CapioFile &StorageManager::get(const std::filesystem::path &path) {
START_LOG(gettid(), "call(path=%s)", path.c_str());
const shared_lock_guard slg(_mutex_storage);
if (_storage.find(path) == _storage.end()) {
ERR_EXIT("File %s was not found in local storage", path.c_str());
bool require_add = false;
{
const shared_lock_guard slg(_mutex_storage);
if (_storage.find(path) == _storage.end()) {
LOG("File %s was not found in local storage", path.c_str());
require_add = true;
}
}
if (require_add) {
this->add(path, true, CAPIO_DEFAULT_DIR_INITIAL_SIZE);
}

const shared_lock_guard slg(_mutex_storage);
return const_cast<CapioFile &>(_storage.at(path));
}
CapioFile &StorageManager::get(const pid_t pid, const int fd) const {
Expand Down
Loading