Skip to content

Commit

Permalink
repos: disallow wrong base (#74)
Browse files Browse the repository at this point in the history
* repos: disallow wrong base

* minor fix

* fix clippy
  • Loading branch information
skyzh authored Mar 22, 2021
1 parent b0b3532 commit 53ac10e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/homebrew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl SnapshotStorage<SnapshotPath> for Homebrew {
if url.starts_with(&bottles_base) {
url[bottles_base.len()..].to_string()
} else {
panic!("unsupported homebrew base");
panic!("Bottles URL doens't begin with its base: {:?}", url);
}
})
.map(|url| crate::utils::rewrite_url_string(&gen_map, &url))
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ fn main() {
concurrent_transfer: opts.transfer_config.concurrent_transfer,
no_delete: opts.transfer_config.no_delete,
print_plan: opts.transfer_config.print_plan,
dry_run: opts.transfer_config.dry_run,
snapshot_config,
};

Expand Down
2 changes: 2 additions & 0 deletions src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ pub struct TransferConfig {
pub concurrent_transfer: usize,
#[structopt(long, help = "Don't delete files")]
pub no_delete: bool,
#[structopt(long, help = "Enable dry run mode")]
pub dry_run: bool,
#[structopt(
long,
help = "Print first n records of transfer plan",
Expand Down
6 changes: 3 additions & 3 deletions src/pypi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ impl SnapshotStorage<SnapshotPath> for Pypi {
let snapshot = packages?
.into_iter()
.flatten()
.filter_map(|(url, _)| {
.map(|(url, _)| {
if url.starts_with(&package_base) {
Some(url[package_base.len()..].to_string())
url[package_base.len()..].to_string()
} else {
None
panic!("PyPI package isn't stored on base: {:?}", url);
}
})
.collect();
Expand Down
5 changes: 5 additions & 0 deletions src/simple_diff_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub struct SimpleDiffTransferConfig {
pub progress: bool,
pub concurrent_transfer: usize,
pub no_delete: bool,
pub dry_run: bool,
pub snapshot_config: SnapshotConfig,
pub print_plan: usize,
}
Expand Down Expand Up @@ -254,6 +255,10 @@ where
deletions.len()
);

if self.config.dry_run {
return Ok(());
}

info!(logger, "updating objects");

let source = Arc::new(self.source);
Expand Down

0 comments on commit 53ac10e

Please sign in to comment.