mirror of
https://github.com/AleoHQ/leo.git
synced 2025-01-03 15:28:05 +03:00
add import directory file and errors
This commit is contained in:
parent
878310f793
commit
a9338a9756
33
leo/directories/imports.rs
Normal file
33
leo/directories/imports.rs
Normal file
@ -0,0 +1,33 @@
|
||||
use crate::errors::ImportsDirectoryError;
|
||||
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
pub(crate) static IMPORTS_DIRECTORY_NAME: &str = "imports/";
|
||||
|
||||
pub struct ImportsDirectory;
|
||||
|
||||
impl ImportsDirectory {
|
||||
/// Creates a directory at the provided path with the default directory name.
|
||||
pub fn create(path: &PathBuf) -> Result<(), ImportsDirectoryError> {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() && !path.ends_with(IMPORTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(IMPORTS_DIRECTORY_NAME));
|
||||
}
|
||||
|
||||
fs::create_dir_all(&path).map_err(ImportsDirectoryError::Creating)
|
||||
}
|
||||
|
||||
/// Removes the directory at the provided path.
|
||||
pub fn remove(path: &PathBuf) -> Result<(), ImportsDirectoryError> {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() && !path.ends_with(IMPORTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(IMPORTS_DIRECTORY_NAME));
|
||||
}
|
||||
|
||||
if path.exists() {
|
||||
fs::remove_dir_all(&path).map_err(ImportsDirectoryError::Removing)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
@ -1,3 +1,6 @@
|
||||
pub mod imports;
|
||||
pub use self::imports::*;
|
||||
|
||||
pub mod inputs;
|
||||
pub use self::inputs::*;
|
||||
|
||||
|
28
leo/errors/directory/imports.rs
Normal file
28
leo/errors/directory/imports.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use std::{ffi::OsString, fs::FileType, io};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ImportsDirectoryError {
|
||||
#[error("creating: {}", _0)]
|
||||
Creating(io::Error),
|
||||
|
||||
#[error("file entry getting: {}", _0)]
|
||||
GettingFileEntry(io::Error),
|
||||
|
||||
#[error("file {:?} extension getting", _0)]
|
||||
GettingFileExtension(OsString),
|
||||
|
||||
#[error("file {:?} type getting: {}", _0, _1)]
|
||||
GettingFileType(OsString, io::Error),
|
||||
|
||||
#[error("invalid file {:?} extension: {:?}", _0, _1)]
|
||||
InvalidFileExtension(OsString, OsString),
|
||||
|
||||
#[error("invalid file {:?} type: {:?}", _0, _1)]
|
||||
InvalidFileType(OsString, FileType),
|
||||
|
||||
#[error("reading: {}", _0)]
|
||||
Reading(io::Error),
|
||||
|
||||
#[error("removing: {}", _0)]
|
||||
Removing(io::Error),
|
||||
}
|
@ -1,3 +1,6 @@
|
||||
pub mod imports;
|
||||
pub use self::imports::*;
|
||||
|
||||
pub mod inputs;
|
||||
pub use self::inputs::*;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! The program package zip file.
|
||||
|
||||
use crate::{
|
||||
directories::{INPUTS_DIRECTORY_NAME, OUTPUTS_DIRECTORY_NAME},
|
||||
directories::{IMPORTS_DIRECTORY_NAME, INPUTS_DIRECTORY_NAME, OUTPUTS_DIRECTORY_NAME},
|
||||
errors::ZipFileError,
|
||||
files::{
|
||||
CHECKSUM_FILE_EXTENSION,
|
||||
@ -109,9 +109,11 @@ impl ZipFile {
|
||||
}
|
||||
|
||||
fn is_excluded(path: &Path) -> bool {
|
||||
// excluded directories: `/inputs`, `/outputs`
|
||||
// excluded directories: `inputs`, `outputs`, `imports`
|
||||
if path.ends_with(INPUTS_DIRECTORY_NAME.trim_end_matches("/"))
|
||||
| path.ends_with(OUTPUTS_DIRECTORY_NAME.trim_end_matches("/"))
|
||||
| path.ends_with(IMPORTS_DIRECTORY_NAME.trim_end_matches("/"))
|
||||
| path
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user