mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 12:05:46 +00:00
Ensure correct permissions for decompressed files from .zip on Unix
This commit is contained in:
parent
96a4e8bb78
commit
19f12ff791
@ -127,7 +127,7 @@ impl TryFrom<clap::ArgMatches<'static>> for Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
eprintln!("{} {}", "[ERROR]".red(), err);
|
eprintln!("{} {}", "[ERROR]".red(), err);
|
||||||
return Err(crate::Error::IOError);
|
return Err(crate::Error::IoError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,15 @@ use zip::{self, read::ZipFile, ZipArchive};
|
|||||||
use super::decompressor::{DecompressionResult, Decompressor};
|
use super::decompressor::{DecompressionResult, Decompressor};
|
||||||
use crate::{file::File, utils};
|
use crate::{file::File, utils};
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
fn __unix_set_permissions(file_path: &PathBuf, file: &ZipFile) {
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
|
||||||
|
if let Some(mode) = file.unix_mode() {
|
||||||
|
fs::set_permissions(&file_path, fs::Permissions::from_mode(mode)).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ZipDecompressor {}
|
pub struct ZipDecompressor {}
|
||||||
|
|
||||||
impl ZipDecompressor {
|
impl ZipDecompressor {
|
||||||
@ -65,7 +74,8 @@ impl ZipDecompressor {
|
|||||||
io::copy(&mut file, &mut outfile)?;
|
io::copy(&mut file, &mut outfile)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: check if permissions are correct when on Unix
|
#[cfg(unix)]
|
||||||
|
__unix_set_permissions(&file_path, &file);
|
||||||
|
|
||||||
let file_path = fs::canonicalize(file_path.clone())?;
|
let file_path = fs::canonicalize(file_path.clone())?;
|
||||||
unpacked_files.push(file_path);
|
unpacked_files.push(file_path);
|
||||||
@ -89,6 +99,7 @@ impl ZipDecompressor {
|
|||||||
None => {
|
None => {
|
||||||
let file = fs::File::open(&from.path)?;
|
let file = fs::File::open(&from.path)?;
|
||||||
let mut archive = zip::ZipArchive::new(file)?;
|
let mut archive = zip::ZipArchive::new(file)?;
|
||||||
|
|
||||||
Ok(Self::zip_decompress(&mut archive, into)?)
|
Ok(Self::zip_decompress(&mut archive, into)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ pub enum Error {
|
|||||||
// TODO: get rid of this error variant
|
// TODO: get rid of this error variant
|
||||||
InvalidUnicode,
|
InvalidUnicode,
|
||||||
InvalidInput,
|
InvalidInput,
|
||||||
IOError,
|
IoError,
|
||||||
FileNotFound(PathBuf),
|
FileNotFound(PathBuf),
|
||||||
AlreadyExists,
|
AlreadyExists,
|
||||||
InvalidZipArchive(&'static str),
|
InvalidZipArchive(&'static str),
|
||||||
@ -50,7 +50,7 @@ impl From<std::io::Error> for Error {
|
|||||||
std::io::ErrorKind::AlreadyExists => Self::AlreadyExists,
|
std::io::ErrorKind::AlreadyExists => Self::AlreadyExists,
|
||||||
_other => {
|
_other => {
|
||||||
println!("{}: {}", "IO error".red(), err);
|
println!("{}: {}", "IO error".red(), err);
|
||||||
Self::IOError
|
Self::IoError
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user