|
|
@@ -432,12 +432,18 @@ impl<'dir> File<'dir> {
|
|
|
/// This actual size the file takes up on disk, in bytes.
|
|
|
#[cfg(unix)]
|
|
|
pub fn blocksize(&self) -> f::Blocksize {
|
|
|
- if self.is_file() || self.is_link() {
|
|
|
+ if self.deref_links && self.is_link() {
|
|
|
+ match self.link_target() {
|
|
|
+ FileTarget::Ok(f) => f.blocksize(),
|
|
|
+ _ => f::Blocksize::None,
|
|
|
+ }
|
|
|
+ } else if self.is_file() {
|
|
|
// Note that metadata.blocks returns the number of blocks
|
|
|
// for 512 byte blocks according to the POSIX standard
|
|
|
// even though the physical block size may be different.
|
|
|
f::Blocksize::Some(self.metadata.blocks() * 512)
|
|
|
} else {
|
|
|
+ // directory or symlinks
|
|
|
f::Blocksize::None
|
|
|
}
|
|
|
}
|
|
|
@@ -481,14 +487,11 @@ impl<'dir> File<'dir> {
|
|
|
/// itself.
|
|
|
#[cfg(unix)]
|
|
|
pub fn size(&self) -> f::Size {
|
|
|
- if self.is_link() {
|
|
|
- let target = self.link_target();
|
|
|
- if let FileTarget::Ok(target) = target {
|
|
|
- return target.size();
|
|
|
+ if self.deref_links && self.is_link() {
|
|
|
+ match self.link_target() {
|
|
|
+ FileTarget::Ok(f) => f.size(),
|
|
|
+ _ => f::Size::None,
|
|
|
}
|
|
|
- }
|
|
|
- if self.is_directory() {
|
|
|
- f::Size::None
|
|
|
} else if self.is_char_device() || self.is_block_device() {
|
|
|
let device_id = self.metadata.rdev();
|
|
|
|
|
|
@@ -497,20 +500,17 @@ impl<'dir> File<'dir> {
|
|
|
// the "as u32" cast are not needed. We turn off the warning to
|
|
|
// allow it to compile cleanly on Linux.
|
|
|
#[allow(trivial_numeric_casts)]
|
|
|
- #[allow(clippy::unnecessary_cast)]
|
|
|
- #[allow(clippy::useless_conversion)]
|
|
|
+ #[allow(clippy::unnecessary_cast, clippy::useless_conversion)]
|
|
|
f::Size::DeviceIDs(f::DeviceIDs {
|
|
|
// SAFETY: Calling libc function to decompose the device_id
|
|
|
major: unsafe { libc::major(device_id.try_into().unwrap()) } as u32,
|
|
|
minor: unsafe { libc::minor(device_id.try_into().unwrap()) } as u32,
|
|
|
})
|
|
|
- } else if self.is_link() && self.deref_links {
|
|
|
- match self.link_target() {
|
|
|
- FileTarget::Ok(f) => f.size(),
|
|
|
- _ => f::Size::None,
|
|
|
- }
|
|
|
- } else {
|
|
|
+ } else if self.is_file() {
|
|
|
f::Size::Some(self.metadata.len())
|
|
|
+ } else {
|
|
|
+ // directory and symlink
|
|
|
+ f::Size::None
|
|
|
}
|
|
|
}
|
|
|
|