From 9235166c766c73fd4204ef91fac1b705591f903e Mon Sep 17 00:00:00 2001 From: Henri Casanova Date: Fri, 4 Oct 2024 15:24:38 -1000 Subject: [PATCH] tmp commit --- include/fsmod/FileSystem.hpp | 2 ++ src/FileSystem.cpp | 15 +++++++++++++-- src/PathUtil.cpp | 3 ++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/fsmod/FileSystem.hpp b/include/fsmod/FileSystem.hpp index 83270fb..e8398b7 100644 --- a/include/fsmod/FileSystem.hpp +++ b/include/fsmod/FileSystem.hpp @@ -92,6 +92,8 @@ namespace simgrid::fsmod { [[nodiscard]] std::vector> get_partitions() const; [[nodiscard]] std::shared_ptr get_partition_for_path_or_null(const std::string& full_path) const; + [[nodiscard]] sg_size_t get_free_space_at_path(const std::string &full_path) const; + private: friend class File; diff --git a/src/FileSystem.cpp b/src/FileSystem.cpp index 3813d0c..d183f28 100644 --- a/src/FileSystem.cpp +++ b/src/FileSystem.cpp @@ -295,7 +295,6 @@ namespace simgrid::fsmod { * @return */ std::shared_ptr FileSystem::open(const std::string &full_path, const std::string& access_mode) { - std::cerr << "FSMON: OPENING FILE\n"; // "Get a file descriptor" if (this->num_open_files_ >= this->max_num_open_files_) { throw TooManyOpenFilesException(XBT_THROW_POINT); @@ -337,7 +336,6 @@ namespace simgrid::fsmod { file->current_position_ = metadata->get_current_size(); this->num_open_files_++; - std::cerr << "FSMON: DONE OPENING FILE\n"; return file; } @@ -467,4 +465,17 @@ namespace simgrid::fsmod { partition->delete_directory(path_at_mount_point); } + + /** + * @brief Returns the free space on the path's partition + * @param full_path: a path + * @return a number of bytes + */ + sg_size_t FileSystem::get_free_space_at_path(const std::string &full_path) const { + std::string simplified_path = PathUtil::simplify_path_string(full_path); + auto [partition, path_at_mount_point] = this->find_path_at_mount_point(simplified_path); + return partition->get_free_space(); + } + + } diff --git a/src/PathUtil.cpp b/src/PathUtil.cpp index ded1371..1312946 100644 --- a/src/PathUtil.cpp +++ b/src/PathUtil.cpp @@ -60,7 +60,8 @@ namespace simgrid::fsmod { * @return True if mount_point is a prefix of simplified_absolute_path, false otherwise */ bool PathUtil::is_at_mount_point(std::string_view simplified_absolute_path, std::string_view mount_point) { - return simplified_absolute_path.rfind(mount_point, 0) == 0; + bool to_return = simplified_absolute_path.rfind(mount_point, 0) == 0; + return to_return; } /**