diff --git a/capio/server/include/storage/manager.hpp b/capio/server/include/storage/manager.hpp index 069c99132..788525ead 100644 --- a/capio/server/include/storage/manager.hpp +++ b/capio/server/include/storage/manager.hpp @@ -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. diff --git a/capio/server/src/storage_manager.cpp b/capio/server/src/storage_manager.cpp index 877b09689..f6278fd93 100644 --- a/capio/server/src/storage_manager.cpp +++ b/capio/server/src/storage_manager.cpp @@ -96,13 +96,21 @@ StorageManager::tryGet(const std::filesystem::path &path) const { return {const_cast(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(_storage.at(path)); } CapioFile &StorageManager::get(const pid_t pid, const int fd) const {