Skip to content

Commit

Permalink
add correct file and directory size()
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloNicolla committed Apr 26, 2024
1 parent c8ff2a7 commit e2290ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
7 changes: 6 additions & 1 deletion Directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::unique_ptr<SystemObject>>& Directory::getChildren() const
Expand Down
7 changes: 6 additions & 1 deletion File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 1 addition & 6 deletions SystemObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ namespace fs
m_parentPath = parentPath;
}

size_t SystemObject::getSize() const
{
return m_size;
}

int SystemObject::getPermissions() const
{
return m_permissions;
Expand Down Expand Up @@ -87,7 +82,7 @@ namespace fs
<< m_created << "|"
<< m_modified << "|"
<< m_parentPath << "|"
<< m_size << "|"
<< getSize() << "|"
<< m_permissions;
return ofs;
}
Expand Down

0 comments on commit e2290ea

Please sign in to comment.