]> Dogcows Code - chaz/tar/commitdiff
Initial revision
authorFrançois Pinard <pinard@iro.umontreal.ca>
Wed, 16 Nov 1994 02:42:25 +0000 (02:42 +0000)
committerFrançois Pinard <pinard@iro.umontreal.ca>
Wed, 16 Nov 1994 02:42:25 +0000 (02:42 +0000)
src/create.c

index 5d09f35ed15baf22695f86d9013265e48b511052..c2453409efb076499aea266c67ff7121d5182d19 100644 (file)
@@ -1,5 +1,5 @@
 /* Create a tar archive.
-   Copyright (C) 1985, 1992 Free Software Foundation
+   Copyright (C) 1988 Free Software Foundation
 
 This file is part of GNU Tar.
 
@@ -33,6 +33,9 @@ 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
@@ -41,9 +44,6 @@ extern int    errno;
 #endif
 #endif
 
-#include "tar.h"
-#include "port.h"
-
 #ifndef        __MSDOS__
 #include <pwd.h>
 #include <grp.h>
@@ -152,13 +152,13 @@ create_archive()
        open_archive(0);                /* Open for writing */
 
        if(f_gnudump) {
-               char *buf = ck_malloc(PATH_MAX);
+               char *buf = ck_malloc(NAME_MAX);
                char *q,*bufp;
 
                collect_and_sort_names();
 
                while(p=name_from_list())
-                       dump_file(p,-1, 1);
+                       dump_file(p,-1);
                /* if(!f_dironly) { */
                        blank_name_list();
                        while(p=name_from_list()) {
@@ -169,7 +169,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, 1);
+                                               dump_file(buf,-1);
                                        }
                                }
                        }
@@ -178,9 +178,9 @@ create_archive()
        } else {
                p = name_next(1);
                if(!p)
-                       dump_file(".", -1, 1);
+                       dump_file(".", -1);
                else {
-                       do dump_file(p, -1, 1);
+                       do dump_file(p, -1);
                        while (p = name_next(1));
                }
        }
@@ -199,10 +199,9 @@ create_archive()
  * Sets global "hstat" to stat() output for this file.
  */
 void
-dump_file (p, curdev, toplevel)
+dump_file (p, curdev)
        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;
@@ -212,7 +211,6 @@ dump_file (p, curdev, toplevel)
        union record    *exhdr;
        char save_linkflag;
        extern time_t new_time;
-       int critical_error = 0;
 /*     int sparse_ind = 0;*/
 
 
@@ -235,8 +233,7 @@ dump_file (p, curdev, toplevel)
 badperror:
                msg_perror("can't add file %s",p);
 badfile:
-               if (!f_ignore_failed_read || critical_error)
-                 errors++;
+               errors++;
                return;
        }
 
@@ -304,11 +301,7 @@ badfile:
                                /* We found a link. */
                                hstat.st_size = 0;
                                header = start_header(p, &hstat);
-                               if (header == NULL) 
-                                 {
-                                   critical_error = 1;
-                                   goto badfile;
-                                 }
+                               if (header == NULL) goto badfile;
                                while(!f_absolute_paths && *link_name == '/') {
                                        static int link_warn = 0;
 
@@ -331,11 +324,6 @@ 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 */
                        }
                }
@@ -398,10 +386,7 @@ badfile:
                                
                                header = start_header(p, &hstat);
                                if (header == NULL)
-                                 {
-                                   critical_error = 1;
-                                   goto badfile;
-                                 }
+                                       goto badfile;
                                header->header.linkflag = LF_SPARSE;
                                header_moved++;
                                
@@ -477,7 +462,6 @@ badfile:
                        if (header == NULL) {
                                if(f>=0)
                                        (void)close(f);
-                               critical_error = 1;
                                goto badfile;
                        }
                }
@@ -499,11 +483,7 @@ badfile:
                        
        extend:         exhdr = findrec();
                        
-                       if (exhdr == NULL) 
-                         {
-                           critical_error = 1;
-                           goto badfile;
-                         }
+                       if (exhdr == NULL) goto badfile;
                        bzero(exhdr->charptr, RECORDSIZE);
                        for (i = 0; i < SPARSE_EXT_HDR; i++) {
                                if (i+index_offset > upperbound)
@@ -534,7 +514,7 @@ badfile:
                  while (sizeleft > 0) {
                        
                        if(f_multivol) {   
-                               save_name = p;
+                               save_name = header->header.name;
                                save_sizeleft = sizeleft;
                                save_totsize = hstat.st_size;
                        }
@@ -572,11 +552,6 @@ badfile:
                if (f >= 0)
                        (void)close(f);
 
-               if (f_remove_files)
-                 {
-                   if (unlink (p) == -1)
-                     msg_perror ("cannot remove %s", p);
-                 }
                return;
 
                /*
@@ -605,11 +580,7 @@ badfile:
 
                hstat.st_size = 0;              /* Force 0 size on symlink */
                header = start_header(p, &hstat);
-               if (header == NULL) 
-                 {
-                   critical_error = 1;
-                   goto badfile;
-                 }
+               if (header == NULL) goto badfile;
                size = readlink(p, header->header.linkname, NAMSIZ);
                if (size < 0) goto badperror;
                if (size == NAMSIZ) {
@@ -625,11 +596,6 @@ 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
@@ -669,10 +635,7 @@ badfile:
                         */
                        header = start_header(namebuf, &hstat);
                        if (header == NULL)
-                         {
-                           critical_error = 1;
-                           goto badfile;       /* eg name too long */
-                         }
+                               goto badfile;   /* eg name too long */
 
                        if (f_gnudump)
                                header->header.linkflag = LF_DUMPDIR;
@@ -739,7 +702,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 && toplevel && curdev != hstat.st_dev) {
+               if (f_local_filesys && curdev >= 0 && curdev != hstat.st_dev) {
                        if(f_verbose)
                                msg("%s: is on a different filesystem; not dumped",p);
                        return;
@@ -779,7 +742,7 @@ badfile:
                        strcpy(namebuf+len, d->d_name);
                        if(f_exclude && check_exclude(namebuf))
                                continue;
-                       dump_file(namebuf, our_device, 0);
+                       dump_file(namebuf, our_device);
                }
 
                closedir(dirp);
@@ -818,11 +781,7 @@ badfile:
 
        hstat.st_size = 0;              /* Force 0 size */
        header = start_header(p, &hstat);
-       if (header == NULL) 
-         {
-           critical_error = 1;
-           goto badfile;       /* eg name too long */
-         }
+       if (header == NULL) goto badfile;       /* eg name too long */
 
        header->header.linkflag = type;
 #if defined(S_IFBLK) || defined(S_IFCHR)
@@ -835,11 +794,6 @@ badfile:
 #endif
 
        finish_header(header);
-       if (f_remove_files)
-         {
-           if (unlink (p) == -1)
-             msg_perror ("cannot remove %s", p);
-         }
        return;
 
        unknown:
@@ -925,7 +879,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.030474 seconds and 4 git commands to generate.