Skip to main content

cargo_plot/core/
file_stats.rs

1// use std::fs;
2use std::path::{Path, PathBuf};
3pub mod weight;
4
5use self::weight::get_path_weight;
6
7/// [POL]: Struktura przechowująca metadane (statystyki) pliku lub folderu.
8#[derive(Debug, Clone)]
9pub struct FileStats {
10    pub path: String,      // Oryginalna ścieżka relatywna (np. "src/main.rs")
11    pub absolute: PathBuf, // Pełna ścieżka absolutna na dysku
12    pub weight_bytes: u64, // Rozmiar w bajtach
13
14                           // ⚡ Miejsce na przyszłe parametry:
15                           // pub created_at: Option<std::time::SystemTime>,
16                           // pub modified_at: Option<std::time::SystemTime>,
17}
18
19impl FileStats {
20    /// [POL]: Pobiera statystyki pliku bezpośrednio z dysku.
21    pub fn fetch(path: &str, entry_absolute: &str) -> Self {
22        let absolute = Path::new(entry_absolute).join(path);
23
24        let weight_bytes = get_path_weight(&absolute, true);
25        // let weight_bytes = fs::metadata(&absolute)
26        //     .map(|m| m.len())
27        //     .unwrap_or(0);
28
29        Self {
30            path: path.to_string(),
31            absolute,
32            weight_bytes,
33        }
34    }
35}