reduce memuse: fileinfo uses boxed path instead of pathbuf

reduce memuse: fileinfo does not store full metadata
This commit is contained in:
sreedevk
2025-07-13 13:40:41 +00:00
parent 5daec2f531
commit 81e13a14a2
3 changed files with 9 additions and 8 deletions

View File

@@ -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()?,
})
}
}

View File

@@ -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())
}

View File

@@ -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();