mirror of
https://github.com/sreedevk/deduplicator.git
synced 2026-09-07 22:36:17 +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 gxhash::GxHasher;
|
||||||
use memmap2::Mmap;
|
use memmap2::Mmap;
|
||||||
use std::{
|
use std::{
|
||||||
fs::{self, Metadata},
|
fs,
|
||||||
hash::Hasher,
|
hash::Hasher,
|
||||||
io::Read,
|
io::Read,
|
||||||
path::PathBuf,
|
path::{Path, PathBuf},
|
||||||
|
time::SystemTime,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct FileInfo {
|
pub struct FileInfo {
|
||||||
pub path: PathBuf,
|
pub path: Box<Path>,
|
||||||
pub size: u64,
|
pub size: u64,
|
||||||
pub filemeta: Metadata,
|
pub modified: SystemTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileInfo {
|
impl FileInfo {
|
||||||
@@ -40,9 +41,9 @@ impl FileInfo {
|
|||||||
pub fn new(path: PathBuf) -> Result<Self> {
|
pub fn new(path: PathBuf) -> Result<Self> {
|
||||||
let filemeta = std::fs::metadata(&path)?;
|
let filemeta = std::fs::metadata(&path)?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
path,
|
path: path.into_boxed_path(),
|
||||||
filemeta: filemeta.clone(),
|
|
||||||
size: filemeta.len(),
|
size: filemeta.len(),
|
||||||
|
modified: filemeta.modified()?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ impl Formatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn human_mtime(file: &FileInfo) -> Result<String> {
|
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())
|
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"]);
|
itable.set_titles(row!["index", "filename", "size", "updated_at"]);
|
||||||
let max_path_size = group
|
let max_path_size = group
|
||||||
.iter()
|
.iter()
|
||||||
.map(|f| f.path.clone().into_os_string().len())
|
.map(|f| f.path.iter().count())
|
||||||
.max()
|
.max()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user