From 6aae03d230a4e8a004c3fc4decf1a9f1d2afe8b4 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Thu, 29 Dec 2022 13:00:26 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20Check=20if=20the=20provided?= =?UTF-8?q?=20export-file=20is=20a=20file=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/error.rs | 6 ++++++ src/main.rs | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 9b75c87..3d4bf92 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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), } diff --git a/src/main.rs b/src/main.rs index 099733d..a3efe71 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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) -> Result { 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 {