Skip to content

Commit

Permalink
fix: reject empty cache dir path
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-olszewski committed Mar 5, 2024
1 parent 91742e1 commit b98e4e1
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion crates/turborepo-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
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 b98e4e1

Please sign in to comment.