xz: Make --keep accept symlinks, hardlinks, and setuid/setgid/sticky.

Previously this required using --force but that has other
effects too which might be undesirable. Changing the behavior
of --keep has a small risk of breaking existing scripts but
since this is a fairly special corner case I expect the
likehood of breakage to be low enough.

I think the new behavior is more logical. The only reason for
the old behavior was to be consistent with gzip and bzip2.

Thanks to Vincent Lefevre and Sebastian Andrzej Siewior.
This commit is contained in:
Lasse Collin 2021-01-11 23:41:16 +02:00
parent 73c555b307
commit 074259f4f3
2 changed files with 20 additions and 5 deletions

View File

@ -536,8 +536,9 @@ io_open_src_real(file_pair *pair)
} }
// Symlinks are not followed unless writing to stdout or --force // Symlinks are not followed unless writing to stdout or --force
// was used. // or --keep was used.
const bool follow_symlinks = opt_stdout || opt_force; const bool follow_symlinks
= opt_stdout || opt_force || opt_keep_original;
// We accept only regular files if we are writing the output // We accept only regular files if we are writing the output
// to disk too. bzip2 allows overriding this with --force but // to disk too. bzip2 allows overriding this with --force but
@ -674,7 +675,7 @@ io_open_src_real(file_pair *pair)
} }
#ifndef TUKLIB_DOSLIKE #ifndef TUKLIB_DOSLIKE
if (reg_files_only && !opt_force) { if (reg_files_only && !opt_force && !opt_keep_original) {
if (pair->src_st.st_mode & (S_ISUID | S_ISGID)) { if (pair->src_st.st_mode & (S_ISUID | S_ISGID)) {
// gzip rejects setuid and setgid files even // gzip rejects setuid and setgid files even
// when --force was used. bzip2 doesn't check // when --force was used. bzip2 doesn't check
@ -683,7 +684,7 @@ io_open_src_real(file_pair *pair)
// and setgid bits there. // and setgid bits there.
// //
// We accept setuid and setgid files if // We accept setuid and setgid files if
// --force was used. We drop these bits // --force or --keep was used. We drop these bits
// explicitly in io_copy_attr(). // explicitly in io_copy_attr().
message_warning(_("%s: File has setuid or " message_warning(_("%s: File has setuid or "
"setgid bit set, skipping"), "setgid bit set, skipping"),

View File

@ -5,7 +5,7 @@
.\" This file has been put into the public domain. .\" This file has been put into the public domain.
.\" You can do whatever you want with this file. .\" You can do whatever you want with this file.
.\" .\"
.TH XZ 1 "2020-11-01" "Tukaani" "XZ Utils" .TH XZ 1 "2021-01-11" "Tukaani" "XZ Utils"
. .
.SH NAME .SH NAME
xz, unxz, xzcat, lzma, unlzma, lzcat \- Compress or decompress .xz and .lzma files xz, unxz, xzcat, lzma, unlzma, lzcat \- Compress or decompress .xz and .lzma files
@ -392,6 +392,20 @@ should be used.
.TP .TP
.BR \-k ", " \-\-keep .BR \-k ", " \-\-keep
Don't delete the input files. Don't delete the input files.
.IP ""
Since
.B xz
5.4.0,
this option also makes
.B xz
compress or decompress even if the input is
a symbolic link to a regular file,
has more than one hard link,
or has the setuid, setgid, or sticky bit set.
The setuid, setgid, and sticky bits are not copied
to the target file.
In earlier versions this was only done with
.BR \-\-force .
.TP .TP
.BR \-f ", " \-\-force .BR \-f ", " \-\-force
This option has several effects: This option has several effects: