From c9b87c4c0353c3fd398abd8b3c8062953ca1369b Mon Sep 17 00:00:00 2001 From: hedonihilist <76996792+hedonihilist@users.noreply.github.com> Date: Sun, 8 Aug 2021 01:50:02 +0800 Subject: [PATCH] Count the size of the directories when calculating the size in DirInfo (#3902) * take dir entry size into consideration when calculting the size of a directory in DirInfo * fmt check --- crates/nu-engine/src/filesystem/dir_info.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/nu-engine/src/filesystem/dir_info.rs b/crates/nu-engine/src/filesystem/dir_info.rs index e23f741434..da661b88f1 100644 --- a/crates/nu-engine/src/filesystem/dir_info.rs +++ b/crates/nu-engine/src/filesystem/dir_info.rs @@ -95,6 +95,14 @@ impl DirInfo { path, }; + match std::fs::metadata(&s.path) { + Ok(d) => { + s.size = d.len(); // dir entry size + s.blocks = file_real_size_fast(&s.path, &d).ok().unwrap_or(0); + } + Err(e) => s = s.add_error(e.into()), + }; + match std::fs::read_dir(&s.path) { Ok(d) => { for f in d {