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: &Vec<PathBuf>, format: &CompressionFormat) -> OuchResult<()> {
20 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);
21 return Err(Error::InvalidInput);
27 pub (crate) fn create_path_if_non_existent(path: &Path) -> OuchResult<()> {
30 "{}: attempting to create folder {:?}.",
34 std::fs::create_dir_all(path)?;
36 "{}: directory {:#?} created.",
38 fs::canonicalize(&path)?
44 pub (crate) fn get_destination_path(dest: &Option<File>) -> &Path {
47 // Must be None according to the way command-line arg. parsing in Ouch works
48 assert_eq!(output.extension, None);
50 Path::new(&output.path)
52 None => Path::new("."),