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

Clean all by default #34

Merged
merged 4 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions doc/src/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Improve the verbose output from `submit`.
* `show status` hides actions with 0 directories by default. Pass `--all` to show all
actions.
* `clean` now cleans all caches by default.

*Fixed:*

Expand Down
9 changes: 4 additions & 5 deletions doc/src/row/clean.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

Usage
```bash
row clean [OPTIONS] <--directory|--submitted|--completed|--all>
row clean [OPTIONS]
```

`row clean` safely removes cache files generated by **row**. The
[cache concepts page](../guide/concepts/cache.md) describes cases where you might need
to clean the cache.

## `[OPTIONS]`

### `--all`
By default, `row clean` removes all cache files. Pass one or more of the options to
remove only selected caches.

Remove all caches.
## `[OPTIONS]`

### `--completed`

Expand Down
26 changes: 13 additions & 13 deletions src/cli/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ use row::{
#[derive(Args, Debug)]
pub struct Arguments {
#[command(flatten)]
selection: Selection,
selection: Option<Selection>,

/// Force removal of the completed and/or submitted cache when there are submitted jobs.
#[arg(long, display_order = 0)]
force: bool,
}

#[derive(Args, Debug)]
#[group(required = true, multiple = false)]
#[group(multiple = true)]
#[allow(clippy::struct_excessive_bools)]
pub struct Selection {
/// Remove the directory cache.
Expand All @@ -39,10 +39,6 @@ pub struct Selection {
/// Remove the completed cache.
#[arg(long, display_order = 0)]
completed: bool,

/// Remove all caches.
#[arg(long, display_order = 0)]
all: bool,
}

/// Remove row cache files.
Expand All @@ -57,19 +53,23 @@ pub fn clean(
// Delete all existing completion staging files.
project.close(multi_progress)?;

let selection = &args.selection;
let selection = args.selection.as_ref().unwrap_or(&Selection {
directory: true,
submitted: true,
completed: true,
});

let num_submitted = project.state().num_submitted();
if num_submitted > 0 {
let force_needed = selection.completed || selection.submitted || selection.all;
let force_needed = selection.completed || selection.submitted;

if force_needed {
warn!("There are {num_submitted} directories with submitted jobs.");
}
if selection.submitted || selection.all {
if selection.submitted {
warn!("The submitted cache is not recoverable. Row may resubmit running jobs.");
}
if selection.completed || selection.all {
if selection.completed {
warn!("These jobs may add to the completed cache after it is cleaned.");
}
if force_needed && !args.force {
Expand All @@ -80,7 +80,7 @@ pub fn clean(

let data_directory = project.workflow().root.join(DATA_DIRECTORY_NAME);

if selection.submitted || selection.all {
if selection.submitted {
let path = data_directory.join(SUBMITTED_CACHE_FILE_NAME);
info!("Removing '{}'.", path.display());
if let Err(error) = fs::remove_file(&path) {
Expand All @@ -90,7 +90,7 @@ pub fn clean(
}
}
}
if selection.completed || selection.all {
if selection.completed {
let path = data_directory.join(COMPLETED_CACHE_FILE_NAME);
info!("Removing '{}'.", path.display());
if let Err(error) = fs::remove_file(&path) {
Expand All @@ -100,7 +100,7 @@ pub fn clean(
}
}
}
if selection.directory || selection.all {
if selection.directory {
let path = data_directory.join(DIRECTORY_CACHE_FILE_NAME);
info!("Removing '{}'.", path.display());
if let Err(error) = fs::remove_file(&path) {
Expand Down