dev_scripts/sync/
mod.rs

1use std::{
2    collections::HashSet,
3    fs::{DirEntry, read_dir},
4    path::Path,
5};
6
7use anyhow::Result;
8use clap::ValueEnum;
9use strum::{Display, EnumIter};
10
11/// The [mirror] module contains all logic to download data from an Arch Linux package mirror.
12/// This includes the database files or packages.
13pub mod mirror;
14/// The [pkgsrc] module handles the download of package source repositories.
15/// This requires interaction with `git` and the official Arch Linux Gitlab, where all of the
16/// package source repositories for the official packages are located.
17pub mod pkgsrc;
18
19/// All Arch Linux package repositories we may want to test.
20#[derive(Clone, Display, Debug, EnumIter, PartialEq, ValueEnum)]
21pub enum PackageRepositories {
22    #[strum(to_string = "core")]
23    Core,
24    #[strum(to_string = "extra")]
25    Extra,
26    #[strum(to_string = "multilib")]
27    Multilib,
28}
29
30/// A small helper function that returns a list of unique file names in a directory.
31pub fn filenames_in_dir(path: &Path) -> Result<HashSet<String>> {
32    let entries = read_dir(path)?;
33    let entries: Vec<DirEntry> = entries.collect::<Result<Vec<DirEntry>, std::io::Error>>()?;
34    let files: HashSet<String> = entries
35        .iter()
36        .map(|entry| entry.file_name().to_string_lossy().to_string())
37        .collect();
38
39    Ok(files)
40}