diff --git a/capio/server/include/storage/manager.hpp b/capio/server/include/storage/manager.hpp index d2fc927c1..069c99132 100644 --- a/capio/server/include/storage/manager.hpp +++ b/capio/server/include/storage/manager.hpp @@ -96,8 +96,13 @@ class StorageManager { * @param tid The thread ID. * @param fd The file descriptor number. * @param path The path of the file being opened. + * @param register_open Whether this operation should also call open() on the CapioFile + * instance. defaults to true + * TODO: support flag CLONE_FILES which will directly affect the behaviour of + * register_open. */ - void _addNewFdToStorage(pid_t tid, int fd, const std::filesystem::path &path); + void _addNewFdToStorage(pid_t tid, int fd, const std::filesystem::path &path, + bool register_open); public: /** @@ -300,4 +305,4 @@ class StorageManager { void updateDirectory(pid_t tid, const std::filesystem::path &file_path); }; -#endif // CAPIO_STORAGE_MANAGER_HPP \ No newline at end of file +#endif // CAPIO_STORAGE_MANAGER_HPP diff --git a/capio/server/src/storage_manager.cpp b/capio/server/src/storage_manager.cpp index 75267cfa4..d4f7eb55a 100644 --- a/capio/server/src/storage_manager.cpp +++ b/capio/server/src/storage_manager.cpp @@ -221,7 +221,7 @@ void StorageManager::clone(const pid_t parent_tid, const pid_t child_tid) { const auto path = _opened_fd_map[parent_tid][fd]._path; const auto offset = *_opened_fd_map[parent_tid][fd]._offset; - _addNewFdToStorage(child_tid, fd, path); + _addNewFdToStorage(child_tid, fd, path, false); _addNewFdToMap(child_tid, fd, path, offset); } } @@ -276,8 +276,11 @@ void StorageManager::_addNewFdToMap(const pid_t tid, const int fd, } void StorageManager::_addNewFdToStorage(const pid_t tid, const int fd, - const std::filesystem::path &path) { - _storage[path].open(); + const std::filesystem::path &path, + const bool register_open = true) { + if (register_open) { + _storage[path].open(); + } _storage[path].add_fd(tid, fd); }