feat: Check if the provided export-file is a file path

This commit is contained in:
Sergio Gasquez 2022-12-29 13:00:26 +00:00
parent 829820f4c8
commit 6aae03d230
2 changed files with 11 additions and 1 deletions

View File

@ -84,4 +84,10 @@ pub enum Error {
emoji::ERROR
)]
FailedToRemoveFile(String),
#[diagnostic(code(espup::wrong_export_file))]
#[error(
"{} Wrong export file destination: '{0}'. Please, use an absolte or releative path (including the file and its extension).",
emoji::ERROR
)]
WrongExportFile(String),
}

View File

@ -20,7 +20,7 @@ use log::{debug, info, warn};
use miette::Result;
use std::{
collections::HashSet,
fs::{remove_dir_all, remove_file, File},
fs::{metadata, remove_dir_all, remove_file, File},
io::Write,
path::PathBuf,
};
@ -428,6 +428,10 @@ fn clear_dist_folder() -> Result<(), Error> {
/// Returns the absolute path to the export file, uses the DEFAULT_EXPORT_FILE if no arg is provided.
fn get_export_file(export_file: Option<PathBuf>) -> Result<PathBuf, Error> {
if let Some(export_file) = export_file {
let metadata = export_file.metadata()?;
if !metadata.is_file() {
return Err(Error::WrongExportFile(export_file.display().to_string()));
}
if export_file.is_absolute() {
Ok(export_file)
} else {