diff --git a/Cargo.lock b/Cargo.lock index 9549447..61e4ba9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -953,9 +953,9 @@ checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "registry-conformance" -version = "0.3.0" +version = "0.4.0" source = "sparse+https://integer32llc.github.io/registry-conformance/" -checksum = "1616afb1bbc576b6aa79fc318f8b0604340945be5765de85954fa52532b4d38e" +checksum = "d32618611649b0df9be05d325c0ddfa5fb7e088a5e50662a4b7a3722da73f1c7" dependencies = [ "base64", "futures", diff --git a/Cargo.toml b/Cargo.toml index a7a7370..ea0a153 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ unused_crate_dependencies = "deny" [workspace.dependencies] argh = { version = "0.1.12", default-features = false } -registry-conformance = { version = "0.3.0", registry = "registry-conformance" } +registry-conformance = { version = "0.4.0", registry = "registry-conformance" } snafu = { version = "0.8.2", default-features = false, features = ["rust_1_65", "std"] } tokio = { version = "1.37.0", default-features = false, features = ["macros", "process", "rt-multi-thread"] } diff --git a/conformance/src/main.rs b/conformance/src/main.rs index b5edee3..a3ec985 100644 --- a/conformance/src/main.rs +++ b/conformance/src/main.rs @@ -185,18 +185,21 @@ impl Margo { Ok(()) } - async fn yank_crate_(&mut self, crate_: &CreatedCrate) -> Result<(), YankError> { + async fn yank_crate_(&mut self, crate_: &CreatedCrate, yanked: bool) -> Result<(), YankError> { use yank_error::*; - self.command() - .arg("yank") + let mut cmd = self.command(); + cmd.arg("yank") .arg("--registry") .arg(&self.directory) .arg(crate_.name()) - .args(["--version", crate_.version()]) - .expect_success() - .await - .context(ExecutionSnafu)?; + .args(["--version", crate_.version()]); + + if !yanked { + cmd.arg("--undo"); + } + + cmd.expect_success().await.context(ExecutionSnafu)?; Ok(()) } @@ -295,7 +298,11 @@ impl Registry for Margo { } async fn yank_crate(&mut self, crate_: &CreatedCrate) -> Result<(), Error> { - Ok(self.yank_crate_(crate_).await?) + Ok(self.yank_crate_(crate_, true).await?) + } + + async fn unyank_crate(&mut self, crate_: &CreatedCrate) -> Result<(), Error> { + Ok(self.yank_crate_(crate_, false).await?) } async fn shutdown(self) -> Result<(), Error> { diff --git a/src/main.rs b/src/main.rs index 311ca50..dfd8ab2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -91,6 +91,10 @@ struct YankArgs { #[argh(option)] registry: PathBuf, + /// undo a previous yank + #[argh(switch)] + undo: bool, + /// the version of the crate #[argh(option)] version: Version, @@ -284,7 +288,7 @@ fn do_generate_html(_global: &Global, html: GenerateHtmlArgs) -> Result<(), Erro fn do_yank(_global: &Global, yank: YankArgs) -> Result<(), Error> { let r = Registry::open(yank.registry)?; - r.yank(yank.name, yank.version)?; + r.yank(yank.name, yank.version, !yank.undo)?; Ok(()) } @@ -383,7 +387,6 @@ impl Registry { fs::create_dir_all(path).context(CrateDirSnafu { path })?; } - // FUTURE: Add `unyank` subcommand // FUTURE: Add `remove` subcommand // FUTURE: Stronger file system consistency (atomic file overwrites, rollbacks on error) @@ -412,12 +415,12 @@ impl Registry { Err(HtmlError) } - fn yank(&self, name: CrateName, version: Version) -> Result<(), YankError> { + fn yank(&self, name: CrateName, version: Version, yanked: bool) -> Result<(), YankError> { use yank_error::*; self.read_modify_write(&name, |index| { let entry = index.get_mut(&version).context(VersionSnafu)?; - entry.yanked = true; + entry.yanked = yanked; Ok(()) }) }