Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hil: add option for reusing existing rts #269

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion hil/src/commands/flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@ pub struct Flash {
#[arg(long)]
slow: bool,
/// If this flag is given, overwites any existing files when downloading the rts.
#[arg(long)]
#[arg(long, conflicts_with = "reuse_existing")]
overwrite_existing: bool,
/// If this flag is given, reuses rts if already exists on path.
#[arg(long, conflicts_with = "overwite_existing")]
reuse_existing: bool,
}

impl Flash {
pub async fn run(self) -> Result<()> {
let args = self;
let existing_file_behavior = if args.overwrite_existing {
ExistingFileBehavior::Overwrite
} else if args.reuse_existing {
ExistingFileBehavior::Reuse
} else {
ExistingFileBehavior::Abort
};
Expand Down
18 changes: 16 additions & 2 deletions hil/src/download_s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub enum ExistingFileBehavior {
Overwrite,
/// If a file exists, abort
Abort,
/// If a file exists, reuse it
Reuse,
}

struct ContentRange(RangeInclusive<u64>);
Expand All @@ -54,9 +56,21 @@ pub async fn download_url(
out_path: &Utf8Path,
existing_file_behavior: ExistingFileBehavior,
) -> Result<()> {
if existing_file_behavior == ExistingFileBehavior::Abort {
ensure!(!out_path.exists(), "{out_path:?} already exists!");
let path_exists = out_path.exists();

match existing_file_behavior {
ExistingFileBehavior::Abort => {
ensure!(!path_exists, "{out_path:?} already exists!");
}
ExistingFileBehavior::Reuse => {
if path_exists {
info!("{out_path:?} already exists, reusing it");
return Ok(());
}
}
ExistingFileBehavior::Overwrite => {}
}

let parent_dir = out_path
.parent()
.expect("please provide the path to a file")
Expand Down
Loading