diff options
Diffstat (limited to 'crates/vcs/src/data')
| -rw-r--r-- | crates/vcs/src/data/sheet.rs | 22 | ||||
| -rw-r--r-- | crates/vcs/src/data/vault/sheets.rs | 16 |
2 files changed, 23 insertions, 15 deletions
diff --git a/crates/vcs/src/data/sheet.rs b/crates/vcs/src/data/sheet.rs index 3acc8ff..edf307a 100644 --- a/crates/vcs/src/data/sheet.rs +++ b/crates/vcs/src/data/sheet.rs @@ -14,8 +14,15 @@ use crate::{ pub type SheetName = String; pub type SheetPathBuf = PathBuf; pub type InputName = String; -pub type InputPackage = (InputName, Vec<(InputRaltivePathBuf, VirtualFileId)>); -pub type InputRaltivePathBuf = PathBuf; +pub type InputRelativePathBuf = PathBuf; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct InputPackage { + /// Name of the input package + pub name: InputName, + /// Files in this input package with their relative paths and virtual file IDs + pub files: Vec<(InputRelativePathBuf, VirtualFileId)>, +} const SHEET_NAME: &str = "{sheet-name}"; @@ -62,9 +69,12 @@ impl<'a> Sheet<'a> { pub fn add_input( &mut self, input_name: InputName, - files: Vec<(InputRaltivePathBuf, VirtualFileId)>, + files: Vec<(InputRelativePathBuf, VirtualFileId)>, ) { - self.data.inputs.push((input_name, files)); + self.data.inputs.push(InputPackage { + name: input_name, + files, + }); } /// Remove an input package from the sheet @@ -72,7 +82,7 @@ impl<'a> Sheet<'a> { self.data .inputs .iter() - .position(|(name, _)| name == input_name) + .position(|input| input.name == *input_name) .map(|pos| self.data.inputs.remove(pos)) } @@ -92,7 +102,7 @@ impl<'a> Sheet<'a> { /// Because I don't want a second instance of the sheet to be kept in memory. /// If needed, please deserialize and reload it. pub async fn persist(self) -> Result<(), std::io::Error> { - SheetData::write_to(&self.data, &self.sheet_path()).await + SheetData::write_to(&self.data, self.sheet_path()).await } /// Get the path to the sheet file diff --git a/crates/vcs/src/data/vault/sheets.rs b/crates/vcs/src/data/vault/sheets.rs index ede4077..dfad862 100644 --- a/crates/vcs/src/data/vault/sheets.rs +++ b/crates/vcs/src/data/vault/sheets.rs @@ -53,12 +53,11 @@ impl Vault { let path = entry.path(); // Check if it's a YAML file - if path.is_file() && path.extension().map_or(false, |ext| ext == "yaml") { - if let Some(_file_stem) = path.file_stem().and_then(|s| s.to_str()) { + if path.is_file() && path.extension().is_some_and(|ext| ext == "yaml") + && let Some(file_stem) = path.file_stem().and_then(|s| s.to_str()) { // Create a new SheetName and add it to the result list - sheet_names.push(SheetName::new()); + sheet_names.push(file_stem.to_string()); } - } } Ok(sheet_names) @@ -128,7 +127,7 @@ impl Vault { // Create the sheet file let sheet_data = SheetData { - holder: sheet_name.clone(), + holder: holder.clone(), inputs: Vec::new(), mapping: HashMap::new(), }; @@ -220,7 +219,7 @@ impl Vault { if !trash_dir.exists() { return Err(Error::new( std::io::ErrorKind::NotFound, - format!("Trash directory does not exist!"), + "Trash directory does not exist!".to_string(), )); } @@ -229,15 +228,14 @@ impl Vault { let entry = entry?; let path = entry.path(); - if path.is_file() { - if let Some(file_name) = path.file_stem().and_then(|s| s.to_str()) { + if path.is_file() + && let Some(file_name) = path.file_stem().and_then(|s| s.to_str()) { // Check if the filename starts with the sheet name if file_name.starts_with(&sheet_name) { found_path = Some(path); break; } } - } } let trash_path = found_path.ok_or_else(|| { |
