test
This commit is contained in:
parent
5190262192
commit
d28f1d0032
@ -0,0 +1,3 @@
|
|||||||
|
pub mod packages;
|
||||||
|
pub mod pin;
|
||||||
|
pub mod sources;
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, BufRead};
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use crate::structs::{AptSource, RepoType};
|
||||||
|
|
||||||
|
/// Loads Debian APT sources from a given file path (e.g., "/etc/apt/sources.list")
|
||||||
|
pub fn load_sources(path: &str) -> io::Result<Vec<AptSource>> {
|
||||||
|
let file = File::open(Path::new(path))?;
|
||||||
|
let reader = io::BufReader::new(file);
|
||||||
|
|
||||||
|
let mut sources = Vec::new();
|
||||||
|
let mut counter = 1;
|
||||||
|
|
||||||
|
for line in reader.lines() {
|
||||||
|
let line = line?;
|
||||||
|
let trimmed = line.trim();
|
||||||
|
|
||||||
|
// Skip empty lines and comments
|
||||||
|
if trimmed.is_empty() || trimmed.starts_with('#') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let parts: Vec<&str> = trimmed.split_whitespace().collect();
|
||||||
|
if parts.len() < 3 {
|
||||||
|
eprintln!("Skipping malformed line: {}", trimmed);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine repository type
|
||||||
|
let repo_type = match parts[0] {
|
||||||
|
"deb" => RepoType::Bin,
|
||||||
|
"deb-src" => RepoType::Src,
|
||||||
|
other => {
|
||||||
|
eprintln!("Unknown repo type: {}", other);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// parts[1] = URI
|
||||||
|
// parts[2] = distribution (bookworm, trixie, etc.)
|
||||||
|
// parts[3..] = components
|
||||||
|
let uri = parts[1].to_string();
|
||||||
|
let debian_version = parts[2].to_string();
|
||||||
|
let components = parts[3..].iter().map(|s| s.to_string()).collect();
|
||||||
|
|
||||||
|
sources.push(AptSource {
|
||||||
|
name: Some(format!("repo{}", counter)),
|
||||||
|
bin_repo: repo_type,
|
||||||
|
uri,
|
||||||
|
debian_version,
|
||||||
|
components,
|
||||||
|
});
|
||||||
|
|
||||||
|
counter += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(sources)
|
||||||
|
}
|
||||||
13
src/main.rs
13
src/main.rs
@ -1,3 +1,12 @@
|
|||||||
fn main() {
|
mod loaders;
|
||||||
println!("Hello, world!");
|
mod structs;
|
||||||
|
|
||||||
|
use crate::loaders::sources::load_sources;
|
||||||
|
|
||||||
|
fn main() -> std::io::Result<()> {
|
||||||
|
let sources = load_sources("/etc/apt/sources.list")?;
|
||||||
|
for source in sources {
|
||||||
|
println!("{:?}", source);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,7 @@ pub struct System {
|
|||||||
pub arch: String,
|
pub arch: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub enum RepoType {
|
pub enum RepoType {
|
||||||
Bin, // deb
|
Bin, // deb
|
||||||
Src, // deb-src
|
Src, // deb-src
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user