Skip to main content

flashkraft_core/domain/
drive_info.rs

1//! Drive Information Domain Model
2//!
3//! This module contains the DriveInfo struct which represents
4//! information about a storage drive in the system.
5
6/// Information about a storage drive
7#[derive(Debug, Clone)]
8pub struct DriveInfo {
9    /// Name of the drive
10    pub name: String,
11    /// Mount point of the drive
12    pub mount_point: String,
13    /// Size of the drive in gigabytes
14    pub size_gb: f64,
15    /// Raw device path (e.g., /dev/sde)
16    pub device_path: String,
17    /// Whether this drive is a system drive
18    pub is_system: bool,
19    /// Whether this drive is read-only (locked)
20    pub is_read_only: bool,
21    /// Whether this drive is disabled for selection
22    pub disabled: bool,
23}
24
25impl DriveInfo {
26    /// Create a new DriveInfo instance
27    ///
28    /// # Arguments
29    ///
30    /// * `name` - The name of the drive
31    /// * `mount_point` - Where the drive is mounted
32    /// * `size_gb` - Size in gigabytes
33    /// * `device_path` - Raw device path (e.g., /dev/sde)
34    pub fn new(name: String, mount_point: String, size_gb: f64, device_path: String) -> Self {
35        Self {
36            name,
37            mount_point,
38            size_gb,
39            device_path,
40            is_system: false,
41            is_read_only: false,
42            disabled: false,
43        }
44    }
45
46    /// Create a new DriveInfo instance with all fields
47    ///
48    /// # Arguments
49    ///
50    /// * `name` - The name of the drive
51    /// * `mount_point` - Where the drive is mounted
52    /// * `size_gb` - Size in gigabytes
53    /// * `device_path` - Raw device path (e.g., /dev/sde)
54    /// * `is_system` - Whether this is a system drive
55    /// * `is_read_only` - Whether this drive is read-only
56    pub fn with_constraints(
57        name: String,
58        mount_point: String,
59        size_gb: f64,
60        device_path: String,
61        is_system: bool,
62        is_read_only: bool,
63    ) -> Self {
64        Self {
65            name,
66            mount_point,
67            size_gb,
68            device_path,
69            is_system,
70            is_read_only,
71            disabled: false,
72        }
73    }
74
75    /// Get a display string for the drive
76    ///
77    /// # Returns
78    ///
79    /// A formatted string showing name, size, and mount point
80    #[allow(dead_code)]
81    pub fn display_string(&self) -> String {
82        format!(
83            "{} - {:.2} GB ({})",
84            self.name, self.size_gb, self.mount_point
85        )
86    }
87}
88
89impl PartialEq for DriveInfo {
90    fn eq(&self, other: &Self) -> bool {
91        self.device_path == other.device_path
92    }
93}
94
95#[cfg(test)]
96mod tests {
97    use super::*;
98
99    #[test]
100    fn test_drive_display_string() {
101        let drive = DriveInfo::new(
102            "USB Drive".to_string(),
103            "/media/usb".to_string(),
104            32.0,
105            "/dev/sdb".to_string(),
106        );
107        assert_eq!(drive.display_string(), "USB Drive - 32.00 GB (/media/usb)");
108    }
109
110    #[test]
111    fn test_drive_equality() {
112        let drive1 = DriveInfo::new(
113            "USB".to_string(),
114            "/media/usb".to_string(),
115            32.0,
116            "/dev/sdb".to_string(),
117        );
118        let drive2 = DriveInfo::new(
119            "USB".to_string(),
120            "/media/usb".to_string(),
121            32.0,
122            "/dev/sdb".to_string(),
123        );
124        let drive3 = DriveInfo::new(
125            "USB2".to_string(),
126            "/media/usb2".to_string(),
127            32.0,
128            "/dev/sdc".to_string(),
129        );
130
131        assert_eq!(drive1, drive2);
132        assert_ne!(drive1, drive3);
133    }
134}