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

Warn the user if they fetch to a file not in the input data dir #54

Merged
merged 1 commit into from
Jan 30, 2024
Merged
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
27 changes: 26 additions & 1 deletion src/commands/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::os::unix::fs::MetadataExt;
use std::path::{Path, PathBuf};

use crate::new::normalize_path;
use crate::options::KerblamTomlOptions;
use crate::options::{KerblamTomlOptions, RemoteFile};
use crate::utils::{ask_for, run_command, YesNo};

use anyhow::{anyhow, bail, Result};
Expand Down Expand Up @@ -209,6 +209,31 @@ pub fn fetch_remote_data(config: KerblamTomlOptions) -> Result<()> {
return Ok(());
}

// Check if any remote files will be saved somewhere else than the
// input data dir. If so, warn the user before continuing.
let data_dir = config.input_data_dir();
let non_canonical_files: Vec<&RemoteFile> = remote_files
.iter()
.filter(|x| !x.path.starts_with(&data_dir))
.collect();
if !non_canonical_files.is_empty() {
let msg = non_canonical_files
.into_iter()
.map(|x| x.path.clone().into_os_string().into_string().unwrap())
.map(|x| format!("\t- {}", x))
.reduce(|x, y| format!("{}\n{}", x, y))
.unwrap();
eprintln!(
"⚠️ Some target paths are not inside the input data directory:\n{}",
msg
);

let approve = ask_for::<YesNo>("Continue?");
if matches!(approve, YesNo::No) {
return Ok(());
}
}

let mut success = true;

let client = Client::new();
Expand Down
Loading