Skip to content

Commit

Permalink
Merge pull request #54 from MrHedmad/warn_absolute_fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHedmad authored Jan 30, 2024
2 parents d17acf5 + 0bdff8f commit 205bc27
Showing 1 changed file with 26 additions and 1 deletion.
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

0 comments on commit 205bc27

Please sign in to comment.