From e2290ea8443be84130011fade2e530c7f9042f9e Mon Sep 17 00:00:00 2001 From: PabloNicolla Date: Fri, 26 Apr 2024 14:57:29 -0400 Subject: [PATCH] add correct file and directory size() --- Directory.cpp | 7 ++++++- File.cpp | 7 ++++++- SystemObject.cpp | 7 +------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Directory.cpp b/Directory.cpp index cb60b1a..082cc60 100644 --- a/Directory.cpp +++ b/Directory.cpp @@ -18,7 +18,12 @@ namespace fs size_t Directory::getSize() const { - return 1; + size_t sum{}; + for (auto& [k, v] : m_children) + { + sum += v->getSize(); + } + return sum; } const std::unordered_map>& Directory::getChildren() const diff --git a/File.cpp b/File.cpp index faac964..d723a23 100644 --- a/File.cpp +++ b/File.cpp @@ -78,7 +78,12 @@ namespace fs size_t File::getSize() const { - return 0; + std::string parentPath = getParentPath().empty() ? "" : getParentPath() + '/'; + adaptParentPath(parentPath); + const std::filesystem::path path{ + "./fs/home/" + getOwner() + '/' + parentPath + getName() + }; + return std::filesystem::file_size(path); } std::string& File::adaptParentPath(std::string& parentPath) diff --git a/SystemObject.cpp b/SystemObject.cpp index edf5219..686d24a 100644 --- a/SystemObject.cpp +++ b/SystemObject.cpp @@ -54,11 +54,6 @@ namespace fs m_parentPath = parentPath; } - size_t SystemObject::getSize() const - { - return m_size; - } - int SystemObject::getPermissions() const { return m_permissions; @@ -87,7 +82,7 @@ namespace fs << m_created << "|" << m_modified << "|" << m_parentPath << "|" - << m_size << "|" + << getSize() << "|" << m_permissions; return ofs; }