Don't compress or decompress special files unless writing
to stdout even if --force is used. --force will still enable compression of symlinks, but only in case they point to a regular file. The new way simply seems more reasonable. It matches gzip's behavior while the old one matched bzip2's behavior.
This commit is contained in:
parent
cee12aa852
commit
23ac2c44c3
|
@ -275,9 +275,14 @@ io_open_src(file_pair *pair)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Symlinks are not followed unless writing to stdout or --force
|
||||||
|
// was used.
|
||||||
|
const bool follow_symlinks = opt_stdout || opt_force;
|
||||||
|
|
||||||
// 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, and if --force was not given.
|
// to disk too. bzip2 allows overriding this with --force but
|
||||||
const bool reg_files_only = !opt_stdout && !opt_force;
|
// gzip and xz don't.
|
||||||
|
const bool reg_files_only = !opt_stdout;
|
||||||
|
|
||||||
// Flags for open()
|
// Flags for open()
|
||||||
int flags = O_RDONLY | O_BINARY | O_NOCTTY;
|
int flags = O_RDONLY | O_BINARY | O_NOCTTY;
|
||||||
|
@ -293,13 +298,13 @@ io_open_src(file_pair *pair)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(O_NOFOLLOW)
|
#if defined(O_NOFOLLOW)
|
||||||
if (reg_files_only)
|
if (!follow_symlinks)
|
||||||
flags |= O_NOFOLLOW;
|
flags |= O_NOFOLLOW;
|
||||||
#elif !defined(TUKLIB_DOSLIKE)
|
#elif !defined(TUKLIB_DOSLIKE)
|
||||||
// Some POSIX-like systems lack O_NOFOLLOW (it's not required
|
// Some POSIX-like systems lack O_NOFOLLOW (it's not required
|
||||||
// by POSIX). Check for symlinks with a separate lstat() on
|
// by POSIX). Check for symlinks with a separate lstat() on
|
||||||
// these systems.
|
// these systems.
|
||||||
if (reg_files_only) {
|
if (!follow_symlinks) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (lstat(pair->src_name, &st)) {
|
if (lstat(pair->src_name, &st)) {
|
||||||
message_error("%s: %s", pair->src_name,
|
message_error("%s: %s", pair->src_name,
|
||||||
|
@ -374,7 +379,7 @@ io_open_src(file_pair *pair)
|
||||||
was_symlink = true;
|
was_symlink = true;
|
||||||
|
|
||||||
# else
|
# else
|
||||||
if (errno == ELOOP && reg_files_only) {
|
if (errno == ELOOP && !follow_symlinks) {
|
||||||
const int saved_errno = errno;
|
const int saved_errno = errno;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (lstat(pair->src_name, &st) == 0
|
if (lstat(pair->src_name, &st) == 0
|
||||||
|
|
Loading…
Reference in New Issue