Fixed sorting issue on prune command

main
Michal 2 years ago
parent 0cf709bc90
commit c1a6460f97
No known key found for this signature in database
GPG Key ID: A6A1A4DCB22279B9

16
Cargo.lock generated

@ -10,6 +10,7 @@ dependencies = [
"colored", "colored",
"libc", "libc",
"mimalloc", "mimalloc",
"regex",
"serde", "serde",
"serde_derive", "serde_derive",
"tabled", "tabled",
@ -258,6 +259,21 @@ dependencies = [
"redox_syscall", "redox_syscall",
] ]
[[package]]
name = "regex"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
dependencies = [
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.6.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.140" version = "1.0.140"

@ -26,3 +26,4 @@ libc = { version = "0.2.126", default-features = false }
colored = { version = "2.0.0", default-features = false } colored = { version = "2.0.0", default-features = false }
tabled = { version = "0.8.0", default-features = false, features = ["derive"] } tabled = { version = "0.8.0", default-features = false, features = ["derive"] }
termion = { version = "1.5.6", default-features = false } termion = { version = "1.5.6", default-features = false }
regex = { version = "1.6.0", default-features = false, features = ["std"] }

@ -40,20 +40,20 @@ pub fn prune(verbose: bool) {
// Split files into Vec<PackageFile>, turning name-1.0.0-1-x86_64.tar.gz into PackageFile { name: "name", ver: "1.0.0-1", ext: "x86_64.tar.gz" } // Split files into Vec<PackageFile>, turning name-1.0.0-1-x86_64.tar.gz into PackageFile { name: "name", ver: "1.0.0-1", ext: "x86_64.tar.gz" }
let mut packages: Vec<PackageFile> = vec![]; let mut packages: Vec<PackageFile> = vec![];
for file in files { for file in files {
// Regex fuckery. Please don't mess with this.
let re = regex::Regex::new(r"^(.+)(-.+-.+)(-.+\..+\..+\.+..+)$").unwrap();
let file = file.to_str().unwrap(); let file = file.to_str().unwrap();
let mut parts = file.split('-'); for cap in re.captures_iter(file) {
let name = parts.next().unwrap(); let name = cap[1].to_string();
let ver = parts.next().unwrap(); let mut ver = cap[2].to_string();
let rel = parts.next().unwrap(); ver.remove(0).to_string();
let ext = parts.next().unwrap(); let mut ext = cap[3].to_string();
let package = PackageFile { ext.remove(0).to_string();
name: name.to_string(), let package = PackageFile { name, ver, ext };
ver: ver.to_string() + "-" + rel,
ext: ext.to_string(),
};
log!(verbose, "Package: {:?}", package); log!(verbose, "Package: {:?}", package);
packages.push(package); packages.push(package);
} }
}
// Split packages into a Vector of Vectors by unique name // Split packages into a Vector of Vectors by unique name
let mut packages_by_name: Vec<Vec<&PackageFile>> = vec![]; let mut packages_by_name: Vec<Vec<&PackageFile>> = vec![];

Loading…
Cancel
Save