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

Method download_package_source_repositories

dev-scripts/src/sync/pkgsrc.rs:51–100  ·  view source on GitHub ↗

Download all official package source git repositories.

(&self)

Source from the content-addressed store, hash-verified

49impl PkgSrcDownloader {
50 /// Download all official package source git repositories.
51 pub fn download_package_source_repositories(&self) -> Result<(), Error> {
52 // Query the arch web API to get a list all official active repositories
53 // The returned json is a map where the keys are the package names
54 // and the value is a list of maintainer names.
55 let repos = get(PKGBASE_MAINTAINER_URL)
56 .map_err(|source| Error::HttpQueryFailed {
57 context: "retrieving the list of pkgbases".to_string(),
58 source,
59 })?
60 .json::<HashMap<String, Vec<String>>>()
61 .map_err(|source| Error::HttpQueryFailed {
62 context: "deserializing the response as JSON".to_string(),
63 source,
64 })?;
65
66 let all_repo_names: Vec<String> = repos.keys().map(String::from).collect();
67 info!("Found {} official packages.", all_repo_names.len());
68
69 let download_dir = self.cache_dir.as_ref().join(DOWNLOAD_DIR).join(PKGSRC_DIR);
70
71 // Remove all old repos before trying to update them.
72 self.remove_old_repos(&all_repo_names, &download_dir)?;
73
74 // Copy all .SRCINFO files to the target directory
75 self.parallel_update_or_clone(&all_repo_names, &download_dir)?;
76
77 // Copy .SRCINFO and PKGBUILD files to the target directory
78 for repo in all_repo_names {
79 let download_path = download_dir.join(&repo);
80 for file in [SRCINFO_FILE_NAME, PKGBUILD_FILE_NAME] {
81 if download_path.join(file).exists() {
82 let target_dir = self.cache_dir.as_ref().join(PKGSRC_DIR).join(&repo);
83 create_dir_all(&target_dir).map_err(|source| Error::IoPath {
84 path: target_dir.to_path_buf(),
85 context: "recursively creating a directory".to_string(),
86 source,
87 })?;
88 copy(download_path.join(file), target_dir.join(file)).map_err(|source| {
89 Error::IoPath {
90 path: download_path.join(file),
91 context: "copying the file to the target directory".to_string(),
92 source,
93 }
94 })?;
95 }
96 }
97 }
98
99 Ok(())
100 }
101
102 /// Remove all local repositories for packages that no longer exist in the official
103 /// repositories.

Callers 1

test_filesFunction · 0.80

Calls 5

remove_old_reposMethod · 0.80
joinMethod · 0.45
as_refMethod · 0.45
to_path_bufMethod · 0.45

Tested by 1

test_filesFunction · 0.64