Skip to content

Commit

Permalink
Merge pull request #34 from glotzerlab/clean-all-by-default
Browse files Browse the repository at this point in the history
Clean all by default
  • Loading branch information
joaander authored Aug 15, 2024
2 parents dbf8d51 + 4cf081a commit 8b89dc4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
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

0 comments on commit 8b89dc4

Please sign in to comment.