File size: 2,198 Bytes
e5034c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use std::path::PathBuf;

use derive_setters::Setters;

/// Configuration for filesystem walking operations
#[derive(Debug, Clone, Setters)]
#[setters(strip_option, into)]
pub struct Walker {
    /// Base directory to start walking from
    pub cwd: PathBuf,
    /// Maximum depth of directory traversal (None for unlimited)
    pub max_depth: Option<usize>,
    /// Maximum number of entries per directory (None for unlimited)
    pub max_breadth: Option<usize>,
    /// Maximum size of individual files to process (None for unlimited)
    pub max_file_size: Option<u64>,
    /// Maximum number of files to process in total (None for unlimited)
    pub max_files: Option<usize>,
    /// Maximum total size of all files combined (None for unlimited)
    pub max_total_size: Option<u64>,
    /// Whether to skip binary files
    pub skip_binary: bool,
}

impl Walker {
    /// Creates a new WalkerConfig with conservative default limits
    pub fn conservative() -> Self {
        Self {
            cwd: PathBuf::new(),
            max_depth: Some(5),
            max_breadth: Some(10),
            max_file_size: Some(1024 * 1024), // 1MB
            max_files: Some(100),
            max_total_size: Some(10 * 1024 * 1024), // 10MB
            skip_binary: true,
        }
    }

    /// Creates a new WalkerConfig with no limits (use with caution)
    pub fn unlimited() -> Self {
        Self {
            cwd: PathBuf::new(),
            max_depth: None,
            max_breadth: None,
            max_file_size: None,
            max_files: None,
            max_total_size: None,
            skip_binary: false,
        }
    }
}

impl Default for Walker {
    fn default() -> Self {
        Self::conservative()
    }
}

/// Represents a file or directory found during filesystem traversal
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct WalkedFile {
    /// Relative path from the base directory
    pub path: String,
    /// File name (None for root directory)
    pub file_name: Option<String>,
    /// Size in bytes
    pub size: u64,
}

impl WalkedFile {
    /// Returns true if this represents a directory
    pub fn is_dir(&self) -> bool {
        self.path.ends_with('/')
    }
}