Skip to content

Commit 2905579

Browse files
committed
✨ Add bsdtar-compatible verbose output for stdio subcommand
- Create mode: prints "a <path>" to stderr for each entry - Extract mode: prints "x <path>" to stderr for each entry - Append mode: prints "a <path>" to stderr for each entry - Update mode: prints "a <path>" to stderr for each entry - Verbose output is controlled by -v flag, only for stdio subcommand - Regular create/extract/append/update commands are unaffected
1 parent 54687fb commit 2905579

5 files changed

Lines changed: 47 additions & 3 deletions

File tree

cli/src/command/append.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ fn append_to_archive(args: AppendCommand) -> anyhow::Result<()> {
472472
&filter,
473473
&time_filters,
474474
password,
475+
false,
475476
)
476477
}
477478

@@ -482,9 +483,15 @@ pub(crate) fn run_append_archive(
482483
filter: &PathFilter<'_>,
483484
time_filters: &TimeFilters,
484485
password: Option<&[u8]>,
486+
verbose: bool,
485487
) -> anyhow::Result<()> {
486488
let rx = spawn_entry_results(target_items, create_options, filter, time_filters, password);
487-
drain_entry_results(rx, |entry| archive.add_entry(entry))?;
489+
drain_entry_results(rx, |entry| {
490+
if verbose {
491+
eprintln!("a {}", entry.name());
492+
}
493+
archive.add_entry(entry)
494+
})?;
488495
archive.finalize()?;
489496
Ok(())
490497
}

cli/src/command/create.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ fn create_archive(args: CreateCommand) -> anyhow::Result<()> {
530530
&filter,
531531
&time_filters,
532532
password,
533+
false,
533534
)?;
534535
}
535536
log::info!(
@@ -558,6 +559,7 @@ pub(crate) fn create_archive_file<W, F>(
558559
filter: &PathFilter<'_>,
559560
time_filters: &TimeFilters,
560561
password: Option<&[u8]>,
562+
verbose: bool,
561563
) -> anyhow::Result<()>
562564
where
563565
W: Write,
@@ -585,11 +587,21 @@ where
585587
let buffered = io::BufWriter::with_capacity(64 * 1024, file);
586588
if solid {
587589
let mut writer = Archive::write_solid_header(buffered, write_option)?;
588-
drain_entry_results(rx, |entry| writer.add_entry(entry))?;
590+
drain_entry_results(rx, |entry| {
591+
if verbose {
592+
eprintln!("a {}", entry.name());
593+
}
594+
writer.add_entry(entry)
595+
})?;
589596
writer.finalize()?;
590597
} else {
591598
let mut writer = Archive::write_header(buffered)?;
592-
drain_entry_results(rx, |entry| writer.add_entry(entry))?;
599+
drain_entry_results(rx, |entry| {
600+
if verbose {
601+
eprintln!("a {}", entry.name());
602+
}
603+
writer.add_entry(entry)
604+
})?;
593605
writer.finalize()?;
594606
}
595607
Ok(())

cli/src/command/extract.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ fn extract_archive(args: ExtractCommand) -> anyhow::Result<()> {
462462
unlink_first: false,
463463
time_filters,
464464
safe_writes: args.safe_writes && !args.no_safe_writes,
465+
verbose: false,
465466
};
466467
if let Some(working_dir) = args.working_dir {
467468
env::set_current_dir(&working_dir)
@@ -548,6 +549,7 @@ pub(crate) struct OutputOption<'a> {
548549
pub(crate) unlink_first: bool,
549550
pub(crate) time_filters: TimeFilters,
550551
pub(crate) safe_writes: bool,
552+
pub(crate) verbose: bool,
551553
}
552554

553555
pub(crate) fn run_extract_archive_reader<'a, 'p, Provider>(
@@ -589,6 +591,9 @@ where
589591
log::debug!("Skip: {item_path}");
590592
return Ok(());
591593
};
594+
if args.verbose {
595+
eprintln!("x {}", name);
596+
}
592597
if args.to_stdout {
593598
return extract_entry_to_stdout(&item, password);
594599
}
@@ -668,6 +673,9 @@ where
668673
log::debug!("Skip: {item_path}");
669674
return Ok(());
670675
};
676+
if args.verbose {
677+
eprintln!("x {}", name);
678+
}
671679
if args.to_stdout {
672680
return extract_entry_to_stdout(&item, password);
673681
}
@@ -827,6 +835,7 @@ pub(crate) fn extract_entry<'a, T>(
827835
unlink_first,
828836
time_filters: _,
829837
safe_writes,
838+
verbose: _,
830839
}: &OutputOption<'a>,
831840
) -> io::Result<()>
832841
where

cli/src/command/stdio.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ fn run_create_archive(args: StdioCommand) -> anyhow::Result<()> {
929929
&filter,
930930
&time_filters,
931931
password,
932+
args.verbose,
932933
)
933934
} else {
934935
create_archive_file(
@@ -938,6 +939,7 @@ fn run_create_archive(args: StdioCommand) -> anyhow::Result<()> {
938939
&filter,
939940
&time_filters,
940941
password,
942+
args.verbose,
941943
)
942944
}
943945
}
@@ -1043,6 +1045,7 @@ fn run_extract_archive(ctx: &GlobalContext, args: StdioCommand) -> anyhow::Resul
10431045
unlink_first: args.unlink_first,
10441046
time_filters,
10451047
safe_writes: args.safe_writes && !args.no_safe_writes,
1048+
verbose: args.verbose,
10461049
};
10471050
let mut files = args.files;
10481051
if let Some(path) = &args.files_from {
@@ -1278,6 +1281,7 @@ fn run_append(args: StdioCommand) -> anyhow::Result<()> {
12781281
&filter,
12791282
&time_filters,
12801283
password,
1284+
args.verbose,
12811285
)
12821286
} else {
12831287
let target_items = collect_items_from_sources(sources, &collect_options, &mut resolver)?;
@@ -1295,6 +1299,7 @@ fn run_append(args: StdioCommand) -> anyhow::Result<()> {
12951299
&filter,
12961300
&time_filters,
12971301
password,
1302+
args.verbose,
12981303
)
12991304
}
13001305
}
@@ -1461,6 +1466,7 @@ fn run_update(args: StdioCommand) -> anyhow::Result<()> {
14611466
false, // sync is always false for stdio (bsdtar compatibility)
14621467
&mut out_archive,
14631468
TransformStrategyUnSolid,
1469+
args.verbose,
14641470
)?;
14651471

14661472
out_archive.finalize()?;

cli/src/command/update.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ fn update_archive(args: UpdateCommand) -> anyhow::Result<()> {
497497
sync,
498498
&mut out_archive,
499499
TransformStrategyUnSolid,
500+
false,
500501
),
501502
SolidEntriesTransformStrategy::KeepSolid => run_update_archive(
502503
archives,
@@ -506,6 +507,7 @@ fn update_archive(args: UpdateCommand) -> anyhow::Result<()> {
506507
sync,
507508
&mut out_archive,
508509
TransformStrategyKeepSolid,
510+
false,
509511
),
510512
}?;
511513

@@ -528,6 +530,7 @@ pub(crate) fn run_update_archive<Strategy, R, W>(
528530
sync: bool,
529531
out_archive: &mut Archive<W>,
530532
_strategy: Strategy,
533+
verbose: bool,
531534
) -> anyhow::Result<()>
532535
where
533536
Strategy: TransformStrategy,
@@ -589,6 +592,9 @@ where
589592

590593
for entry in ReorderByIndex::new(rx.into_iter()) {
591594
if let Some(entry) = entry? {
595+
if verbose {
596+
eprintln!("a {}", entry.name());
597+
}
592598
out_archive.add_entry(entry)?;
593599
}
594600
}
@@ -605,6 +611,7 @@ pub(crate) fn run_update_archive<'d, Strategy, W>(
605611
sync: bool,
606612
out_archive: &mut Archive<W>,
607613
_strategy: Strategy,
614+
verbose: bool,
608615
) -> anyhow::Result<()>
609616
where
610617
Strategy: TransformStrategy,
@@ -665,6 +672,9 @@ where
665672

666673
for entry in ReorderByIndex::new(rx.into_iter()) {
667674
if let Some(entry) = entry? {
675+
if verbose {
676+
eprintln!("a {}", entry.name());
677+
}
668678
out_archive.add_entry(entry)?;
669679
}
670680
}

0 commit comments

Comments
 (0)