1 /* Extract files from a tar archive.
2 Copyright 1988, 92,93,94,96,97,98, 1999 Free Software Foundation, Inc.
3 Written by John Gilmore, on 1985-11-19.
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2, or (at your option) any later
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
34 static int we_are_root
; /* true if our effective uid == 0 */
35 static mode_t newdir_umask
; /* umask when creating new directories */
36 static mode_t current_umask
; /* current umask (which is set to 0 if -p) */
38 /* Status of the permissions of a file that we are extracting. */
41 /* This file may have existed already; its permissions are unknown. */
44 /* This file was created using the permissions from the archive. */
47 /* This is an intermediate directory; the archive did not specify
52 /* List of directories whose statuses we need to extract after we've
53 finished extracting their subsidiary files. The head of the list
54 has the longest name; each non-head element in the list is an
55 ancestor (in the directory hierarchy) of the preceding element. */
56 struct delayed_set_stat
58 struct delayed_set_stat
*next
;
59 struct stat stat_info
;
61 mode_t invert_permissions
;
62 enum permstatus permstatus
;
66 static struct delayed_set_stat
*delayed_set_stat_head
;
68 /*--------------------------.
69 | Set up to extract files. |
70 `--------------------------*/
75 we_are_root
= geteuid () == 0;
76 same_permissions_option
+= we_are_root
;
77 same_owner_option
+= we_are_root
;
78 xalloc_fail_func
= apply_delayed_set_stat
;
80 /* Option -p clears the kernel umask, so it does not affect proper
81 restoration of file permissions. New intermediate directories will
82 comply with umask at start of program. */
84 newdir_umask
= umask (0);
85 if (0 < same_permissions_option
)
89 umask (newdir_umask
); /* restore the kernel umask */
90 current_umask
= newdir_umask
;
94 /* If restoring permissions, restore the mode for FILE_NAME from
95 information given in *STAT_INFO; otherwise invert the
96 INVERT_PERMISSIONS bits from the file's current permissions.
97 PERMSTATUS specifies the status of the file's permissions.
98 TYPEFLAG specifies the type of the file. */
100 set_mode (char *file_name
, struct stat
*stat_info
,
101 mode_t invert_permissions
, enum permstatus permstatus
,
106 if (0 < same_permissions_option
107 && permstatus
!= INTERDIR_PERMSTATUS
)
109 mode
= stat_info
->st_mode
;
111 /* If we created the file and it has a usual mode, then its mode
112 is normally set correctly already. But on many hosts, some
113 directories inherit the setgid bits from their parents, so we
114 we must set directories' modes explicitly. */
115 if (permstatus
== ARCHIVED_PERMSTATUS
116 && ! (mode
& ~ MODE_RWX
)
117 && typeflag
!= DIRTYPE
118 && typeflag
!= GNUTYPE_DUMPDIR
)
121 else if (! invert_permissions
)
125 /* We must inspect a directory's current permissions, since the
126 directory may have inherited its setgid bit from its parent.
128 INVERT_PERMISSIONS happens to be nonzero only for directories
129 that we created, so there's no point optimizing this code for
132 if (stat (file_name
, &st
) != 0)
134 stat_error (file_name
);
137 mode
= st
.st_mode
^ invert_permissions
;
140 if (chmod (file_name
, mode
) != 0)
141 chmod_error_details (file_name
, mode
);
144 /* Restore stat attributes (owner, group, mode and times) for
145 FILE_NAME, using information given in *STAT_INFO.
146 If not restoring permissions, invert the
147 INVERT_PERMISSIONS bits from the file's current permissions.
148 PERMSTATUS specifies the status of the file's permissions.
149 TYPEFLAG specifies the type of the file. */
151 /* FIXME: About proper restoration of symbolic link attributes, we still do
152 not have it right. Pretesters' reports tell us we need further study and
153 probably more configuration. For now, just use lchown if it exists, and
154 punt for the rest. Sigh! */
157 set_stat (char *file_name
, struct stat
*stat_info
,
158 mode_t invert_permissions
, enum permstatus permstatus
,
161 struct utimbuf utimbuf
;
163 if (typeflag
!= SYMTYPE
)
165 /* We do the utime before the chmod because some versions of utime are
166 broken and trash the modes of the file. */
168 if (! touch_option
&& permstatus
!= INTERDIR_PERMSTATUS
)
170 /* We set the accessed time to `now', which is really the time we
171 started extracting files, unless incremental_option is used, in
172 which case .st_atime is used. */
174 /* FIXME: incremental_option should set ctime too, but how? */
176 if (incremental_option
)
177 utimbuf
.actime
= stat_info
->st_atime
;
179 utimbuf
.actime
= start_time
;
181 utimbuf
.modtime
= stat_info
->st_mtime
;
183 if (utime (file_name
, &utimbuf
) < 0)
184 utime_error (file_name
);
187 /* Some systems allow non-root users to give files away. Once this
188 done, it is not possible anymore to change file permissions, so we
189 have to set permissions prior to possibly giving files away. */
191 set_mode (file_name
, stat_info
,
192 invert_permissions
, permstatus
, typeflag
);
195 if (0 < same_owner_option
&& permstatus
!= INTERDIR_PERMSTATUS
)
197 /* When lchown exists, it should be used to change the attributes of
198 the symbolic link itself. In this case, a mere chown would change
199 the attributes of the file the symbolic link is pointing to, and
200 should be avoided. */
202 if (typeflag
== SYMTYPE
)
205 if (lchown (file_name
, stat_info
->st_uid
, stat_info
->st_gid
) < 0)
206 chown_error_details (file_name
,
207 stat_info
->st_uid
, stat_info
->st_gid
);
212 if (chown (file_name
, stat_info
->st_uid
, stat_info
->st_gid
) < 0)
213 chown_error_details (file_name
,
214 stat_info
->st_uid
, stat_info
->st_gid
);
216 /* On a few systems, and in particular, those allowing to give files
217 away, changing the owner or group destroys the suid or sgid bits.
218 So let's attempt setting these bits once more. */
219 if (stat_info
->st_mode
& (S_ISUID
| S_ISGID
| S_ISVTX
))
220 set_mode (file_name
, stat_info
,
221 invert_permissions
, permstatus
, typeflag
);
226 /* Remember to restore stat attributes (owner, group, mode and times)
227 for the directory FILE_NAME, using information given in *STAT_INFO,
228 once we stop extracting files into that directory.
229 If not restoring permissions, remember to invert the
230 INVERT_PERMISSIONS bits from the file's current permissions.
231 PERMSTATUS specifies the status of the file's permissions. */
233 delay_set_stat (char const *file_name
, struct stat
const *stat_info
,
234 mode_t invert_permissions
, enum permstatus permstatus
)
236 size_t file_name_len
= strlen (file_name
);
237 struct delayed_set_stat
*data
= xmalloc (sizeof *data
+ file_name_len
);
238 data
->file_name_len
= file_name_len
;
239 strcpy (data
->file_name
, file_name
);
240 data
->invert_permissions
= invert_permissions
;
241 data
->permstatus
= permstatus
;
242 data
->stat_info
= *stat_info
;
243 data
->next
= delayed_set_stat_head
;
244 delayed_set_stat_head
= data
;
247 /* Update the delayed_set_stat info for an intermediate directory
248 created on the path to DIR_NAME. The intermediate directory
249 turned out to be the same as this directory, due to ".." or
250 symbolic links. *DIR_STAT_INFO is the status of the directory. */
252 repair_delayed_set_stat (char const *dir_name
,
253 struct stat
const *dir_stat_info
)
255 struct delayed_set_stat
*data
;
256 for (data
= delayed_set_stat_head
; data
; data
= data
->next
)
259 if (stat (data
->file_name
, &st
) != 0)
261 stat_error (data
->file_name
);
265 if (st
.st_dev
== dir_stat_info
->st_dev
266 && st
.st_ino
== dir_stat_info
->st_ino
)
268 data
->stat_info
= current_stat
;
269 data
->invert_permissions
= (MODE_RWX
270 & (current_stat
.st_mode
^ st
.st_mode
));
271 data
->permstatus
= ARCHIVED_PERMSTATUS
;
276 ERROR ((0, 0, _("%s: Unexpected inconsistency when making directory"),
277 quotearg_colon (dir_name
)));
280 /*-----------------------------------------------------------------------.
281 | After a file/link/symlink/directory creation has failed, see if it's |
282 | because some required directory was not present, and if so, create all |
283 | required directories. Return non-zero if a directory was created. |
284 `-----------------------------------------------------------------------*/
287 make_directories (char *file_name
)
289 char *cursor
; /* points into path */
290 int did_something
= 0; /* did we do anything yet? */
291 int saved_errno
= errno
; /* remember caller's errno */
293 int invert_permissions
;
296 for (cursor
= strchr (file_name
, '/');
298 cursor
= strchr (cursor
+ 1, '/'))
300 /* Avoid mkdir of empty string, if leading or double '/'. */
302 if (cursor
== file_name
|| cursor
[-1] == '/')
305 /* Avoid mkdir where last part of path is "." or "..". */
307 if (cursor
[-1] == '.'
308 && (cursor
== file_name
+ 1 || cursor
[-2] == '/'
309 || (cursor
[-2] == '.'
310 && (cursor
== file_name
+ 2 || cursor
[-3] == '/'))))
313 *cursor
= '\0'; /* truncate the path there */
314 mode
= MODE_RWX
& ~ newdir_umask
;
315 invert_permissions
= we_are_root
? 0 : MODE_WXUSR
& ~ mode
;
316 status
= mkdir (file_name
, mode
^ invert_permissions
);
320 /* Create a struct delayed_set_stat even if
321 invert_permissions is zero, because
322 repair_delayed_set_stat may need to update the struct. */
323 delay_set_stat (file_name
,
324 ¤t_stat
/* ignored */,
325 invert_permissions
, INTERDIR_PERMSTATUS
);
327 print_for_mkdir (file_name
, cursor
- file_name
, mode
);
338 /* Turbo C mkdir gives a funny errno. */
342 /* Directory already exists. */
345 /* Some other error in the mkdir. We return to the caller. */
350 return did_something
; /* tell them to retry if we made one */
353 /* Prepare to extract a file.
354 Return zero if extraction should not proceed. */
357 prepare_to_extract (char const *file_name
)
359 if (to_stdout_option
)
362 if (old_files_option
== UNLINK_FIRST_OLD_FILES
363 && !remove_any_file (file_name
, recursive_unlink_option
)
364 && errno
&& errno
!= ENOENT
)
366 unlink_error (file_name
);
373 /*--------------------------------------------------------------------.
374 | Attempt repairing what went wrong with the extraction. Delete an |
375 | already existing file or create missing intermediate directories. |
376 | Return nonzero if we somewhat increased our chances at a successful |
377 | extraction. errno is properly restored on zero return. |
378 `--------------------------------------------------------------------*/
381 maybe_recoverable (char *file_name
, int *interdir_made
)
389 /* Remove an old file, if the options allow this. */
391 switch (old_files_option
)
396 case DEFAULT_OLD_FILES
:
397 case OVERWRITE_OLD_FILES
:
399 int r
= remove_any_file (file_name
, 0);
406 /* Attempt creating missing intermediate directories. */
407 if (! make_directories (file_name
))
413 /* Just say we can't do anything about it... */
424 extract_sparse_file (int fd
, off_t
*sizeleft
, off_t totalsize
, char *name
)
430 /* assuming sizeleft is initially totalsize */
432 while (*sizeleft
> 0)
434 union block
*data_block
= find_next_block ();
437 ERROR ((0, 0, _("Unexpected EOF in archive")));
440 if (lseek (fd
, sparsearray
[sparse_ind
].offset
, SEEK_SET
) < 0)
442 seek_error_details (name
, sparsearray
[sparse_ind
].offset
);
445 written
= sparsearray
[sparse_ind
++].numbytes
;
446 while (written
> BLOCKSIZE
)
448 count
= full_write (fd
, data_block
->buffer
, BLOCKSIZE
);
453 set_next_block_after (data_block
);
454 data_block
= find_next_block ();
457 ERROR ((0, 0, _("Unexpected EOF in archive")));
462 count
= full_write (fd
, data_block
->buffer
, written
);
466 else if (count
!= written
)
468 write_error_details (name
, count
, written
);
469 skip_file (*sizeleft
);
474 set_next_block_after (data_block
);
480 /*----------------------------------.
481 | Extract a file from the archive. |
482 `----------------------------------*/
485 extract_archive (void)
487 union block
*data_block
;
498 int interdir_made
= 0;
505 #define CURRENT_FILE_NAME (skipcrud + current_file_name)
507 set_next_block_after (current_header
);
508 decode_header (current_header
, ¤t_stat
, ¤t_format
, 1);
510 if (interactive_option
&& !confirm ("extract", current_file_name
))
512 if (current_header
->oldgnu_header
.isextended
)
513 skip_extended_headers ();
514 skip_file (current_stat
.st_size
);
518 /* Print the block from `current_header' and `current_stat'. */
523 /* Check for fully specified file names and other atrocities. */
526 if (! absolute_names_option
)
528 while (CURRENT_FILE_NAME
[0] == '/')
530 static int warned_once
;
535 WARN ((0, 0, _("Removing leading `/' from member names")));
537 skipcrud
++; /* force relative path */
540 if (contains_dot_dot (CURRENT_FILE_NAME
))
542 ERROR ((0, 0, _("%s: Member name contains `..'"),
543 quotearg_colon (CURRENT_FILE_NAME
)));
544 if (current_header
->oldgnu_header
.isextended
)
545 skip_extended_headers ();
546 skip_file (current_stat
.st_size
);
551 /* Take a safety backup of a previously existing file. */
553 if (backup_option
&& !to_stdout_option
)
554 if (!maybe_backup_file (CURRENT_FILE_NAME
, 0))
557 ERROR ((0, e
, _("%s: Was unable to backup this file"),
558 quotearg_colon (CURRENT_FILE_NAME
)));
559 if (current_header
->oldgnu_header
.isextended
)
560 skip_extended_headers ();
561 skip_file (current_stat
.st_size
);
565 /* Extract the archive entry according to its type. */
567 typeflag
= current_header
->header
.typeflag
;
570 /* JK - What we want to do if the file is sparse is loop through
571 the array of sparse structures in the header and read in and
572 translate the character strings representing 1) the offset at
573 which to write and 2) how many bytes to write into numbers,
574 which we store into the scratch array, "sparsearray". This
575 array makes our life easier the same way it did in creating the
576 tar file that had to deal with a sparse file.
578 After we read in the first five (at most) sparse structures, we
579 check to see if the file has an extended header, i.e., if more
580 sparse structures are needed to describe the contents of the new
581 file. If so, we read in the extended headers and continue to
582 store their contents into the sparsearray. */
587 xmalloc (sp_array_size
* sizeof (struct sp_array
));
589 for (counter
= 0; counter
< SPARSES_IN_OLDGNU_HEADER
; counter
++)
591 struct sparse
const *s
= ¤t_header
->oldgnu_header
.sp
[counter
];
592 sparsearray
[counter
].offset
= OFF_FROM_HEADER (s
->offset
);
593 sparsearray
[counter
].numbytes
= SIZE_FROM_HEADER (s
->numbytes
);
594 if (!sparsearray
[counter
].numbytes
)
598 if (current_header
->oldgnu_header
.isextended
)
600 /* Read in the list of extended headers and translate them
601 into the sparsearray as before. Note that this
602 invalidates current_header. */
604 /* static */ int ind
= SPARSES_IN_OLDGNU_HEADER
;
608 exhdr
= find_next_block ();
611 ERROR ((0, 0, _("Unexpected EOF in archive")));
614 for (counter
= 0; counter
< SPARSES_IN_SPARSE_HEADER
; counter
++)
616 struct sparse
const *s
= &exhdr
->sparse_header
.sp
[counter
];
617 if (counter
+ ind
> sp_array_size
- 1)
619 /* Realloc the scratch area since we've run out of
624 xrealloc (sparsearray
,
625 sp_array_size
* sizeof (struct sp_array
));
627 if (s
->numbytes
[0] == 0)
629 sparsearray
[counter
+ ind
].offset
=
630 OFF_FROM_HEADER (s
->offset
);
631 sparsearray
[counter
+ ind
].numbytes
=
632 SIZE_FROM_HEADER (s
->numbytes
);
634 if (!exhdr
->sparse_header
.isextended
)
638 ind
+= SPARSES_IN_SPARSE_HEADER
;
639 set_next_block_after (exhdr
);
642 set_next_block_after (exhdr
);
650 /* Appears to be a file. But BSD tar uses the convention that a slash
651 suffix means a directory. */
653 name_length
= strlen (CURRENT_FILE_NAME
);
654 if (name_length
&& CURRENT_FILE_NAME
[name_length
- 1] == '/')
657 /* FIXME: deal with protection issues. */
660 openflag
= (O_WRONLY
| O_BINARY
| O_CREAT
661 | (old_files_option
== OVERWRITE_OLD_FILES
664 mode
= current_stat
.st_mode
& MODE_RWX
& ~ current_umask
;
666 if (to_stdout_option
)
672 if (! prepare_to_extract (CURRENT_FILE_NAME
))
674 if (current_header
->oldgnu_header
.isextended
)
675 skip_extended_headers ();
676 skip_file (current_stat
.st_size
);
683 /* Contiguous files (on the Masscomp) have to specify the size in
684 the open call that creates them. */
686 if (typeflag
== CONTTYPE
)
687 fd
= open (CURRENT_FILE_NAME
, openflag
| O_CTG
,
688 mode
, current_stat
.st_size
);
690 fd
= open (CURRENT_FILE_NAME
, openflag
, mode
);
692 #else /* not O_CTG */
693 if (typeflag
== CONTTYPE
)
695 static int conttype_diagnosed
;
697 if (!conttype_diagnosed
)
699 conttype_diagnosed
= 1;
700 WARN ((0, 0, _("Extracting contiguous files as regular files")));
703 fd
= open (CURRENT_FILE_NAME
, openflag
, mode
);
705 #endif /* not O_CTG */
709 if (maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
712 open_error (CURRENT_FILE_NAME
);
713 if (current_header
->oldgnu_header
.isextended
)
714 skip_extended_headers ();
715 skip_file (current_stat
.st_size
);
722 if (typeflag
== GNUTYPE_SPARSE
)
725 size_t name_length_bis
;
727 /* Kludge alert. NAME is assigned to header.name because
728 during the extraction, the space that contains the header
729 will get scribbled on, and the name will get munged, so any
730 error messages that happen to contain the filename will look
731 REAL interesting unless we do this. */
733 name_length_bis
= strlen (CURRENT_FILE_NAME
) + 1;
734 name
= xmalloc (name_length_bis
);
735 memcpy (name
, CURRENT_FILE_NAME
, name_length_bis
);
736 size
= current_stat
.st_size
;
737 extract_sparse_file (fd
, &size
, current_stat
.st_size
, name
);
740 for (size
= current_stat
.st_size
;
744 if (multi_volume_option
)
746 assign_string (&save_name
, current_file_name
);
747 save_totsize
= current_stat
.st_size
;
748 save_sizeleft
= size
;
751 /* Locate data, determine max length writeable, write it,
752 block that we have used the data, then check if the write
755 data_block
= find_next_block ();
758 ERROR ((0, 0, _("Unexpected EOF in archive")));
759 break; /* FIXME: What happens, then? */
762 written
= available_space_after (data_block
);
767 sstatus
= full_write (fd
, data_block
->buffer
, written
);
769 set_next_block_after ((union block
*)
770 (data_block
->buffer
+ written
- 1));
771 if (sstatus
== written
)
774 /* Error in writing to file. Print it, skip to next file in
777 write_error_details (CURRENT_FILE_NAME
, sstatus
, written
);
778 skip_file (size
- written
);
779 break; /* still do the close, mod time, chmod, etc */
782 if (multi_volume_option
)
783 assign_string (&save_name
, 0);
785 /* If writing to stdout, don't try to do anything to the filename;
786 it doesn't exist, or we don't want to touch it anyway. */
788 if (to_stdout_option
)
794 close_error (CURRENT_FILE_NAME
);
799 set_stat (CURRENT_FILE_NAME
, ¤t_stat
, 0,
800 (old_files_option
== OVERWRITE_OLD_FILES
802 : ARCHIVED_PERMSTATUS
),
808 if (! prepare_to_extract (CURRENT_FILE_NAME
))
811 while (status
= symlink (current_link_name
, CURRENT_FILE_NAME
),
813 if (!maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
818 /* Setting the attributes of symbolic links might, on some systems,
819 change the pointed to file, instead of the symbolic link itself.
820 At least some of these systems have a lchown call, and the
821 set_stat routine knows about this. */
823 set_stat (CURRENT_FILE_NAME
, ¤t_stat
, 0,
824 ARCHIVED_PERMSTATUS
, typeflag
);
829 ERROR ((0, e
, _("%s: Cannot create symlink to %s"),
830 quotearg_colon (CURRENT_FILE_NAME
),
831 quote (current_link_name
)));
839 static int warned_once
;
845 _("Attempting extraction of symbolic links as hard links")));
853 if (! prepare_to_extract (CURRENT_FILE_NAME
))
858 struct stat st1
, st2
;
861 /* MSDOS does not implement links. However, djgpp's link() actually
863 status
= link (current_link_name
, CURRENT_FILE_NAME
);
867 if (maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
870 if (incremental_option
&& errno
== EEXIST
)
873 if (stat (current_link_name
, &st1
) == 0
874 && stat (CURRENT_FILE_NAME
, &st2
) == 0
875 && st1
.st_dev
== st2
.st_dev
876 && st1
.st_ino
== st2
.st_ino
)
879 ERROR ((0, e
, _("%s: Cannot link to %s"),
880 quotearg_colon (CURRENT_FILE_NAME
),
881 quote (current_link_name
)));
889 current_stat
.st_mode
|= S_IFCHR
;
895 current_stat
.st_mode
|= S_IFBLK
;
898 #if S_IFCHR || S_IFBLK
900 if (! prepare_to_extract (CURRENT_FILE_NAME
))
903 status
= mknod (CURRENT_FILE_NAME
, current_stat
.st_mode
,
904 current_stat
.st_rdev
);
907 if (maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
909 mknod_error (CURRENT_FILE_NAME
);
914 set_stat (CURRENT_FILE_NAME
, ¤t_stat
, 0,
915 ARCHIVED_PERMSTATUS
, typeflag
);
919 #if HAVE_MKFIFO || defined mkfifo
921 if (! prepare_to_extract (CURRENT_FILE_NAME
))
924 while (status
= mkfifo (CURRENT_FILE_NAME
, current_stat
.st_mode
),
926 if (!maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
930 set_stat (CURRENT_FILE_NAME
, ¤t_stat
, 0,
931 ARCHIVED_PERMSTATUS
, typeflag
);
934 mkfifo_error (CURRENT_FILE_NAME
);
942 case GNUTYPE_DUMPDIR
:
943 name_length
= strlen (CURRENT_FILE_NAME
);
946 /* Remove trailing "/" and "/.", unless that would result in the
950 if (1 < name_length
&& CURRENT_FILE_NAME
[name_length
- 1] == '/')
951 CURRENT_FILE_NAME
[--name_length
] = '\0';
952 else if (2 < name_length
953 && CURRENT_FILE_NAME
[name_length
- 1] == '.'
954 && CURRENT_FILE_NAME
[name_length
- 2] == '/')
955 CURRENT_FILE_NAME
[name_length
-= 2] = '\0';
960 if (incremental_option
)
962 /* Read the entry and delete files that aren't listed in the
965 gnu_restore (skipcrud
);
967 else if (typeflag
== GNUTYPE_DUMPDIR
)
968 skip_file (current_stat
.st_size
);
970 if (! prepare_to_extract (CURRENT_FILE_NAME
))
973 mode
= ((current_stat
.st_mode
974 | (we_are_root
? 0 : MODE_WXUSR
))
978 status
= mkdir (CURRENT_FILE_NAME
, mode
);
981 if (errno
== EEXIST
&& interdir_made
982 && contains_dot_dot (CURRENT_FILE_NAME
))
986 if (stat (CURRENT_FILE_NAME
, &st
) == 0)
988 repair_delayed_set_stat (CURRENT_FILE_NAME
, &st
);
994 if (maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
997 if (errno
!= EEXIST
|| old_files_option
== KEEP_OLD_FILES
)
999 mkdir_error (CURRENT_FILE_NAME
);
1001 undo_last_backup ();
1007 || old_files_option
== OVERWRITE_OLD_FILES
)
1008 delay_set_stat (CURRENT_FILE_NAME
, ¤t_stat
,
1009 mode
& ~ current_stat
.st_mode
,
1011 ? ARCHIVED_PERMSTATUS
1012 : UNKNOWN_PERMSTATUS
));
1015 case GNUTYPE_VOLHDR
:
1017 fprintf (stdlis
, _("Reading %s\n"), quote (current_file_name
));
1024 case GNUTYPE_MULTIVOL
:
1026 _("%s: Cannot extract -- file is continued from another volume"),
1027 quotearg_colon (current_file_name
)));
1028 skip_file (current_stat
.st_size
);
1030 undo_last_backup ();
1033 case GNUTYPE_LONGNAME
:
1034 case GNUTYPE_LONGLINK
:
1035 ERROR ((0, 0, _("Visible long name error")));
1036 skip_file (current_stat
.st_size
);
1038 undo_last_backup ();
1043 _("%s: Unknown file type '%c', extracted as normal file"),
1044 quotearg_colon (CURRENT_FILE_NAME
), typeflag
));
1048 #undef CURRENT_FILE_NAME
1051 /* Fix the status of all directories whose statuses need fixing. */
1053 apply_delayed_set_stat (void)
1055 apply_nonancestor_delayed_set_stat ("");
1058 /* Fix the statuses of all directories whose statuses need fixing, and
1059 which are not ancestors of FILE_NAME. */
1061 apply_nonancestor_delayed_set_stat (char const *file_name
)
1063 size_t file_name_len
= strlen (file_name
);
1065 while (delayed_set_stat_head
)
1067 struct delayed_set_stat
*data
= delayed_set_stat_head
;
1068 if (data
->file_name_len
< file_name_len
1069 && file_name
[data
->file_name_len
] == '/'
1070 && memcmp (file_name
, data
->file_name
, data
->file_name_len
) == 0)
1072 delayed_set_stat_head
= data
->next
;
1073 set_stat (data
->file_name
, &data
->stat_info
,
1074 data
->invert_permissions
, data
->permstatus
, DIRTYPE
);
1082 apply_delayed_set_stat ();
1083 error (TAREXIT_FAILURE
, 0, _("Error is not recoverable: exiting now"));