Patch from Denis Vlasenko: unlzma was make files with mode 777. Tweak
authorRob Landley <rob@landley.net>
Tue, 13 Jun 2006 14:54:42 +0000 (14:54 -0000)
committerRob Landley <rob@landley.net>
Tue, 13 Jun 2006 14:54:42 +0000 (14:54 -0000)
everything to do stat() and use xopen3().

archival/bunzip2.c
archival/gunzip.c
archival/unlzma.c

index 1b074c4eeae21e7f549c37101d1083574044d26e..09364b40ecec128e9b9804452837a1d1fda6d52a 100644 (file)
@@ -41,16 +41,21 @@ int bunzip2_main(int argc, char **argv)
 
        /* Check that the input is sane.  */
        if (isatty(src_fd) && (opt & BUNZIP2_OPT_FORCE) == 0) {
-               bb_error_msg_and_die("compressed data not read from terminal.  Use -f to force it.");
+               bb_error_msg_and_die("Compressed data not read from terminal.  Use -f to force it.");
        }
 
        if (filename) {
+               struct stat stat_buf;
                char *extension=filename+strlen(filename)-4;
                if (strcmp(extension, ".bz2") != 0) {
                        bb_error_msg_and_die("Invalid extension");
                }
+               /* TODO: xstat */
+               if (stat(filename, &stat_buf) < 0) {
+                       bb_error_msg_and_die("Couldn't stat file %s", filename);
+               }
                *extension=0;
-               dst_fd = bb_xopen(filename, O_WRONLY | O_CREAT);
+               dst_fd = bb_xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode);
        } else dst_fd = STDOUT_FILENO;
        status = uncompressStream(src_fd, dst_fd);
        if(filename) {
index 7b939290b4b13e80234aca26a6eddbacc9449689..35449b04d074dec90be22bca00f5a6326053b749 100644 (file)
@@ -137,11 +137,8 @@ int gunzip_main(int argc, char **argv)
                                bb_error_msg_and_die("Invalid extension");
                        }
 
-                       /* Open output file */
-                       dst_fd = bb_xopen(new_path, O_WRONLY | O_CREAT);
-
-                       /* Set permissions on the file */
-                       chmod(new_path, stat_buf.st_mode);
+                       /* Open output file (with correct permissions) */
+                       dst_fd = bb_xopen3(new_path, O_WRONLY | O_CREAT, stat_buf.st_mode);
 
                        /* If unzip succeeds remove the old file */
                        delete_path = old_path;
index dc85cb25ebc6818e77331cec4b1f8d584146e3ca..404da0acd486fa819e1d01d5c6561413acc22d44 100644 (file)
@@ -41,13 +41,18 @@ int unlzma_main(int argc, char **argv)
                filename = 0;
 
        if (filename) {
+               struct stat stat_buf;
                char *extension = filename + strlen(filename) - 5;
 
                if (strcmp(extension, ".lzma") != 0) {
                        bb_error_msg_and_die("Invalid extension");
                }
+               /* TODO: xstat? */
+               if (stat(filename, &stat_buf) < 0) {
+                       bb_error_msg_and_die("Couldn't stat file %s", filename);
+               }
                *extension = 0;
-               dst_fd = bb_xopen(filename, O_WRONLY | O_CREAT);
+               dst_fd = bb_xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode);
        } else
                dst_fd = STDOUT_FILENO;
        status = unlzma(src_fd, dst_fd);