improve code structure

This commit is contained in:
valoq 2025-07-12 18:20:15 +02:00
parent 133f46a2c8
commit a4ff65f44c
No known key found for this signature in database
GPG Key ID: 19F09A0FB865CBD8
6 changed files with 9 additions and 20 deletions

View File

@ -5,7 +5,7 @@ use std::{
}; };
use fs_err as fs; use fs_err as fs;
use crate::utils::landlock; //use crate::utils::landlock;
#[cfg(not(feature = "bzip3"))] #[cfg(not(feature = "bzip3"))]
use crate::archive; use crate::archive;
@ -19,7 +19,7 @@ use crate::{
utils::{ utils::{
self, self,
io::lock_and_flush_output_stdio, io::lock_and_flush_output_stdio,
is_path_stdin, is_path_stdin, landlock,
logger::{info, info_accessible}, logger::{info, info_accessible},
nice_directory_display, user_wants_to_continue, nice_directory_display, user_wants_to_continue,
}, },
@ -324,14 +324,11 @@ fn execute_decompression(
is_smart_unpack: bool, is_smart_unpack: bool,
disable_sandbox: bool, disable_sandbox: bool,
) -> crate::Result<ControlFlow<(), usize>> { ) -> crate::Result<ControlFlow<(), usize>> {
// init landlock sandbox to restrict file system write access to output_dir // init landlock sandbox to restrict file system write access to output_dir
// The output directory iseither specified with the -d option or the current working directory is used // The output directory iseither specified with the -d option or the current working directory is used
// TODO: restrict acess to the current working directory to allow only creating new files // TODO: restrict acess to the current working directory to allow only creating new files
// TODO: move to unpack and smart_unpack to cover the differetn dirctories used for // TODO: move to unpack and smart_unpack to cover the differetn dirctories used for
// decompression // decompression
//if !input_is_stdin && options.remove { //if !input_is_stdin && options.remove {
//permit write access to input_file_path //permit write access to input_file_path
//} else { //} else {
@ -339,7 +336,6 @@ fn execute_decompression(
landlock::init_sandbox(&[output_dir], disable_sandbox); landlock::init_sandbox(&[output_dir], disable_sandbox);
if is_smart_unpack { if is_smart_unpack {
return smart_unpack(unpack_fn, output_dir, output_file_path, question_policy); return smart_unpack(unpack_fn, output_dir, output_file_path, question_policy);
} }

View File

@ -4,14 +4,14 @@ use std::{
}; };
use fs_err as fs; use fs_err as fs;
use crate::utils::landlock; //use crate::utils::landlock;
use crate::{ use crate::{
archive, archive,
commands::warn_user_about_loading_zip_in_memory, commands::warn_user_about_loading_zip_in_memory,
extension::CompressionFormat::{self, *}, extension::CompressionFormat::{self, *},
list::{self, FileInArchive, ListOptions}, list::{self, FileInArchive, ListOptions},
utils::{io::lock_and_flush_output_stdio, user_wants_to_continue}, utils::{io::lock_and_flush_output_stdio, user_wants_to_continue, landlock},
QuestionAction, QuestionPolicy, BUFFER_CAPACITY, QuestionAction, QuestionPolicy, BUFFER_CAPACITY,
}; };
@ -25,7 +25,6 @@ pub fn list_archive_contents(
password: Option<&[u8]>, password: Option<&[u8]>,
disable_sandbox: bool, disable_sandbox: bool,
) -> crate::Result<()> { ) -> crate::Result<()> {
//rar uses a temporary file which needs to be defined early to be permitted in landlock //rar uses a temporary file which needs to be defined early to be permitted in landlock
let mut temp_file = tempfile::NamedTempFile::new()?; let mut temp_file = tempfile::NamedTempFile::new()?;

View File

@ -261,9 +261,7 @@ pub fn run(
.map(|str| <[u8] as ByteSlice>::from_os_str(str).expect("convert password to bytes failed")), .map(|str| <[u8] as ByteSlice>::from_os_str(str).expect("convert password to bytes failed")),
args.disable_sandbox, args.disable_sandbox,
)?; )?;
} }
Ok(()) Ok(())
} }
} }

View File

@ -21,9 +21,6 @@ use self::{
}, },
}; };
//use utils::landlock::*;
// Used in BufReader and BufWriter to perform less syscalls // Used in BufReader and BufWriter to perform less syscalls
const BUFFER_CAPACITY: usize = 1024 * 32; const BUFFER_CAPACITY: usize = 1024 * 32;
@ -64,7 +61,6 @@ fn run() -> Result<()> {
// Since either the specified output directory is created if it did not exist, or the .ouch-tmp // Since either the specified output directory is created if it did not exist, or the .ouch-tmp
// directory is created in the current working directory, the parent directory of the target // directory is created in the current working directory, the parent directory of the target
// directory requires LANDLOCK_ACCESS_FS_MAKE_DIR // directory requires LANDLOCK_ACCESS_FS_MAKE_DIR
// expects either the .tmp-ouch-XXXXXX path or the specified output directory (-d option) // expects either the .tmp-ouch-XXXXXX path or the specified output directory (-d option)
//utils::landlock::init_sandbox(&working_dir); //utils::landlock::init_sandbox(&working_dir);

View File

@ -1,14 +1,14 @@
// Landlock support and generic Landlock sandbox implementation. // Landlock support and generic Landlock sandbox implementation.
// https://landlock.io/rust-landlock/landlock/struct.Ruleset.html // https://landlock.io/rust-landlock/landlock/struct.Ruleset.html
use std::path::Path;
use landlock::{ use landlock::{
Access, AccessFs, PathBeneath, PathFd, PathFdError, RestrictionStatus, Ruleset, Access, AccessFs, PathBeneath, PathFd, PathFdError, RestrictionStatus, Ruleset,
RulesetAttr, RulesetCreatedAttr, RulesetError, ABI, RulesetAttr, RulesetCreatedAttr, RulesetError, ABI,
}; };
use thiserror::Error; use thiserror::Error;
use std::path::Path;
/// The status code returned from `ouch` on error /// The status code returned from `ouch` on error
pub const EXIT_FAILURE: i32 = libc::EXIT_FAILURE; pub const EXIT_FAILURE: i32 = libc::EXIT_FAILURE;

View File

@ -8,9 +8,9 @@ mod file_visibility;
mod formatting; mod formatting;
mod fs; mod fs;
pub mod io; pub mod io;
pub mod landlock;
pub mod logger; pub mod logger;
mod question; mod question;
pub mod landlock;
pub use self::{ pub use self::{
file_visibility::FileVisibilityPolicy, file_visibility::FileVisibilityPolicy,