fix: clear old revisions

This commit is contained in:
2026-02-03 17:24:13 -08:00
parent c48880d0ca
commit a1a1466116
5 changed files with 85 additions and 1 deletions

66
Cargo.lock generated
View File

@@ -73,6 +73,15 @@ version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
[[package]]
name = "block2"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5"
dependencies = [
"objc2",
]
[[package]]
name = "bumpalo"
version = "3.19.1"
@@ -85,6 +94,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "cfg_aliases"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]]
name = "clap"
version = "4.5.56"
@@ -153,6 +168,17 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "ctrlc"
version = "3.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73736a89c4aff73035ba2ed2e565061954da00d4970fc9ac25dcc85a2a20d790"
dependencies = [
"dispatch2",
"nix",
"windows-sys",
]
[[package]]
name = "dirs"
version = "6.0.0"
@@ -174,6 +200,18 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "dispatch2"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec"
dependencies = [
"bitflags",
"block2",
"libc",
"objc2",
]
[[package]]
name = "either"
version = "1.15.0"
@@ -336,6 +374,7 @@ name = "minecraft-sync"
version = "0.1.0"
dependencies = [
"clap",
"ctrlc",
"dirs",
"flate2",
"indicatif",
@@ -358,6 +397,18 @@ dependencies = [
"simd-adler32",
]
[[package]]
name = "nix"
version = "0.30.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6"
dependencies = [
"bitflags",
"cfg-if",
"cfg_aliases",
"libc",
]
[[package]]
name = "nu-ansi-term"
version = "0.50.3"
@@ -367,6 +418,21 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "objc2"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7c2599ce0ec54857b29ce62166b0ed9b4f6f1a70ccc9a71165b6154caca8c05"
dependencies = [
"objc2-encode",
]
[[package]]
name = "objc2-encode"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33"
[[package]]
name = "once_cell"
version = "1.21.3"

View File

@@ -5,6 +5,7 @@ edition = "2024"
[dependencies]
clap = { version = "4.5.56", features = ["derive"] }
ctrlc = "3.5.1"
dirs = "6.0.0"
flate2 = "1.1.8"
indicatif = "0.18.3"

2
justfile Normal file
View File

@@ -0,0 +1,2 @@
dev arg="":
RUST_LOG=debug cargo run --profile dev-fast -- {{arg}}

View File

@@ -22,6 +22,12 @@ pub enum ErrorKind {
#[source]
source: std::io::Error,
},
#[error("error clearing old revisions at {path}")]
ClearRevisions {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("error persisting archive to {path}")]
PersistError {
path: PathBuf,

View File

@@ -1,5 +1,5 @@
use std::fs::DirEntry;
use std::io::BufWriter;
use std::io::{self, BufWriter};
use std::path::{self, Path};
use std::{fs, path::PathBuf};
@@ -52,6 +52,15 @@ impl StorageImpl for FSStorage {
path = ?archive_path,
"stored revision"
);
let remove_path = base_path().join(&format!("revision_{revision}.tar.gz"));
match fs::remove_file(&remove_path) {
Ok(_) => {}
Err(e) => match e.kind() {
io::ErrorKind::NotFound => {}
_ => return Err(Error::clear_revisions(e, &remove_path)),
},
};
tracing::debug!(revision, path = ?remove_path, "cleared revisions");
Ok(())
}
}