Browse Source

fix: dereferencing linksfile size.

Signed-off-by: Christina Sørensen <christina@cafkafk.com>
Andrzej Grzeslak 3 years ago
parent
commit
53ae13169d
1 changed files with 10 additions and 1 deletions
  1. 10 1
      src/fs/file.rs

+ 10 - 1
src/fs/file.rs

@@ -343,6 +343,10 @@ impl<'dir> File<'dir> {
     ///
     /// Block and character devices return their device IDs, because they
     /// usually just have a file size of zero.
+    ///
+    /// Links will return the size of their target (recursively through other
+    /// links) if dereferencing is enabled, otherwise the size of the link
+    /// itself.
     pub fn size(&self) -> f::Size {
         if self.is_directory() {
             f::Size::None
@@ -359,7 +363,12 @@ impl<'dir> File<'dir> {
                 minor: device_ids[7],
             })
         }
-        else {
+        else if self.is_link() && self.deref_links {
+            match self.link_target() {
+                FileTarget::Ok(f) => f.size(),
+                _ => f::Size::None
+            }
+        } else {
             f::Size::Some(self.metadata.len())
         }
     }