Skip to content

Commit

Permalink
Support unyanking a crate
Browse files Browse the repository at this point in the history
  • Loading branch information
shepmaster committed May 17, 2024
1 parent 9660c81 commit c7d8661
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }

Expand Down
23 changes: 15 additions & 8 deletions conformance/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down Expand Up @@ -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> {
Expand Down
11 changes: 7 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(())
}

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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(())
})
}
Expand Down

0 comments on commit c7d8661

Please sign in to comment.