Make open use mode 0777 since it will already be & ~umask it will preserve the default permissions.

Don't try to copy permissions from STDIN.
This commit is contained in:
Con Kolivas 2011-04-10 11:03:45 +10:00
parent e66d97ab19
commit 920ad9251d

11
lrzip.c
View file

@ -595,11 +595,11 @@ void decompress_file(rzip_control *control)
control->fd_in = fd_in; control->fd_in = fd_in;
if (!(TEST_ONLY | STDOUT)) { if (!(TEST_ONLY | STDOUT)) {
fd_out = open(control->outfile, O_WRONLY | O_CREAT | O_EXCL, 0600); fd_out = open(control->outfile, O_WRONLY | O_CREAT | O_EXCL, 0777);
if (FORCE_REPLACE && (-1 == fd_out) && (EEXIST == errno)) { if (FORCE_REPLACE && (-1 == fd_out) && (EEXIST == errno)) {
if (unlikely(unlink(control->outfile))) if (unlikely(unlink(control->outfile)))
fatal("Failed to unlink an existing file: %s\n", control->outfile); fatal("Failed to unlink an existing file: %s\n", control->outfile);
fd_out = open(control->outfile, O_WRONLY | O_CREAT | O_EXCL, 0600); fd_out = open(control->outfile, O_WRONLY | O_CREAT | O_EXCL, 0777);
} }
if (unlikely(fd_out == -1)) { if (unlikely(fd_out == -1)) {
/* We must ensure we don't delete a file that already /* We must ensure we don't delete a file that already
@ -611,6 +611,8 @@ void decompress_file(rzip_control *control)
if (unlikely(fd_hist == -1)) if (unlikely(fd_hist == -1))
fatal("Failed to open history file %s\n", control->outfile); fatal("Failed to open history file %s\n", control->outfile);
/* Can't copy permissions from STDIN */
if (!STDIN)
preserve_perms(control, fd_in, fd_out); preserve_perms(control, fd_in, fd_out);
} else { } else {
fd_out = open_tmpoutfile(control); fd_out = open_tmpoutfile(control);
@ -1012,11 +1014,11 @@ void compress_file(rzip_control *control)
print_progress("Output filename is: %s\n", control->outfile); print_progress("Output filename is: %s\n", control->outfile);
} }
fd_out = open(control->outfile, O_RDWR | O_CREAT | O_EXCL, 0600); fd_out = open(control->outfile, O_RDWR | O_CREAT | O_EXCL, 0777);
if (FORCE_REPLACE && (-1 == fd_out) && (EEXIST == errno)) { if (FORCE_REPLACE && (-1 == fd_out) && (EEXIST == errno)) {
if (unlikely(unlink(control->outfile))) if (unlikely(unlink(control->outfile)))
fatal("Failed to unlink an existing file: %s\n", control->outfile); fatal("Failed to unlink an existing file: %s\n", control->outfile);
fd_out = open(control->outfile, O_RDWR | O_CREAT | O_EXCL, 0600); fd_out = open(control->outfile, O_RDWR | O_CREAT | O_EXCL, 0777);
} }
if (unlikely(fd_out == -1)) { if (unlikely(fd_out == -1)) {
/* We must ensure we don't delete a file that already /* We must ensure we don't delete a file that already
@ -1025,6 +1027,7 @@ void compress_file(rzip_control *control)
fatal("Failed to create %s\n", control->outfile); fatal("Failed to create %s\n", control->outfile);
} }
control->fd_out = fd_out; control->fd_out = fd_out;
if (!STDIN)
preserve_perms(control, fd_in, fd_out); preserve_perms(control, fd_in, fd_out);
} else } else
open_tmpoutbuf(control); open_tmpoutbuf(control);