]> Dogcows Code - chaz/tar/blobdiff - src/create.c
*** empty log message ***
[chaz/tar] / src / create.c
index c2453409efb076499aea266c67ff7121d5182d19..b03c2f227c694df8990bf5cd7545f4eab3840bc7 100644 (file)
@@ -1,5 +1,5 @@
 /* Create a tar archive.
-   Copyright (C) 1988 Free Software Foundation
+   Copyright (C) 1985, 1992 Free Software Foundation
 
 This file is part of GNU Tar.
 
@@ -33,9 +33,6 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 extern int     errno;
 #endif
 
-#include "tar.h"
-#include "port.h"
-
 #ifdef BSD42
 #include <sys/file.h>
 #else
@@ -44,6 +41,9 @@ extern int    errno;
 #endif
 #endif
 
+#include "tar.h"
+#include "port.h"
+
 #ifndef        __MSDOS__
 #include <pwd.h>
 #include <grp.h>
@@ -91,8 +91,6 @@ extern struct name *gnu_list_name;
 extern void print_header();
 
 union record *start_header();
-void add_mangle();
-void add_symlink_mangle();
 void blank_name_list();
 int check_exclude();
 PTR ck_malloc();
@@ -115,7 +113,6 @@ void to_oct();
 void dump_file();
 void write_dir_file();
 void write_eot();
-void write_mangled();
 int zero_record();
 
 /* This code moved from tar.h since create.c is the only file that cares
@@ -152,13 +149,13 @@ create_archive()
        open_archive(0);                /* Open for writing */
 
        if(f_gnudump) {
-               char *buf = ck_malloc(NAME_MAX);
+               char *buf = ck_malloc(PATH_MAX);
                char *q,*bufp;
 
                collect_and_sort_names();
 
                while(p=name_from_list())
-                       dump_file(p,-1);
+                       dump_file(p,-1, 1);
                /* if(!f_dironly) { */
                        blank_name_list();
                        while(p=name_from_list()) {
@@ -169,7 +166,7 @@ create_archive()
                                for(q=gnu_list_name->dir_contents;q && *q;q+=strlen(q)+1) {
                                        if(*q=='Y') {
                                                strcpy(bufp,q+1);
-                                               dump_file(buf,-1);
+                                               dump_file(buf,-1, 1);
                                        }
                                }
                        }
@@ -177,15 +174,11 @@ create_archive()
                free(buf);
        } else {
                p = name_next(1);
-               if(!p)
-                       dump_file(".", -1);
-               else {
-                       do dump_file(p, -1);
-                       while (p = name_next(1));
-               }
+               do 
+                 dump_file(p, -1, 1);
+               while (p = name_next(1));
        }
 
-       write_mangled();
        write_eot();
        close_archive();
        if(f_gnudump)
@@ -199,9 +192,10 @@ create_archive()
  * Sets global "hstat" to stat() output for this file.
  */
 void
-dump_file (p, curdev)
+dump_file (p, curdev, toplevel)
        char    *p;                     /* File name to dump */
        int     curdev;                 /* Device our parent dir was on */
+       int     toplevel;               /* Whether we are a toplevel call */
 {
        union record    *header;
        char type;
@@ -211,6 +205,8 @@ dump_file (p, curdev)
        union record    *exhdr;
        char save_linkflag;
        extern time_t new_time;
+       int critical_error = 0;
+       time_t restore_times[2];
 /*     int sparse_ind = 0;*/
 
 
@@ -233,9 +229,13 @@ dump_file (p, curdev)
 badperror:
                msg_perror("can't add file %s",p);
 badfile:
-               errors++;
+               if (!f_ignore_failed_read || critical_error)
+                 errors++;
                return;
        }
+       
+       restore_times[0] = hstat.st_atime;
+       restore_times[1] = hstat.st_utime;
 
 #ifdef S_ISHIDDEN
        if (S_ISHIDDEN (hstat.st_mode)) {
@@ -301,7 +301,11 @@ badfile:
                                /* We found a link. */
                                hstat.st_size = 0;
                                header = start_header(p, &hstat);
-                               if (header == NULL) goto badfile;
+                               if (header == NULL) 
+                                 {
+                                   critical_error = 1;
+                                   goto badfile;
+                                 }
                                while(!f_absolute_paths && *link_name == '/') {
                                        static int link_warn = 0;
 
@@ -324,6 +328,11 @@ badfile:
                                header->header.linkflag = LF_LINK;
                                finish_header(header);
                /* FIXME: Maybe remove from list after all links found? */
+                               if (f_remove_files)
+                                 {
+                                   if (unlink (p) == -1)
+                                     msg_perror ("cannot remove %s", p);
+                                 }
                                return;         /* We dumped it */
                        }
                }
@@ -386,7 +395,10 @@ badfile:
                                
                                header = start_header(p, &hstat);
                                if (header == NULL)
-                                       goto badfile;
+                                 {
+                                   critical_error = 1;
+                                   goto badfile;
+                                 }
                                header->header.linkflag = LF_SPARSE;
                                header_moved++;
                                
@@ -462,6 +474,7 @@ badfile:
                        if (header == NULL) {
                                if(f>=0)
                                        (void)close(f);
+                               critical_error = 1;
                                goto badfile;
                        }
                }
@@ -483,7 +496,11 @@ badfile:
                        
        extend:         exhdr = findrec();
                        
-                       if (exhdr == NULL) goto badfile;
+                       if (exhdr == NULL) 
+                         {
+                           critical_error = 1;
+                           goto badfile;
+                         }
                        bzero(exhdr->charptr, RECORDSIZE);
                        for (i = 0; i < SPARSE_EXT_HDR; i++) {
                                if (i+index_offset > upperbound)
@@ -514,7 +531,7 @@ badfile:
                  while (sizeleft > 0) {
                        
                        if(f_multivol) {   
-                               save_name = header->header.name;
+                               save_name = p;
                                save_sizeleft = sizeleft;
                                save_totsize = hstat.st_size;
                        }
@@ -552,6 +569,13 @@ badfile:
                if (f >= 0)
                        (void)close(f);
 
+               if (f_remove_files)
+                 {
+                   if (unlink (p) == -1)
+                     msg_perror ("cannot remove %s", p);
+                 }
+               if (f_atime_preserve)
+                 utime (p, restore_times);
                return;
 
                /*
@@ -570,7 +594,9 @@ badfile:
                        save_name=0;
                if(f>=0)
                        (void)close(f);
-             return;
+               if (f_atime_preserve)
+                 utime (p, restore_times);
+               return;
        }
 
 #ifdef S_ISLNK
@@ -580,7 +606,11 @@ badfile:
 
                hstat.st_size = 0;              /* Force 0 size on symlink */
                header = start_header(p, &hstat);
-               if (header == NULL) goto badfile;
+               if (header == NULL) 
+                 {
+                   critical_error = 1;
+                   goto badfile;
+                 }
                size = readlink(p, header->header.linkname, NAMSIZ);
                if (size < 0) goto badperror;
                if (size == NAMSIZ) {
@@ -596,6 +626,11 @@ badfile:
                        header->header.linkname[size] = '\0';
                header->header.linkflag = LF_SYMLINK;
                finish_header(header);          /* Nothing more to do to it */
+               if (f_remove_files)
+                 {
+                   if (unlink (p) == -1)
+                     msg_perror ("cannot remove %s", p);
+                 }
                return;
        }
 #endif
@@ -635,7 +670,10 @@ badfile:
                         */
                        header = start_header(namebuf, &hstat);
                        if (header == NULL)
-                               goto badfile;   /* eg name too long */
+                         {
+                           critical_error = 1;
+                           goto badfile;       /* eg name too long */
+                         }
 
                        if (f_gnudump)
                                header->header.linkflag = LF_DUMPDIR;
@@ -690,6 +728,8 @@ badfile:
                        }
                        if(f_multivol)
                                save_name = 0;
+                       if (f_atime_preserve)
+                         utime (p, restore_times);
                        return;
                }
 
@@ -702,7 +742,7 @@ badfile:
                 * See if we are crossing from one file system to another,
                 * and avoid doing so if the user only wants to dump one file system.
                 */
-               if (f_local_filesys && curdev >= 0 && curdev != hstat.st_dev) {
+               if (f_local_filesys && !toplevel && curdev != hstat.st_dev) {
                        if(f_verbose)
                                msg("%s: is on a different filesystem; not dumped",p);
                        return;
@@ -742,11 +782,13 @@ badfile:
                        strcpy(namebuf+len, d->d_name);
                        if(f_exclude && check_exclude(namebuf))
                                continue;
-                       dump_file(namebuf, our_device);
+                       dump_file(namebuf, our_device, 0);
                }
 
                closedir(dirp);
                free(namebuf);
+               if (f_atime_preserve)
+                 utime (p, restore_times);
                return;
        }
 
@@ -781,7 +823,11 @@ badfile:
 
        hstat.st_size = 0;              /* Force 0 size */
        header = start_header(p, &hstat);
-       if (header == NULL) goto badfile;       /* eg name too long */
+       if (header == NULL) 
+         {
+           critical_error = 1;
+           goto badfile;       /* eg name too long */
+         }
 
        header->header.linkflag = type;
 #if defined(S_IFBLK) || defined(S_IFCHR)
@@ -794,6 +840,11 @@ badfile:
 #endif
 
        finish_header(header);
+       if (f_remove_files)
+         {
+           if (unlink (p) == -1)
+             msg_perror ("cannot remove %s", p);
+         }
        return;
 
        unknown:
@@ -879,7 +930,7 @@ finish_sparse_file(fd, sizeleft, fullsize, name)
 
        }
        free(sparsearray);
-       printf ("Amount actually written is (I hope) %d.\n", nwritten);
+/*     printf ("Amount actually written is (I hope) %d.\n", nwritten); */
 /*     userec(start+(count-1)/RECORDSIZE);*/
        return 0;
 
This page took 0.033304 seconds and 4 git commands to generate.