Skip to content

Commit

Permalink
fix: reject empty cache dir path (#7630)
Browse files Browse the repository at this point in the history
### Description

As mentioned in #6294 we don't want to allow for an empty cache dir to
be set.

This PR now errors if the user passes an empty string as an argument for
`--cache-dir`

### Testing Instructions

Added unit test. Quick manual test:
```
[0 olszewski@chriss-mbp] /Users/olszewski/code/vercel/turborepo $ turbo_dev build --cache-dir=
 ERROR  invalid value '' for '--cache-dir <CACHE_DIR>': path must not be empty

For more information, try '--help'.
```

Closes TURBO-2534
  • Loading branch information
chris-olszewski committed Mar 6, 2024
1 parent de5ebd7 commit 6b35bbe
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion crates/turborepo-lib/src/cli/mod.rs
Expand Up @@ -605,14 +605,22 @@ fn validate_graph_extension(s: &str) -> Result<String, String> {
}
}

fn path_non_empty(s: &str) -> Result<Utf8PathBuf, String> {
if s.is_empty() {
Err("path must not be empty".to_string())
} else {
Ok(Utf8Path::new(s).to_path_buf())
}
}

#[derive(Parser, Clone, Debug, Default, Serialize, PartialEq)]
#[command(groups = [
ArgGroup::new("daemon-group").multiple(false).required(false),
ArgGroup::new("scope-filter-group").multiple(true).required(false),
])]
pub struct RunArgs {
/// Override the filesystem cache directory.
#[clap(long)]
#[clap(long, value_parser = path_non_empty)]
pub cache_dir: Option<Utf8PathBuf>,
/// Set the number of concurrent cache operations (default 10)
#[clap(long, default_value_t = DEFAULT_NUM_WORKERS)]
Expand Down Expand Up @@ -2344,4 +2352,11 @@ mod test {
])
.is_err());
}

#[test]
fn test_empty_cache_dir() {
assert!(Args::try_parse_from(["turbo", "build", "--cache-dir"]).is_err());
assert!(Args::try_parse_from(["turbo", "build", "--cache-dir="]).is_err());
assert!(Args::try_parse_from(["turbo", "build", "--cache-dir", ""]).is_err());
}
}

0 comments on commit 6b35bbe

Please sign in to comment.