From c1a6460f97346ab91892cf960aa837fa1781071e Mon Sep 17 00:00:00 2001 From: Michal Date: Sat, 23 Jul 2022 16:57:34 +0100 Subject: [PATCH] Fixed sorting issue on prune command --- Cargo.lock | 16 ++++++++++++++++ Cargo.toml | 3 ++- src/operations/prune.rs | 24 ++++++++++++------------ 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b260f19..4a6fe4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index b593ea1..68a509c 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } \ No newline at end of file +termion = { version = "1.5.6", default-features = false } +regex = { version = "1.6.0", default-features = false, features = ["std"] } diff --git a/src/operations/prune.rs b/src/operations/prune.rs index 1749e51..59e5fe9 100644 --- a/src/operations/prune.rs +++ b/src/operations/prune.rs @@ -40,19 +40,19 @@ pub fn prune(verbose: bool) { // Split files into Vec, 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 = 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