Fixed sorting issue on prune command

main
Michal 2 years ago
parent 4305937589
commit edc43e43f8

16
Cargo.lock generated

@ -10,6 +10,7 @@ dependencies = [
"colored",
"libc",
"mimalloc",
"regex",
"serde",
"serde_derive",
"tabled",
@ -258,6 +259,21 @@ dependencies = [
"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]]
name = "serde"
version = "1.0.140"

@ -25,4 +25,5 @@ serde_derive = { version = "1.0.139", default-features = false }
libc = { version = "0.2.126", default-features = false }
colored = { version = "2.0.0", default-features = false }
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,19 +40,19 @@ 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" }
let mut packages: Vec<PackageFile> = vec![];
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 mut parts = file.split('-');
let name = parts.next().unwrap();
let ver = parts.next().unwrap();
let rel = parts.next().unwrap();
let ext = parts.next().unwrap();
let package = PackageFile {
name: name.to_string(),
ver: ver.to_string() + "-" + rel,
ext: ext.to_string(),
};
log!(verbose, "Package: {:?}", package);
packages.push(package);
for cap in re.captures_iter(file) {
let name = cap[1].to_string();
let mut ver = cap[2].to_string();
ver.remove(0).to_string();
let mut ext = cap[3].to_string();
ext.remove(0).to_string();
let package = PackageFile { name, ver, ext };
log!(verbose, "Package: {:?}", package);
packages.push(package);
}
}
// Split packages into a Vector of Vectors by unique name

Loading…
Cancel
Save