Merge branch 'master' into completions-manpage

This commit is contained in:
figsoda 2021-10-30 16:59:24 -04:00 committed by GitHub
commit 614f2aa6d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 73 additions and 17 deletions

View File

@ -292,3 +292,26 @@ jobs:
# with: # with:
# name: 'ouch-x86_64-pc-windows-gnu' # name: 'ouch-x86_64-pc-windows-gnu'
# path: target\x86_64-pc-windows-gnu\release\ouch.exe # path: target\x86_64-pc-windows-gnu\release\ouch.exe
fmt:
name: Check sourcecode format
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
target: x86_64-unknown-linux-musl
components: rustfmt
override: true
- name: Check format with cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

7
Cargo.lock generated
View File

@ -157,6 +157,12 @@ dependencies = [
"miniz_oxide", "miniz_oxide",
] ]
[[package]]
name = "fs-err"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ebd3504ad6116843b8375ad70df74e7bfe83cac77a1f3fe73200c844d43bfe0"
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.3" version = "0.2.3"
@ -294,6 +300,7 @@ dependencies = [
"clap", "clap",
"clap_generate", "clap_generate",
"flate2", "flate2",
"fs-err",
"infer", "infer",
"libc", "libc",
"once_cell", "once_cell",

View File

@ -15,6 +15,7 @@ description = "A command-line utility for easily compressing and decompressing f
[dependencies] [dependencies]
clap = "=3.0.0-beta.5" # Keep it pinned while in beta! clap = "=3.0.0-beta.5" # Keep it pinned while in beta!
atty = "0.2.14" atty = "0.2.14"
fs-err = "2.6.0"
once_cell = "1.8.0" once_cell = "1.8.0"
walkdir = "2.3.2" walkdir = "2.3.2"
bzip2 = "0.4.3" bzip2 = "0.4.3"

View File

@ -1,15 +1,17 @@
//! Contains Tar-specific building and unpacking functions //! Contains Tar-specific building and unpacking functions
use std::{ use std::{
env, fs, env,
io::prelude::*, io::prelude::*,
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
use fs_err as fs;
use tar; use tar;
use walkdir::WalkDir; use walkdir::WalkDir;
use crate::{ use crate::{
error::FinalError,
info, info,
utils::{self, Bytes}, utils::{self, Bytes},
QuestionPolicy, QuestionPolicy,
@ -63,7 +65,12 @@ where
builder.append_dir(path, path)?; builder.append_dir(path, path)?;
} else { } else {
let mut file = fs::File::open(path)?; let mut file = fs::File::open(path)?;
builder.append_file(path, &mut file)?; builder.append_file(path, file.file_mut()).map_err(|err| {
FinalError::with_title("Could not create archive")
.detail("Unexpected error while trying to read file")
.detail(format!("Error: {}.", err))
.into_owned()
})?;
} }
} }
env::set_current_dir(previous_location)?; env::set_current_dir(previous_location)?;

View File

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

View File

@ -6,6 +6,7 @@ use std::{
}; };
use clap::Parser; use clap::Parser;
use fs_err as fs;
use crate::{Error, Opts, QuestionPolicy, Subcommand}; use crate::{Error, Opts, QuestionPolicy, Subcommand};
@ -31,7 +32,7 @@ impl Opts {
} }
fn canonicalize(path: impl AsRef<Path>) -> crate::Result<PathBuf> { 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), Ok(abs_path) => Ok(abs_path),
Err(io_err) => { Err(io_err) => {
if !path.as_ref().exists() { if !path.as_ref().exists() {

View File

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

View File

@ -21,7 +21,7 @@ pub enum Error {
FileNotFound(PathBuf), FileNotFound(PathBuf),
AlreadyExists, AlreadyExists,
InvalidZipArchive(&'static str), InvalidZipArchive(&'static str),
PermissionDenied, PermissionDenied { error_title: String },
UnsupportedZipArchive(&'static str), UnsupportedZipArchive(&'static str),
InternalError, InternalError,
CompressingRootFolder, CompressingRootFolder,
@ -78,6 +78,10 @@ impl FinalError {
self.hints.push(hint.to_string()); self.hints.push(hint.to_string());
self self
} }
pub fn into_owned(&mut self) -> Self {
std::mem::take(self)
}
} }
impl fmt::Display for Error { impl fmt::Display for Error {
@ -134,7 +138,9 @@ impl fmt::Display for Error {
Error::UnknownExtensionError(_) => todo!(), Error::UnknownExtensionError(_) => todo!(),
Error::AlreadyExists => todo!(), Error::AlreadyExists => todo!(),
Error::InvalidZipArchive(_) => todo!(), Error::InvalidZipArchive(_) => todo!(),
Error::PermissionDenied => todo!(), Error::PermissionDenied { error_title } => {
FinalError::with_title(error_title).detail("Permission denied").to_owned()
}
Error::UnsupportedZipArchive(_) => todo!(), Error::UnsupportedZipArchive(_) => todo!(),
Error::Custom { reason } => reason.clone(), Error::Custom { reason } => reason.clone(),
}; };
@ -152,8 +158,8 @@ impl Error {
impl From<std::io::Error> for Error { impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Self { fn from(err: std::io::Error) -> Self {
match err.kind() { match err.kind() {
std::io::ErrorKind::NotFound => panic!("{}", err), std::io::ErrorKind::NotFound => todo!(),
std::io::ErrorKind::PermissionDenied => Self::PermissionDenied, std::io::ErrorKind::PermissionDenied => Self::PermissionDenied { error_title: err.to_string() },
std::io::ErrorKind::AlreadyExists => Self::AlreadyExists, std::io::ErrorKind::AlreadyExists => Self::AlreadyExists,
_other => Self::IoError { reason: err.to_string() }, _other => Self::IoError { reason: err.to_string() },
} }
@ -177,3 +183,9 @@ impl From<walkdir::Error> for Error {
Self::WalkdirError { reason: err.to_string() } Self::WalkdirError { reason: err.to_string() }
} }
} }
impl From<FinalError> for Error {
fn from(err: FinalError) -> Self {
Self::Custom { reason: err }
}
}

View File

@ -1,16 +1,17 @@
use std::{ use std::{
cmp, env, cmp, env,
ffi::OsStr, ffi::OsStr,
fs::{self, ReadDir},
path::Component, path::Component,
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
use fs_err as fs;
use crate::{dialogs::Confirmation, info}; use crate::{dialogs::Confirmation, info};
/// Checks if the given path represents an empty directory. /// Checks if the given path represents an empty directory.
pub fn dir_is_empty(dir_path: &Path) -> bool { 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().map(is_empty).unwrap_or_default() dir_path.read_dir().map(is_empty).unwrap_or_default()
} }

View File

@ -1,13 +1,15 @@
mod utils; mod utils;
use std::{ use std::{
env, fs, env,
io::prelude::*, io::prelude::*,
path::{Path, PathBuf}, path::{Path, PathBuf},
time::Duration, time::Duration,
}; };
use ouch::{commands::run, Opts, QuestionPolicy, Subcommand}; use ouch::{commands::run, Opts, QuestionPolicy, Subcommand};
use fs_err as fs;
use rand::{rngs::SmallRng, RngCore, SeedableRng}; use rand::{rngs::SmallRng, RngCore, SeedableRng};
use tempfile::NamedTempFile; use tempfile::NamedTempFile;
use utils::*; use utils::*;

View File

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