mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 19:45:29 +00:00
Use fs-err
This commit is contained in:
parent
7b04e2bf71
commit
e6fc79dd10
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -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",
|
||||
|
@ -13,6 +13,7 @@ description = "A command-line utility for easily compressing and decompressing f
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
fs-err = "2.6.0"
|
||||
atty = "0.2.14"
|
||||
lazy_static = "1.4.0"
|
||||
walkdir = "2.3.2"
|
||||
|
@ -1,7 +1,8 @@
|
||||
//! Contains Tar-specific building and unpacking functions
|
||||
|
||||
use std::{
|
||||
env, fs,
|
||||
env,
|
||||
fs::File,
|
||||
io::prelude::*,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
@ -57,7 +58,7 @@ where
|
||||
if path.is_dir() {
|
||||
builder.append_dir(path, path)?;
|
||||
} else {
|
||||
let mut file = fs::File::open(path)?;
|
||||
let mut file = File::open(path)?;
|
||||
builder.append_file(path, &mut file)?;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
//! Contains Zip-specific building and unpacking functions
|
||||
|
||||
use std::{
|
||||
env, fs,
|
||||
env,
|
||||
fs::Permissions,
|
||||
io::{self, prelude::*},
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use fs_err as fs;
|
||||
|
||||
use walkdir::WalkDir;
|
||||
use zip::{self, read::ZipFile, ZipArchive};
|
||||
|
||||
@ -124,7 +127,7 @@ fn __unix_set_permissions(file_path: &Path, file: &ZipFile) -> crate::Result<()>
|
||||
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(())
|
||||
|
@ -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() {
|
||||
|
@ -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::{
|
||||
@ -29,7 +29,7 @@ const BUFFER_CAPACITY: usize = 1024 * 64;
|
||||
|
||||
fn represents_several_files(files: &[PathBuf]) -> bool {
|
||||
let is_non_empty_dir = |path: &PathBuf| {
|
||||
let is_non_empty = || !dir_is_empty(&path);
|
||||
let is_non_empty = || !dir_is_empty(path);
|
||||
|
||||
path.is_dir().then(is_non_empty).unwrap_or_default()
|
||||
};
|
||||
|
@ -1,10 +1,12 @@
|
||||
use std::{
|
||||
cmp, env,
|
||||
ffi::OsStr,
|
||||
fs::{self, ReadDir},
|
||||
fs::ReadDir,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use fs_err as fs;
|
||||
|
||||
use crate::{dialogs::Confirmation, info, oof};
|
||||
|
||||
/// Checks if the given path represents an empty directory.
|
||||
|
@ -2,15 +2,15 @@
|
||||
|
||||
#![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};
|
||||
use rand::{distributions::Alphanumeric, prelude::SmallRng, Rng, SeedableRng};
|
||||
|
||||
pub fn create_empty_dir(at: &Path, filename: &str) -> PathBuf {
|
||||
let dirname = Path::new(filename);
|
||||
|
||||
let full_path = at.join(dirname);
|
||||
|
||||
fs::create_dir(&full_path).expect("Failed to create an empty directory");
|
||||
@ -19,7 +19,11 @@ pub fn create_empty_dir(at: &Path, filename: &str) -> PathBuf {
|
||||
}
|
||||
|
||||
pub fn compress_files(at: &Path, paths_to_compress: &[PathBuf], format: &str) -> PathBuf {
|
||||
let archive_path = String::from("archive.") + format;
|
||||
let rng = SmallRng::from_entropy();
|
||||
|
||||
let s: String = rng.sample_iter(&Alphanumeric).take(7).map(char::from).collect();
|
||||
|
||||
let archive_path = format!("archive{}{}", s, format);
|
||||
let archive_path = at.join(archive_path);
|
||||
|
||||
let command = Command::Compress { files: paths_to_compress.to_vec(), output_path: archive_path.to_path_buf() };
|
||||
|
Loading…
x
Reference in New Issue
Block a user