Skip to content

Commit 0d62ace

Browse files
committed
💥 Change stdio -x default overwrite behavior
Align pna stdio -x’s overwrite strategy with bsdtar so existing files are replaced by default, fixing partial restore jobs that previously stopped at collisions and matching users’ expectations from other tar tools. Operators who need to retain the legacy “skip on conflict” semantics can still opt out explicitly with the overwrite-suppression flag.
1 parent 7208008 commit 0d62ace

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

cli/src/command/extract.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,13 @@ fn extract_archive(args: ExtractCommand) -> anyhow::Result<()> {
252252
files.extend(read_paths(path, args.null)?);
253253
}
254254

255-
let overwrite_strategy =
256-
OverwriteStrategy::from_flags(args.overwrite, args.keep_newer_files, args.keep_old_files);
255+
let overwrite_strategy = OverwriteStrategy::from_flags(
256+
args.overwrite,
257+
args.no_overwrite,
258+
args.keep_newer_files,
259+
args.keep_old_files,
260+
OverwriteStrategy::Never,
261+
);
257262
let keep_options = KeepOptions {
258263
timestamp_strategy: TimestampStrategy::from_flags(
259264
args.keep_timestamp,
@@ -333,15 +338,23 @@ pub(crate) enum OverwriteStrategy {
333338
}
334339

335340
impl OverwriteStrategy {
336-
pub(crate) const fn from_flags(overwrite: bool, keep_newer: bool, keep_older: bool) -> Self {
341+
pub(crate) const fn from_flags(
342+
overwrite: bool,
343+
no_overwrite: bool,
344+
keep_newer: bool,
345+
keep_older: bool,
346+
default_strategy: Self,
347+
) -> Self {
337348
if overwrite {
338349
Self::Always
350+
} else if no_overwrite {
351+
Self::Never
339352
} else if keep_newer {
340353
Self::KeepNewer
341354
} else if keep_older {
342355
Self::KeepOlder
343356
} else {
344-
Self::Never
357+
default_strategy
345358
}
346359
}
347360
}

cli/src/command/stdio.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,13 @@ fn run_extract_archive(args: StdioCommand) -> anyhow::Result<()> {
555555
exclude.iter().map(|s| s.as_str()).chain(vcs_patterns),
556556
);
557557

558-
let overwrite_strategy =
559-
OverwriteStrategy::from_flags(args.overwrite, args.keep_newer_files, args.keep_old_files);
558+
let overwrite_strategy = OverwriteStrategy::from_flags(
559+
args.overwrite,
560+
args.no_overwrite,
561+
args.keep_newer_files,
562+
args.keep_old_files,
563+
OverwriteStrategy::Always,
564+
);
560565
let out_option = OutputOption {
561566
overwrite_strategy,
562567
allow_unsafe_links: args.allow_unsafe_links,

0 commit comments

Comments
 (0)