diff options
author | Rob Landley <rob@landley.net> | 2006-06-13 14:54:42 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-06-13 14:54:42 +0000 |
commit | 9a202c9daaac25296129d1b2d63fedd28efe4a0d (patch) | |
tree | 906c371755ccc1abb19955b43cf91f318bf2c891 | |
parent | 1dea55d577641540bfc85f1d969667d89539ef6d (diff) | |
download | busybox-w32-9a202c9daaac25296129d1b2d63fedd28efe4a0d.tar.gz busybox-w32-9a202c9daaac25296129d1b2d63fedd28efe4a0d.tar.bz2 busybox-w32-9a202c9daaac25296129d1b2d63fedd28efe4a0d.zip |
Patch from Denis Vlasenko: unlzma was make files with mode 777. Tweak
everything to do stat() and use xopen3().
-rw-r--r-- | archival/bunzip2.c | 9 | ||||
-rw-r--r-- | archival/gunzip.c | 7 | ||||
-rw-r--r-- | archival/unlzma.c | 7 |
3 files changed, 15 insertions, 8 deletions
diff --git a/archival/bunzip2.c b/archival/bunzip2.c index 1b074c4ee..09364b40e 100644 --- a/archival/bunzip2.c +++ b/archival/bunzip2.c | |||
@@ -41,16 +41,21 @@ int bunzip2_main(int argc, char **argv) | |||
41 | 41 | ||
42 | /* Check that the input is sane. */ | 42 | /* Check that the input is sane. */ |
43 | if (isatty(src_fd) && (opt & BUNZIP2_OPT_FORCE) == 0) { | 43 | if (isatty(src_fd) && (opt & BUNZIP2_OPT_FORCE) == 0) { |
44 | bb_error_msg_and_die("compressed data not read from terminal. Use -f to force it."); | 44 | bb_error_msg_and_die("Compressed data not read from terminal. Use -f to force it."); |
45 | } | 45 | } |
46 | 46 | ||
47 | if (filename) { | 47 | if (filename) { |
48 | struct stat stat_buf; | ||
48 | char *extension=filename+strlen(filename)-4; | 49 | char *extension=filename+strlen(filename)-4; |
49 | if (strcmp(extension, ".bz2") != 0) { | 50 | if (strcmp(extension, ".bz2") != 0) { |
50 | bb_error_msg_and_die("Invalid extension"); | 51 | bb_error_msg_and_die("Invalid extension"); |
51 | } | 52 | } |
53 | /* TODO: xstat */ | ||
54 | if (stat(filename, &stat_buf) < 0) { | ||
55 | bb_error_msg_and_die("Couldn't stat file %s", filename); | ||
56 | } | ||
52 | *extension=0; | 57 | *extension=0; |
53 | dst_fd = bb_xopen(filename, O_WRONLY | O_CREAT); | 58 | dst_fd = bb_xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode); |
54 | } else dst_fd = STDOUT_FILENO; | 59 | } else dst_fd = STDOUT_FILENO; |
55 | status = uncompressStream(src_fd, dst_fd); | 60 | status = uncompressStream(src_fd, dst_fd); |
56 | if(filename) { | 61 | if(filename) { |
diff --git a/archival/gunzip.c b/archival/gunzip.c index 7b939290b..35449b04d 100644 --- a/archival/gunzip.c +++ b/archival/gunzip.c | |||
@@ -137,11 +137,8 @@ int gunzip_main(int argc, char **argv) | |||
137 | bb_error_msg_and_die("Invalid extension"); | 137 | bb_error_msg_and_die("Invalid extension"); |
138 | } | 138 | } |
139 | 139 | ||
140 | /* Open output file */ | 140 | /* Open output file (with correct permissions) */ |
141 | dst_fd = bb_xopen(new_path, O_WRONLY | O_CREAT); | 141 | dst_fd = bb_xopen3(new_path, O_WRONLY | O_CREAT, stat_buf.st_mode); |
142 | |||
143 | /* Set permissions on the file */ | ||
144 | chmod(new_path, stat_buf.st_mode); | ||
145 | 142 | ||
146 | /* If unzip succeeds remove the old file */ | 143 | /* If unzip succeeds remove the old file */ |
147 | delete_path = old_path; | 144 | delete_path = old_path; |
diff --git a/archival/unlzma.c b/archival/unlzma.c index dc85cb25e..404da0acd 100644 --- a/archival/unlzma.c +++ b/archival/unlzma.c | |||
@@ -41,13 +41,18 @@ int unlzma_main(int argc, char **argv) | |||
41 | filename = 0; | 41 | filename = 0; |
42 | 42 | ||
43 | if (filename) { | 43 | if (filename) { |
44 | struct stat stat_buf; | ||
44 | char *extension = filename + strlen(filename) - 5; | 45 | char *extension = filename + strlen(filename) - 5; |
45 | 46 | ||
46 | if (strcmp(extension, ".lzma") != 0) { | 47 | if (strcmp(extension, ".lzma") != 0) { |
47 | bb_error_msg_and_die("Invalid extension"); | 48 | bb_error_msg_and_die("Invalid extension"); |
48 | } | 49 | } |
50 | /* TODO: xstat? */ | ||
51 | if (stat(filename, &stat_buf) < 0) { | ||
52 | bb_error_msg_and_die("Couldn't stat file %s", filename); | ||
53 | } | ||
49 | *extension = 0; | 54 | *extension = 0; |
50 | dst_fd = bb_xopen(filename, O_WRONLY | O_CREAT); | 55 | dst_fd = bb_xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode); |
51 | } else | 56 | } else |
52 | dst_fd = STDOUT_FILENO; | 57 | dst_fd = STDOUT_FILENO; |
53 | status = unlzma(src_fd, dst_fd); | 58 | status = unlzma(src_fd, dst_fd); |