Archive to a directory (internal helper).
(
&self,
dest: &Path,
manifest: &ArchiveManifest,
options: &ArchiveOptions,
)
| 140 | |
| 141 | /// Archive to a directory (internal helper). |
| 142 | fn archive_to_directory( |
| 143 | &self, |
| 144 | dest: &Path, |
| 145 | manifest: &ArchiveManifest, |
| 146 | options: &ArchiveOptions, |
| 147 | ) -> Result<u64, RepositoryError> { |
| 148 | let mut archive = DirectoryArchive::new(dest).map_err(RepositoryError::Io)?; |
| 149 | |
| 150 | let mut total_size = 0u64; |
| 151 | |
| 152 | // First create directories |
| 153 | for entry in manifest.directories() { |
| 154 | archive |
| 155 | .create_directory(&entry.path, entry.mode, 0) |
| 156 | .map_err(RepositoryError::Io)?; |
| 157 | } |
| 158 | |
| 159 | // Then copy files |
| 160 | for entry in manifest.files() { |
| 161 | // Determine source path - strip prefix if it was added |
| 162 | let source_rel_path = if let Some(ref prefix) = options.prefix { |
| 163 | if entry.path.starts_with(prefix) { |
| 164 | entry.path[prefix.len()..].to_string() |
| 165 | } else { |
| 166 | entry.path.clone() |
| 167 | } |
| 168 | } else { |
| 169 | entry.path.clone() |
| 170 | }; |
| 171 | let source_path = self.root.join(&source_rel_path); |
| 172 | |
| 173 | let mut writer = archive |
| 174 | .create_file(&entry.path, entry.size, entry.mode, 0) |
| 175 | .map_err(RepositoryError::Io)?; |
| 176 | |
| 177 | // Copy file contents |
| 178 | let mut source = std::fs::File::open(&source_path).map_err(RepositoryError::Io)?; |
| 179 | let copied = std::io::copy(&mut source, &mut writer).map_err(RepositoryError::Io)?; |
| 180 | total_size += copied; |
| 181 | |
| 182 | archive.close_file(writer).map_err(RepositoryError::Io)?; |
| 183 | } |
| 184 | |
| 185 | archive.finish().map_err(RepositoryError::Io)?; |
| 186 | |
| 187 | Ok(total_size) |
| 188 | } |
| 189 | } |
no test coverage detected