MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / archive

Method archive

atomic-repository/src/repository/archive.rs:30–143  ·  view source on GitHub ↗

This exports the working copy state at the current (or specified) Merkle state to the given destination. # Arguments `working_copy` - Validated identity of the source working directory `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 // Archiv

(
        &self,
        working_copy: WorkingCopyId,
        destination: P,
        options: ArchiveOptions,
    )

Source from the content-addressed store, hash-verified

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

Calls 15

list_trackedFunction · 0.85
ArchiveInterface · 0.85
validate_working_copyMethod · 0.80
desired_view_nameMethod · 0.80
as_refMethod · 0.80
read_txnMethod · 0.80
is_dirMethod · 0.80
archive_to_directoryMethod · 0.80
with_durationMethod · 0.80
with_archive_sizeMethod · 0.80
get_viewMethod · 0.45
should_includeMethod · 0.45