changeset 1720:ceb208839770

Quick cleanup pass on tar.
author Rob Landley <rob@landley.net>
date Tue, 03 Mar 2015 22:06:55 -0600
parents 848969327d77
children a580ecd4a78a
files toys/pending/tar.c
diffstat 1 files changed, 7 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/toys/pending/tar.c	Mon Mar 02 20:27:50 2015 -0600
+++ b/toys/pending/tar.c	Tue Mar 03 22:06:55 2015 -0600
@@ -32,6 +32,7 @@
     X File with names to exclude
     T File with names to include
 */
+
 #define FOR_tar
 #include "toys.h"
 
@@ -433,7 +434,8 @@
       if (pw) u = pw->pw_uid;
       if (gr) g = gr->gr_gid;
     }
-    chown(file_hdr->name, u, g);
+    if (chown(file_hdr->name, u, g))
+      perror_msg("chown %d:%d '%s'", u, g, file_hdr->name);;
   }
 
   if (toys.optflags & FLAG_p) // || !(toys.optflags & FLAG_no_same_permissions))
@@ -745,15 +747,10 @@
 void tar_main(void)
 {
   struct archive_handler *tar_hdl;
-  int fd = 0, flags = O_RDONLY;
+  int fd = 0;
   struct arg_list *tmp;
   char **args = toys.optargs;
 
-  if (!toys.argv[1]) {
-    toys.exithelp++;
-    error_exit(NULL);
-  }
-
   if (!geteuid()) toys.optflags |= FLAG_p;
 
   for (tmp = TT.exc; tmp; tmp = tmp->next)
@@ -765,16 +762,16 @@
 
   if (toys.optflags & FLAG_c) {
     if (!TT.inc) error_exit("empty archive");
-    fd = 1, flags = O_WRONLY|O_CREAT|O_TRUNC;
+    fd = 1;
   }
   if ((toys.optflags & FLAG_f) && strcmp(TT.fname, "-")) 
-    fd = xcreate(TT.fname, flags, 0666);
+    fd = xcreate(TT.fname, fd*(O_WRONLY|O_CREAT|O_TRUNC), 0666);
   if (toys.optflags & FLAG_C) xchdir(TT.dir);
 
   tar_hdl = init_handler();
   tar_hdl->src_fd = fd;
 
-  if (toys.optflags & FLAG_x || toys.optflags & FLAG_t) {
+  if ((toys.optflags & FLAG_x) || (toys.optflags & FLAG_t)) {
     if (toys.optflags & FLAG_O) tar_hdl->extract_handler = extract_to_stdout;
     if (toys.optflags & FLAG_to_command) {
       signal(SIGPIPE, SIG_IGN); //will be using pipe between child & parent