1 use std::{fs, path::{Path, PathBuf}};
4 use crate::{error::{Error, OuchResult}, extension::CompressionFormat, file::File};
6 pub (crate) fn ensure_exists<'a, P>(path: P) -> OuchResult<()>
9 let exists = path.as_ref().exists();
11 eprintln!("{}: could not find file {:?}", "[ERROR]".red(), path.as_ref());
12 return Err(Error::FileNotFound(PathBuf::from(path.as_ref())));
17 pub (crate) fn check_for_multiple_files(files: &[PathBuf], format: &CompressionFormat) -> OuchResult<()> {
19 eprintln!("{}: cannot compress multiple files directly to {:#?}.\n Try using an intermediate archival method such as Tar.\n Example: filename.tar{}", "[ERROR]".red(), format, format);
20 return Err(Error::InvalidInput);
26 pub (crate) fn create_path_if_non_existent(path: &Path) -> OuchResult<()> {
29 "{}: attempting to create folder {:?}.",
33 std::fs::create_dir_all(path)?;
35 "{}: directory {:#?} created.",
37 fs::canonicalize(&path)?
43 pub (crate) fn get_destination_path(dest: &Option<File>) -> &Path {
46 // Must be None according to the way command-line arg. parsing in Ouch works
47 assert_eq!(output.extension, None);
49 Path::new(&output.path)
51 None => Path::new("."),