This exports the working copy state at the current (or specified) Merkle state to the given destination. # Arguments `destination` - Path to the output archive or directory `options` - Options controlling archive creation # Returns An `ArchiveOutcome` with details about the created archive. # Example ```rust,ignore // Archive to a tarball let outcome = repo.archive("release.tar.gz", ArchiveO
(
&self,
destination: P,
options: ArchiveOptions,
)
| 27 | /// ArchiveOptions::default().with_prefix("myproject-1.0/"))?; |
| 28 | /// ``` |
| 29 | pub fn archive<P: AsRef<Path>>( |
| 30 | &self, |
| 31 | destination: P, |
| 32 | options: ArchiveOptions, |
| 33 | ) -> Result<ArchiveOutcome, RepositoryError> { |
| 34 | use std::time::Instant; |
| 35 | |
| 36 | let start = Instant::now(); |
| 37 | let dest_path = destination.as_ref(); |
| 38 | |
| 39 | // Get current state |
| 40 | let txn = self |
| 41 | .pristine |
| 42 | .read_txn() |
| 43 | .map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 44 | |
| 45 | let view_name = options.view.as_deref().unwrap_or(&self.current_view); |
| 46 | let view = txn |
| 47 | .get_view(view_name) |
| 48 | .map_err(|e| RepositoryError::Database(e.to_string()))? |
| 49 | .ok_or_else(|| RepositoryError::ViewNotFound { |
| 50 | name: view_name.to_string(), |
| 51 | })?; |
| 52 | |
| 53 | let state = options.state.unwrap_or(view.state); |
| 54 | |
| 55 | // Build manifest from tracked files |
| 56 | let mut manifest = ArchiveManifest::new(); |
| 57 | let tracked_files = |
| 58 | list_tracked(&txn).map_err(|e| RepositoryError::Database(e.to_string()))?; |
| 59 | |
| 60 | for file in tracked_files { |
| 61 | // Apply include/exclude filters |
| 62 | let path_str = file.path.to_string_lossy(); |
| 63 | if !options.should_include(&path_str) { |
| 64 | continue; |
| 65 | } |
| 66 | |
| 67 | // Get file info from working copy |
| 68 | let full_path = self.root.join(&file.path); |
| 69 | if full_path.is_file() { |
| 70 | let metadata = std::fs::metadata(&full_path).map_err(RepositoryError::Io)?; |
| 71 | let size = metadata.len(); |
| 72 | |
| 73 | let path_string = file.path.to_string_lossy().to_string(); |
| 74 | let mut entry = ArchiveEntry::file(&path_string, size); |
| 75 | |
| 76 | // Apply prefix if specified |
| 77 | if let Some(ref prefix) = options.prefix { |
| 78 | entry.path = format!("{}{}", prefix, path_string); |
| 79 | } |
| 80 | |
| 81 | manifest.add(entry); |
| 82 | } else if full_path.is_dir() { |
| 83 | let path_string = file.path.to_string_lossy().to_string(); |
| 84 | let mut entry = ArchiveEntry::directory(&path_string); |
| 85 | |
| 86 | if let Some(ref prefix) = options.prefix { |