Introduce fs_err as a replacement for fs

This commit is contained in:
Gabriel Simonetto 2021-10-14 20:10:07 -03:00
parent f46ff3c26e
commit 09b050d836
9 changed files with 42 additions and 14 deletions

7
Cargo.lock generated
View File

@ -117,6 +117,12 @@ dependencies = [
"miniz_oxide",
]
[[package]]
name = "fs-err"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ebd3504ad6116843b8375ad70df74e7bfe83cac77a1f3fe73200c844d43bfe0"
[[package]]
name = "getrandom"
version = "0.2.3"
@ -206,6 +212,7 @@ dependencies = [
"atty",
"bzip2",
"flate2",
"fs-err",
"infer",
"lazy_static",
"libc",

View File

@ -14,6 +14,7 @@ description = "A command-line utility for easily compressing and decompressing f
[dependencies]
atty = "0.2.14"
fs-err = "2.6.0"
lazy_static = "1.4.0"
walkdir = "2.3.2"
strsim = "0.10.0"

View File

@ -1,17 +1,19 @@
//! Contains Tar-specific building and unpacking functions
use std::{
env, fs,
env,
io::prelude::*,
path::{Path, PathBuf},
};
use fs_err as fs;
use tar;
use walkdir::WalkDir;
use crate::{
error::FinalError,
info, oof,
utils::{self, Bytes},
utils::{self, to_utf, Bytes},
};
pub fn unpack_archive(reader: Box<dyn Read>, output_folder: &Path, flags: &oof::Flags) -> crate::Result<Vec<PathBuf>> {
@ -58,7 +60,18 @@ where
builder.append_dir(path, path)?;
} else {
let mut file = fs::File::open(path)?;
builder.append_file(path, &mut file)?;
dbg!(&path);
dbg!(&file);
dbg!(&entry);
dbg!(&previous_location);
dbg!(&filename);
// builder.append_file(path, file.file_mut())?;
builder.append_file(path, file.file_mut()).map_err(|err| {
FinalError::with_title(format!("Could not create archive '{}'", to_utf(path.clone()))) // output_path == writer? da
.detail(format!("Unexpected error while trying to read file '{}'", to_utf(output_path)))
.detail(format!("Error: {}.", err))
})?;
}
}
env::set_current_dir(previous_location)?;

View File

@ -1,11 +1,13 @@
//! Contains Zip-specific building and unpacking functions
use std::{
env, fs,
env,
io::{self, prelude::*},
path::{Path, PathBuf},
};
use fs_err as fs;
use walkdir::WalkDir;
use zip::{self, read::ZipFile, ZipArchive};
@ -121,10 +123,11 @@ fn check_for_comments(file: &ZipFile) {
#[cfg(unix)]
fn __unix_set_permissions(file_path: &Path, file: &ZipFile) -> crate::Result<()> {
use std::fs::Permissions;
use std::os::unix::fs::PermissionsExt;
if let Some(mode) = file.unix_mode() {
fs::set_permissions(file_path, fs::Permissions::from_mode(mode))?;
fs::set_permissions(file_path, Permissions::from_mode(mode))?;
}
Ok(())

View File

@ -9,6 +9,8 @@ use std::{
vec::Vec,
};
use fs_err as fs;
use strsim::normalized_damerau_levenshtein;
use crate::{arg_flag, flag, oof, Error};
@ -73,7 +75,7 @@ fn is_typo(path: impl AsRef<Path>) -> bool {
}
fn canonicalize(path: impl AsRef<Path>) -> crate::Result<PathBuf> {
match std::fs::canonicalize(&path.as_ref()) {
match fs::canonicalize(&path.as_ref()) {
Ok(abs_path) => Ok(abs_path),
Err(io_err) => {
if !path.as_ref().exists() {

View File

@ -3,11 +3,11 @@
//! Also, where correctly call functions based on the detected `Command`.
use std::{
fs,
io::{self, BufReader, BufWriter, Read, Write},
path::{Path, PathBuf},
};
use fs_err as fs;
use utils::colors;
use crate::{

View File

@ -1,15 +1,16 @@
use std::{
cmp, env,
ffi::OsStr,
fs::{self, ReadDir},
path::{Path, PathBuf},
};
use fs_err as fs;
use crate::{dialogs::Confirmation, info, oof};
/// Checks if the given path represents an empty directory.
pub fn dir_is_empty(dir_path: &Path) -> bool {
let is_empty = |mut rd: ReadDir| rd.next().is_none();
let is_empty = |mut rd: std::fs::ReadDir| rd.next().is_none();
dir_path.read_dir().ok().map(is_empty).unwrap_or_default()
}

View File

@ -1,12 +1,14 @@
mod utils;
use std::{
env, fs,
env,
io::prelude::*,
path::{Path, PathBuf},
time::Duration,
};
use fs_err as fs;
use ouch::{cli::Command, commands::run, oof};
use rand::{rngs::SmallRng, RngCore, SeedableRng};
use tempfile::NamedTempFile;

View File

@ -2,10 +2,9 @@
#![allow(dead_code)]
use std::{
fs,
path::{Path, PathBuf},
};
use std::path::{Path, PathBuf};
use fs_err as fs;
use ouch::{cli::Command, commands::run, oof};