mirror of
https://github.com/esp-rs/espup.git
synced 2025-10-02 15:14:56 +00:00
feat: ✨ Check if the provided export-file is a file path
This commit is contained in:
parent
829820f4c8
commit
6aae03d230
@ -84,4 +84,10 @@ pub enum Error {
|
|||||||
emoji::ERROR
|
emoji::ERROR
|
||||||
)]
|
)]
|
||||||
FailedToRemoveFile(String),
|
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),
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ use log::{debug, info, warn};
|
|||||||
use miette::Result;
|
use miette::Result;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
fs::{remove_dir_all, remove_file, File},
|
fs::{metadata, remove_dir_all, remove_file, File},
|
||||||
io::Write,
|
io::Write,
|
||||||
path::PathBuf,
|
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.
|
/// 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> {
|
fn get_export_file(export_file: Option<PathBuf>) -> Result<PathBuf, Error> {
|
||||||
if let Some(export_file) = export_file {
|
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() {
|
if export_file.is_absolute() {
|
||||||
Ok(export_file)
|
Ok(export_file)
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user