fix regression for flag -a from #245

This commit is contained in:
Abin Simon 2019-07-31 15:09:16 +05:30 committed by Pierre Peltier
parent 939aba8c61
commit ffcadc1332

View file

@ -21,6 +21,7 @@ pub use self::symlink::SymLink;
pub use crate::flags::Display; pub use crate::flags::Display;
pub use crate::icon::Icons; pub use crate::icon::Icons;
use std::fs;
use std::fs::read_link; use std::fs::read_link;
use std::io::{Error, ErrorKind}; use std::io::{Error, ErrorKind};
use std::path::PathBuf; use std::path::PathBuf;
@ -72,7 +73,8 @@ impl Meta {
let mut current_meta; let mut current_meta;
let mut parent_meta; let mut parent_meta;
let parent_path = match self.path.parent() { let absolute_path = fs::canonicalize(&self.path)?;
let parent_path = match absolute_path.parent() {
None => PathBuf::from("/"), None => PathBuf::from("/"),
Some(path) => PathBuf::from(path), Some(path) => PathBuf::from(path),
}; };
@ -124,7 +126,7 @@ impl Meta {
} }
pub fn calculate_total_size(&mut self) { pub fn calculate_total_size(&mut self) {
if let FileType::Directory{ uid: _ } = self.file_type { if let FileType::Directory { uid: _ } = self.file_type {
if let Some(metas) = &mut self.content { if let Some(metas) = &mut self.content {
let mut size_accumulated = self.size.get_bytes(); let mut size_accumulated = self.size.get_bytes();
for x in &mut metas.iter_mut() { for x in &mut metas.iter_mut() {
@ -132,7 +134,8 @@ impl Meta {
size_accumulated += x.size.get_bytes(); size_accumulated += x.size.get_bytes();
} }
self.size = Size::new(size_accumulated); self.size = Size::new(size_accumulated);
} else { // possibility that 'depth' limited the recursion in 'recurse_into' } else {
// possibility that 'depth' limited the recursion in 'recurse_into'
self.size = Size::new(Meta::calculate_total_file_size(&self.path)); self.size = Size::new(Meta::calculate_total_file_size(&self.path));
} }
} }
@ -177,8 +180,7 @@ impl Meta {
size += Meta::calculate_total_file_size(&path); size += Meta::calculate_total_file_size(&path);
} }
size size
} } else {
else {
0 0
} }
} }