mirror of
https://github.com/sreedevk/deduplicator.git
synced 2026-09-01 04:55:33 +00:00
reduce memuse: fileinfo uses boxed path instead of pathbuf
reduce memuse: fileinfo does not store full metadata
This commit is contained in:
@@ -2,17 +2,18 @@ use anyhow::Result;
|
||||
use gxhash::GxHasher;
|
||||
use memmap2::Mmap;
|
||||
use std::{
|
||||
fs::{self, Metadata},
|
||||
fs,
|
||||
hash::Hasher,
|
||||
io::Read,
|
||||
path::PathBuf,
|
||||
path::{Path, PathBuf},
|
||||
time::SystemTime,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FileInfo {
|
||||
pub path: PathBuf,
|
||||
pub path: Box<Path>,
|
||||
pub size: u64,
|
||||
pub filemeta: Metadata,
|
||||
pub modified: SystemTime,
|
||||
}
|
||||
|
||||
impl FileInfo {
|
||||
@@ -40,9 +41,9 @@ impl FileInfo {
|
||||
pub fn new(path: PathBuf) -> Result<Self> {
|
||||
let filemeta = std::fs::metadata(&path)?;
|
||||
Ok(Self {
|
||||
path,
|
||||
filemeta: filemeta.clone(),
|
||||
path: path.into_boxed_path(),
|
||||
size: filemeta.len(),
|
||||
modified: filemeta.modified()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ impl Formatter {
|
||||
}
|
||||
|
||||
pub fn human_mtime(file: &FileInfo) -> Result<String> {
|
||||
let modified_time: DateTime<Utc> = file.filemeta.modified()?.into();
|
||||
let modified_time: DateTime<Utc> = file.modified.into();
|
||||
Ok(modified_time.format("%Y-%m-%d %H:%M:%S").to_string())
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ impl Interactive {
|
||||
itable.set_titles(row!["index", "filename", "size", "updated_at"]);
|
||||
let max_path_size = group
|
||||
.iter()
|
||||
.map(|f| f.path.clone().into_os_string().len())
|
||||
.map(|f| f.path.iter().count())
|
||||
.max()
|
||||
.unwrap_or_default();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user