Skip to main content

gravityfile_scan/
progress.rs

1//! Scan progress reporting.
2
3use std::path::PathBuf;
4use std::time::Duration;
5
6/// Progress information during a scan.
7#[derive(Debug, Clone)]
8pub struct ScanProgress {
9    /// Number of files scanned so far.
10    pub files_scanned: u64,
11    /// Number of directories scanned so far.
12    pub dirs_scanned: u64,
13    /// Total bytes scanned so far.
14    pub bytes_scanned: u64,
15    /// Current path being scanned.
16    pub current_path: PathBuf,
17    /// Number of errors/warnings encountered.
18    pub errors_count: u64,
19    /// Time elapsed since scan started.
20    pub elapsed: Duration,
21}
22
23impl ScanProgress {
24    /// Create initial progress state.
25    pub fn new() -> Self {
26        Self {
27            files_scanned: 0,
28            dirs_scanned: 0,
29            bytes_scanned: 0,
30            current_path: PathBuf::new(),
31            errors_count: 0,
32            elapsed: Duration::ZERO,
33        }
34    }
35
36    /// Calculate scan rate in files per second.
37    pub fn files_per_second(&self) -> f64 {
38        if self.elapsed.as_secs_f64() > 0.0 {
39            self.files_scanned as f64 / self.elapsed.as_secs_f64()
40        } else {
41            0.0
42        }
43    }
44
45    /// Calculate scan rate in bytes per second.
46    pub fn bytes_per_second(&self) -> f64 {
47        if self.elapsed.as_secs_f64() > 0.0 {
48            self.bytes_scanned as f64 / self.elapsed.as_secs_f64()
49        } else {
50            0.0
51        }
52    }
53
54    /// Get total items scanned (files + dirs).
55    pub fn total_items(&self) -> u64 {
56        self.files_scanned + self.dirs_scanned
57    }
58}
59
60impl Default for ScanProgress {
61    fn default() -> Self {
62        Self::new()
63    }
64}