MCPcopy Create free account
hub / github.com/archlinux/alpm / append_relative_files

Function append_relative_files

alpm-package/src/package.rs:160–199  ·  view source on GitHub ↗

Appends relative files from an input directory to a [`TarballBuilder`]. Before appending any files, all provided `input_paths` are validated against `mtree` (ALPM-MTREE data). # Errors Returns an error if - validating any path in `input_paths` using `mtree` fails, - retrieving files relative to `input_dir` fails, - or adding one of the relative paths to the `builder` fails.

(
    mut builder: TarballBuilder<'c>,
    mtree: &Mtree,
    input_paths: &InputPaths,
)

Source from the content-addressed store, hash-verified

158/// - retrieving files relative to `input_dir` fails,
159/// - or adding one of the relative paths to the `builder` fails.
160fn append_relative_files<'c>(
161 mut builder: TarballBuilder<'c>,
162 mtree: &Mtree,
163 input_paths: &InputPaths,
164) -> Result<TarballBuilder<'c>, crate::Error> {
165 // Validate all paths using the ALPM-MTREE data before appending them to the builder.
166 let mtree_path = PathBuf::from(MetadataFileName::Mtree.as_ref());
167 let check_paths = {
168 let all_paths = input_paths.paths();
169 // If there is an ALPM-MTREE file, exclude it from the validation, as the ALPM-MTREE data
170 // does not cover it.
171 if let Some(mtree_position) = all_paths.iter().position(|path| path == &mtree_path) {
172 let before = &all_paths[..mtree_position];
173 let after = if all_paths.len() > mtree_position {
174 &all_paths[mtree_position + 1..]
175 } else {
176 &[]
177 };
178 &[before, after].concat()
179 } else {
180 all_paths
181 }
182 };
183 mtree.validate_paths(&InputPaths::new(input_paths.base_dir(), check_paths)?)?;
184
185 // Append all files/directories to the archive.
186 for relative_file in input_paths.paths() {
187 let from_path = input_paths.base_dir().join(relative_file.as_path());
188 builder
189 .inner_mut()
190 .append_path_with_name(from_path.as_path(), relative_file.as_path())
191 .map_err(|source| Error::AppendFileToArchive {
192 from_path,
193 to_path: relative_file.clone(),
194 source,
195 })?
196 }
197
198 Ok(builder)
199}
200
201/// An entry in a package archive.
202///

Callers 1

try_fromMethod · 0.85

Calls 8

validate_pathsMethod · 0.80
base_dirMethod · 0.80
inner_mutMethod · 0.80
as_refMethod · 0.45
pathsMethod · 0.45
lenMethod · 0.45
joinMethod · 0.45
as_pathMethod · 0.45

Tested by

no test coverage detected