Compare commits
10 Commits
f9900daeef
...
cb1e1841b4
Author | SHA1 | Date |
---|---|---|
rascul | cb1e1841b4 | 2 years ago |
rasul | c25cf62b42 | 4 years ago |
rasul | 907da2f20a | 4 years ago |
rasul | c2280b350e | 4 years ago |
rasul | 1f29883c84 | 4 years ago |
rascul | 0082d97b57 | 5 years ago |
rascul | 5abbf991d9 | 5 years ago |
rascul | bc4315762c | 5 years ago |
rascul | 18f900005b | 5 years ago |
rascul | 23a5c25726 | 5 years ago |
@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
find src -type f -name '*.rs' -exec rustfmt {} +
|
@ -1,49 +0,0 @@
|
||||
use std::fmt::{Display, Formatter, Result as FmtResult};
|
||||
use std::io::Error as IoError;
|
||||
|
||||
use regex::Error as RegexError;
|
||||
|
||||
pub type MkrootResult<T> = Result<T, MkrootError>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum MkrootError {
|
||||
Io(IoError),
|
||||
Regex(RegexError),
|
||||
Custom(String),
|
||||
Empty,
|
||||
}
|
||||
|
||||
impl From<IoError> for MkrootError {
|
||||
fn from(e: IoError) -> MkrootError {
|
||||
MkrootError::Io(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RegexError> for MkrootError {
|
||||
fn from(e: RegexError) -> MkrootError {
|
||||
MkrootError::Regex(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for MkrootError {
|
||||
fn from(e: String) -> MkrootError {
|
||||
MkrootError::Custom(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<()> for MkrootError {
|
||||
fn from(_: ()) -> MkrootError {
|
||||
MkrootError::Empty
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for MkrootError {
|
||||
fn fmt(&self, f: &mut Formatter) -> FmtResult {
|
||||
match *self {
|
||||
MkrootError::Io(ref e) => Display::fmt(e, f),
|
||||
MkrootError::Regex(ref e) => Display::fmt(e, f),
|
||||
MkrootError::Custom(ref e) => Display::fmt(e, f),
|
||||
MkrootError::Empty => Display::fmt("Empty", f),
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
mod mkroot_files;
|
||||
|
||||
pub use mkroot_files::*;
|
@ -0,0 +1,6 @@
|
||||
#[macro_export]
|
||||
macro_rules! serr {
|
||||
($($arg:tt)*) => {
|
||||
Err(Box::from([$($arg)*].concat()))
|
||||
};
|
||||
}
|
@ -0,0 +1 @@
|
||||
pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
@ -0,0 +1,58 @@
|
||||
use std::fs::{copy, create_dir, metadata, set_permissions, Permissions};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::result::Result;
|
||||
use crate::serr;
|
||||
|
||||
pub fn get_perms(path: &PathBuf) -> Result<Permissions> {
|
||||
match metadata(path) {
|
||||
Ok(meta) => Ok(meta.permissions()),
|
||||
Err(e) => serr!(
|
||||
"Error retrieving metadata ",
|
||||
&path.display().to_string(),
|
||||
": ",
|
||||
&e.to_string()
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_perms(path: &PathBuf, perms: Permissions) -> Result<()> {
|
||||
if let Err(e) = set_permissions(path, perms) {
|
||||
return serr!(
|
||||
"Error setting permissions ",
|
||||
&path.display().to_string(),
|
||||
": ",
|
||||
&e.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn mkdir(dir: &PathBuf) -> Result<()> {
|
||||
if let Err(e) = create_dir(&dir) {
|
||||
return serr!(
|
||||
"Error creating directory ",
|
||||
&dir.display().to_string(),
|
||||
": ",
|
||||
&e.to_string()
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn copy_file(src: &PathBuf, dst: &PathBuf) -> Result<()> {
|
||||
if let Err(e) = copy(&src, &dst) {
|
||||
return serr!(
|
||||
"Error copying file from ",
|
||||
&src.display().to_string(),
|
||||
" to ",
|
||||
&dst.display().to_string(),
|
||||
": ",
|
||||
&e.to_string()
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
use std::fs::copy;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::error::*;
|
||||
|
||||
pub fn copy_file(src: &PathBuf, dst: &PathBuf) -> MkrootResult<()> {
|
||||
if let Err(e) = copy(&src, &dst) {
|
||||
return Err(MkrootError::from(format!(
|
||||
"Error copying file from {} to {}: {}",
|
||||
&src.display(),
|
||||
&dst.display(),
|
||||
e
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
use std::fs::create_dir;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::error::*;
|
||||
|
||||
pub fn mkdir(dir: &PathBuf) -> MkrootResult<()> {
|
||||
if let Err(e) = create_dir(&dir) {
|
||||
return Err(MkrootError::from(format!(
|
||||
"Error creating directory {}: {}",
|
||||
&dir.display(),
|
||||
e
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
mod copy_file;
|
||||
mod mkdir;
|
||||
mod perms;
|
||||
|
||||
pub use crate::util::copy_file::copy_file;
|
||||
pub use crate::util::mkdir::mkdir;
|
||||
pub use crate::util::perms::*;
|
@ -1,27 +0,0 @@
|
||||
use std::fs::{metadata, set_permissions, Permissions};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::error::*;
|
||||
|
||||
pub fn get_perms(path: &PathBuf) -> MkrootResult<Permissions> {
|
||||
match metadata(path) {
|
||||
Ok(meta) => Ok(meta.permissions()),
|
||||
Err(e) => Err(MkrootError::from(format!(
|
||||
"Error retrieving metadata {}: {}",
|
||||
path.display(),
|
||||
e
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_perms(path: &PathBuf, perms: Permissions) -> MkrootResult<()> {
|
||||
if let Err(e) = set_permissions(path, perms) {
|
||||
return Err(MkrootError::from(format!(
|
||||
"Error setting permissions {}: {}",
|
||||
path.display(),
|
||||
e
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in new issue