Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,185 changes: 704 additions & 481 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion arx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ daemonize = "0.5.0"
rand = { version = "0.8.5", features = ["small_rng"]}
lipsum = "0.9.0"
tempfile = "3.8.0"
format-bytes = "0.3.0"
filetime = "0.2.25"
rustest = "0.3.1"
walkdir = "2.4.0"
relative-path = "2.0.1"
regex = "1.12.2"

[features]
default = ["zstd", "fuse"]
Expand Down
88 changes: 50 additions & 38 deletions arx/src/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ const AFTER_HELP: &str = cstr!(

The command format is :
<i>$ arx -o my_archive.arx input_file1 input_file2 input_dir1 ...</i>
In this mode, <i>--recurse</i> is true by default.

<s>From list file ([FILE_LIST])</s>

The command format is :
<i>$ arx -o my_archive.arx -L file_list.txt</i>
In this mode, <i>--recurse</i> is false by default.

File list can be generated this way :
<i>$ find input_dir > file_list.txt</i>
Expand All @@ -51,11 +49,26 @@ foo/bar.txt
```
(If you've used <i>find</i> to generate the list : don't use <i>-type f</i> option)

<s>About file list and <i>--follow-symlink</i> option</s>
<s>About <i>--follow-symlink</i> option</s>

Listing in file list and <i>--follow-symlink</i> passed to arx, you must be coherent.
Follow symlink all the time or never.
If you don't, you may have incoherent state when symlink are pointing to directories.
When passing entries to arx, you must be consistent with <i>--follow-symlink</i>.
One way to be inconsistent is:
1. You have a link (L), pointing to a directory (D) containing a file (D/F).
2. You create a arx passing as input both L and L/F.
3. You don't give <i>--follow-symlink</i>
4. Arx create a symlink L and then try to add the file F to directory L, which is not possible
because L is a symlink.

<s>Triming path</s>

By default, arx trim input path and remove any parent parts. This can be changed with the <i>--keep-parents</i>
option, in this case the path given as input is fully add to the archive.

Absolute path are always trimmed of its first part to become a relative path.

The option <i>--dir_as_root</i> makes arx trim the directory itself. So (if recursion is activated) all entries
in the given directory as place at root of the created archive.
This option has no effect if the input path is a file.

<s,u>Compression detection/selection:</>

Expand Down Expand Up @@ -88,10 +101,6 @@ pub struct Options {
)]
outfile: Option<jbk::Utf8PathBuf>,

/// Remove STRIP_PREFIX from the entries' name added to the archive.
#[arg(long, required = false, value_hint=ValueHint::DirPath, help_heading="Input options")]
strip_prefix: Option<arx::PathBuf>,

/// Move to BASE_DIR before starting adding content to arx archive.
///
/// Argument `INFILES` or `STRIP_PREFIX` must be relative to `BASE_DIR`.
Expand All @@ -100,6 +109,22 @@ pub struct Options {
#[arg(short = 'C', required = false, value_hint=ValueHint::DirPath, verbatim_doc_comment, help_heading="Input options")]
base_dir: Option<PathBuf>,

/// Keep N parents from given path.
///
/// If N > number of parent in the path, keep the path full.
#[arg(short = 'k', long, required = false, default_value_t = Default::default())]
keep_parents: bool,

/// Input dir are considered as root directory.
///
/// Directories given in input are considered as root directory.
/// This means we add file/directory in the given directory directly in the root of arx archive.
/// If input is a file, this options has no effect.
/// If several directories are given, they are all considered as root. However, as it is not possible to have
/// duplicated entries in an arx achive, the directories must be disjoint.
#[arg(long, required = false, default_value_t = false)]
dir_as_root: bool,

/// Input files/directories
///
/// This is an option incompatible with `FILE_LIST.`
Expand Down Expand Up @@ -131,13 +156,11 @@ pub struct Options {
short,
long,
required = false,
default_value_t = false,
default_value_ifs([
("no_recurse", clap::builder::ArgPredicate::IsPresent, "false"),
("infiles", clap::builder::ArgPredicate::IsPresent, "true")
]),
default_value_t = true,
default_value_if("no_recurse", clap::builder::ArgPredicate::IsPresent, "false"),
conflicts_with = "no_recurse",
action, help_heading="Input options"
action,
help_heading = "Input options"
)]
recurse: bool,

Expand Down Expand Up @@ -275,11 +298,6 @@ pub fn create(options: Options) -> Result<()> {
return Ok(());
}

let strip_prefix = match &options.strip_prefix {
Some(s) => s.clone(),
None => arx::PathBuf::new(),
};

let out_file = options.outfile.as_ref().expect(
"Clap unsure it is Some, except if we have list_compressions, and so we return early",
);
Expand Down Expand Up @@ -312,32 +330,26 @@ pub fn create(options: Options) -> Result<()> {
options.compression,
)?;

let mut adder = arx::create::FsAdder::new(
&mut creator,
options.keep_parents,
options.follow_symlink,
options.dir_as_root,
);

if let Some(file_list) = file_list {
let file = File::open(&file_list)
.with_context(|| format!("Cannot open {}", file_list.display()))?;
let files_list = BufReader::new(file)
.lines()
.map(|l| -> Result<PathBuf> { Ok(l?.into()) })
.collect::<Result<Vec<_>>>()?;
let mut list_adder = arx::create::FsAdder::new(&mut creator, strip_prefix);
list_adder.add_from_list(files_list.into_iter(), options.follow_symlink)?;
adder.add_from_list(files_list.into_iter())?;
} else {
let files_list = options
.infiles
.iter()
.map(|f| -> Result<PathBuf> {
if f.is_absolute() {
Err(anyhow!("Input file ({}) must be relative.", f.display()))
} else {
Ok(f.clone())
}
})
.collect::<Result<Vec<_>>>()?;
check_input_paths_exist(&files_list)?;
let mut fs_adder = arx::create::FsAdder::new(&mut creator, strip_prefix);
for infile in files_list {
check_input_paths_exist(&options.infiles)?;
for infile in options.infiles {
debug!("Adding file {infile:?}");
fs_adder.add_from_path(&infile, options.recurse)?;
adder.add_from_path(&infile, options.recurse)?;
}
};

Expand Down
Loading
Loading