1 /* Extract files from a tar archive.
2 Copyright 1988, 92,93,94,96,97,98,99, 2000 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 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 /* List of symbolic links whose creation we have delayed. */
69 struct delayed_symlink
71 /* The next delayed symbolic link in the list. */
72 struct delayed_symlink
*next
;
74 /* The device, inode number and last-modified time of the
75 placeholder symbolic link. */
80 /* The desired owner and group of the symbolic link. */
84 /* The location and desired target of the desired link, as two
85 adjacent character strings, both null-terminated. */
89 static struct delayed_symlink
*delayed_symlink_head
;
91 /* Set up to extract files. */
95 we_are_root
= geteuid () == 0;
96 same_permissions_option
+= we_are_root
;
97 same_owner_option
+= we_are_root
;
98 xalloc_fail_func
= extract_finish
;
100 /* Option -p clears the kernel umask, so it does not affect proper
101 restoration of file permissions. New intermediate directories will
102 comply with umask at start of program. */
104 newdir_umask
= umask (0);
105 if (0 < same_permissions_option
)
109 umask (newdir_umask
); /* restore the kernel umask */
110 current_umask
= newdir_umask
;
114 /* If restoring permissions, restore the mode for FILE_NAME from
115 information given in *STAT_INFO; otherwise invert the
116 INVERT_PERMISSIONS bits from the file's current permissions.
117 PERMSTATUS specifies the status of the file's permissions.
118 TYPEFLAG specifies the type of the file. */
120 set_mode (char const *file_name
, struct stat
const *stat_info
,
121 mode_t invert_permissions
, enum permstatus permstatus
,
126 if (0 < same_permissions_option
127 && permstatus
!= INTERDIR_PERMSTATUS
)
129 mode
= stat_info
->st_mode
;
131 /* If we created the file and it has a usual mode, then its mode
132 is normally set correctly already. But on many hosts, some
133 directories inherit the setgid bits from their parents, so we
134 we must set directories' modes explicitly. */
135 if (permstatus
== ARCHIVED_PERMSTATUS
136 && ! (mode
& ~ MODE_RWX
)
137 && typeflag
!= DIRTYPE
138 && typeflag
!= GNUTYPE_DUMPDIR
)
141 else if (! invert_permissions
)
145 /* We must inspect a directory's current permissions, since the
146 directory may have inherited its setgid bit from its parent.
148 INVERT_PERMISSIONS happens to be nonzero only for directories
149 that we created, so there's no point optimizing this code for
152 if (stat (file_name
, &st
) != 0)
154 stat_error (file_name
);
157 mode
= st
.st_mode
^ invert_permissions
;
160 if (chmod (file_name
, mode
) != 0)
161 chmod_error_details (file_name
, mode
);
164 /* Check time after successfully setting FILE_NAME's time stamp to T. */
166 check_time (char const *file_name
, time_t t
)
169 if (start_time
< t
&& (now
= time (0)) < t
)
170 WARN ((0, 0, _("%s: time stamp %s is %lu s in the future"),
171 file_name
, tartime (t
), (unsigned long) (t
- now
)));
174 /* Restore stat attributes (owner, group, mode and times) for
175 FILE_NAME, using information given in *STAT_INFO.
176 If not restoring permissions, invert the
177 INVERT_PERMISSIONS bits from the file's current permissions.
178 PERMSTATUS specifies the status of the file's permissions.
179 TYPEFLAG specifies the type of the file. */
181 /* FIXME: About proper restoration of symbolic link attributes, we still do
182 not have it right. Pretesters' reports tell us we need further study and
183 probably more configuration. For now, just use lchown if it exists, and
184 punt for the rest. Sigh! */
187 set_stat (char const *file_name
, struct stat
const *stat_info
,
188 mode_t invert_permissions
, enum permstatus permstatus
,
191 struct utimbuf utimbuf
;
193 if (typeflag
!= SYMTYPE
)
195 /* We do the utime before the chmod because some versions of utime are
196 broken and trash the modes of the file. */
198 if (! touch_option
&& permstatus
!= INTERDIR_PERMSTATUS
)
200 /* We set the accessed time to `now', which is really the time we
201 started extracting files, unless incremental_option is used, in
202 which case .st_atime is used. */
204 /* FIXME: incremental_option should set ctime too, but how? */
206 if (incremental_option
)
207 utimbuf
.actime
= stat_info
->st_atime
;
209 utimbuf
.actime
= start_time
;
211 utimbuf
.modtime
= stat_info
->st_mtime
;
213 if (utime (file_name
, &utimbuf
) < 0)
214 utime_error (file_name
);
217 check_time (file_name
, stat_info
->st_atime
);
218 check_time (file_name
, stat_info
->st_mtime
);
222 /* Some systems allow non-root users to give files away. Once this
223 done, it is not possible anymore to change file permissions, so we
224 have to set permissions prior to possibly giving files away. */
226 set_mode (file_name
, stat_info
,
227 invert_permissions
, permstatus
, typeflag
);
230 if (0 < same_owner_option
&& permstatus
!= INTERDIR_PERMSTATUS
)
232 /* When lchown exists, it should be used to change the attributes of
233 the symbolic link itself. In this case, a mere chown would change
234 the attributes of the file the symbolic link is pointing to, and
235 should be avoided. */
237 if (typeflag
== SYMTYPE
)
240 if (lchown (file_name
, stat_info
->st_uid
, stat_info
->st_gid
) < 0)
241 chown_error_details (file_name
,
242 stat_info
->st_uid
, stat_info
->st_gid
);
247 if (chown (file_name
, stat_info
->st_uid
, stat_info
->st_gid
) < 0)
248 chown_error_details (file_name
,
249 stat_info
->st_uid
, stat_info
->st_gid
);
251 /* On a few systems, and in particular, those allowing to give files
252 away, changing the owner or group destroys the suid or sgid bits.
253 So let's attempt setting these bits once more. */
254 if (stat_info
->st_mode
& (S_ISUID
| S_ISGID
| S_ISVTX
))
255 set_mode (file_name
, stat_info
,
256 invert_permissions
, permstatus
, typeflag
);
261 /* Remember to restore stat attributes (owner, group, mode and times)
262 for the directory FILE_NAME, using information given in *STAT_INFO,
263 once we stop extracting files into that directory.
264 If not restoring permissions, remember to invert the
265 INVERT_PERMISSIONS bits from the file's current permissions.
266 PERMSTATUS specifies the status of the file's permissions. */
268 delay_set_stat (char const *file_name
, struct stat
const *stat_info
,
269 mode_t invert_permissions
, enum permstatus permstatus
)
271 size_t file_name_len
= strlen (file_name
);
272 struct delayed_set_stat
*data
= xmalloc (sizeof *data
+ file_name_len
);
273 data
->file_name_len
= file_name_len
;
274 strcpy (data
->file_name
, file_name
);
275 data
->invert_permissions
= invert_permissions
;
276 data
->permstatus
= permstatus
;
277 data
->stat_info
= *stat_info
;
278 data
->next
= delayed_set_stat_head
;
279 delayed_set_stat_head
= data
;
282 /* Update the delayed_set_stat info for an intermediate directory
283 created on the path to DIR_NAME. The intermediate directory turned
284 out to be the same as this directory, e.g. due trailing slash or
285 ".." or symbolic links. *DIR_STAT_INFO is the status of the
288 repair_delayed_set_stat (char const *dir_name
,
289 struct stat
const *dir_stat_info
)
291 struct delayed_set_stat
*data
;
292 for (data
= delayed_set_stat_head
; data
; data
= data
->next
)
295 if (stat (data
->file_name
, &st
) != 0)
297 stat_error (data
->file_name
);
301 if (st
.st_dev
== dir_stat_info
->st_dev
302 && st
.st_ino
== dir_stat_info
->st_ino
)
304 data
->stat_info
= current_stat
;
305 data
->invert_permissions
= (MODE_RWX
306 & (current_stat
.st_mode
^ st
.st_mode
));
307 data
->permstatus
= ARCHIVED_PERMSTATUS
;
312 ERROR ((0, 0, _("%s: Unexpected inconsistency when making directory"),
313 quotearg_colon (dir_name
)));
316 /* After a file/link/symlink/directory creation has failed, see if
317 it's because some required directory was not present, and if so,
318 create all required directories. Return non-zero if a directory
321 make_directories (char *file_name
)
323 char *cursor
; /* points into path */
324 int did_something
= 0; /* did we do anything yet? */
326 int invert_permissions
;
329 for (cursor
= strchr (file_name
, '/');
331 cursor
= strchr (cursor
+ 1, '/'))
333 /* Avoid mkdir of empty string, if leading or double '/'. */
335 if (cursor
== file_name
|| cursor
[-1] == '/')
338 /* Avoid mkdir where last part of path is "." or "..". */
340 if (cursor
[-1] == '.'
341 && (cursor
== file_name
+ 1 || cursor
[-2] == '/'
342 || (cursor
[-2] == '.'
343 && (cursor
== file_name
+ 2 || cursor
[-3] == '/'))))
346 *cursor
= '\0'; /* truncate the path there */
347 mode
= MODE_RWX
& ~ newdir_umask
;
348 invert_permissions
= we_are_root
? 0 : MODE_WXUSR
& ~ mode
;
349 status
= mkdir (file_name
, mode
^ invert_permissions
);
353 /* Create a struct delayed_set_stat even if
354 invert_permissions is zero, because
355 repair_delayed_set_stat may need to update the struct. */
356 delay_set_stat (file_name
,
357 ¤t_stat
/* ignored */,
358 invert_permissions
, INTERDIR_PERMSTATUS
);
360 print_for_mkdir (file_name
, cursor
- file_name
, mode
);
371 /* Turbo C mkdir gives a funny errno. */
375 /* Directory already exists. */
378 /* Some other error in the mkdir. We return to the caller. */
382 return did_something
; /* tell them to retry if we made one */
385 /* Prepare to extract a file.
386 Return zero if extraction should not proceed. */
389 prepare_to_extract (char const *file_name
)
391 if (to_stdout_option
)
394 if (old_files_option
== UNLINK_FIRST_OLD_FILES
395 && !remove_any_file (file_name
, recursive_unlink_option
)
396 && errno
&& errno
!= ENOENT
)
398 unlink_error (file_name
);
405 /* Attempt repairing what went wrong with the extraction. Delete an
406 already existing file or create missing intermediate directories.
407 Return nonzero if we somewhat increased our chances at a successful
408 extraction. errno is properly restored on zero return. */
410 maybe_recoverable (char *file_name
, int *interdir_made
)
418 /* Remove an old file, if the options allow this. */
420 switch (old_files_option
)
425 case DEFAULT_OLD_FILES
:
426 case OVERWRITE_OLD_FILES
:
428 int r
= remove_any_file (file_name
, 0);
435 /* Attempt creating missing intermediate directories. */
436 if (! make_directories (file_name
))
445 /* Just say we can't do anything about it... */
452 extract_sparse_file (int fd
, off_t
*sizeleft
, off_t totalsize
, char *name
)
458 /* assuming sizeleft is initially totalsize */
460 while (*sizeleft
> 0)
462 union block
*data_block
= find_next_block ();
465 ERROR ((0, 0, _("Unexpected EOF in archive")));
468 if (lseek (fd
, sparsearray
[sparse_ind
].offset
, SEEK_SET
) < 0)
470 seek_error_details (name
, sparsearray
[sparse_ind
].offset
);
473 written
= sparsearray
[sparse_ind
++].numbytes
;
474 while (written
> BLOCKSIZE
)
476 count
= full_write (fd
, data_block
->buffer
, BLOCKSIZE
);
481 set_next_block_after (data_block
);
482 data_block
= find_next_block ();
485 ERROR ((0, 0, _("Unexpected EOF in archive")));
490 count
= full_write (fd
, data_block
->buffer
, written
);
494 else if (count
!= written
)
496 write_error_details (name
, count
, written
);
497 skip_file (*sizeleft
);
502 set_next_block_after (data_block
);
508 /* Fix the statuses of all directories whose statuses need fixing, and
509 which are not ancestors of FILE_NAME. */
511 apply_nonancestor_delayed_set_stat (char const *file_name
)
513 size_t file_name_len
= strlen (file_name
);
515 while (delayed_set_stat_head
)
517 struct delayed_set_stat
*data
= delayed_set_stat_head
;
518 if (data
->file_name_len
< file_name_len
519 && file_name
[data
->file_name_len
]
520 && (file_name
[data
->file_name_len
] == '/'
521 || file_name
[data
->file_name_len
- 1] == '/')
522 && memcmp (file_name
, data
->file_name
, data
->file_name_len
) == 0)
524 delayed_set_stat_head
= data
->next
;
525 set_stat (data
->file_name
, &data
->stat_info
,
526 data
->invert_permissions
, data
->permstatus
, DIRTYPE
);
531 /* Extract a file from the archive. */
533 extract_archive (void)
535 union block
*data_block
;
546 int interdir_made
= 0;
550 #define CURRENT_FILE_NAME (skipcrud + current_file_name)
552 set_next_block_after (current_header
);
553 decode_header (current_header
, ¤t_stat
, ¤t_format
, 1);
555 if (interactive_option
&& !confirm ("extract", current_file_name
))
561 /* Print the block from current_header and current_stat. */
566 /* Check for fully specified file names and other atrocities. */
569 if (! absolute_names_option
)
571 while (CURRENT_FILE_NAME
[0] == '/')
573 static int warned_once
;
578 WARN ((0, 0, _("Removing leading `/' from member names")));
580 skipcrud
++; /* force relative path */
583 if (contains_dot_dot (CURRENT_FILE_NAME
))
585 ERROR ((0, 0, _("%s: Member name contains `..'"),
586 quotearg_colon (CURRENT_FILE_NAME
)));
592 apply_nonancestor_delayed_set_stat (CURRENT_FILE_NAME
);
594 /* Take a safety backup of a previously existing file. */
596 if (backup_option
&& !to_stdout_option
)
597 if (!maybe_backup_file (CURRENT_FILE_NAME
, 0))
600 ERROR ((0, e
, _("%s: Was unable to backup this file"),
601 quotearg_colon (CURRENT_FILE_NAME
)));
606 /* Extract the archive entry according to its type. */
608 typeflag
= current_header
->header
.typeflag
;
611 /* JK - What we want to do if the file is sparse is loop through
612 the array of sparse structures in the header and read in and
613 translate the character strings representing 1) the offset at
614 which to write and 2) how many bytes to write into numbers,
615 which we store into the scratch array, "sparsearray". This
616 array makes our life easier the same way it did in creating the
617 tar file that had to deal with a sparse file.
619 After we read in the first five (at most) sparse structures, we
620 check to see if the file has an extended header, i.e., if more
621 sparse structures are needed to describe the contents of the new
622 file. If so, we read in the extended headers and continue to
623 store their contents into the sparsearray. */
628 xmalloc (sp_array_size
* sizeof (struct sp_array
));
630 for (counter
= 0; counter
< SPARSES_IN_OLDGNU_HEADER
; counter
++)
632 struct sparse
const *s
= ¤t_header
->oldgnu_header
.sp
[counter
];
633 sparsearray
[counter
].offset
= OFF_FROM_HEADER (s
->offset
);
634 sparsearray
[counter
].numbytes
= SIZE_FROM_HEADER (s
->numbytes
);
635 if (!sparsearray
[counter
].numbytes
)
639 if (current_header
->oldgnu_header
.isextended
)
641 /* Read in the list of extended headers and translate them
642 into the sparsearray as before. Note that this
643 invalidates current_header. */
645 /* static */ int ind
= SPARSES_IN_OLDGNU_HEADER
;
649 exhdr
= find_next_block ();
652 ERROR ((0, 0, _("Unexpected EOF in archive")));
655 for (counter
= 0; counter
< SPARSES_IN_SPARSE_HEADER
; counter
++)
657 struct sparse
const *s
= &exhdr
->sparse_header
.sp
[counter
];
658 if (counter
+ ind
> sp_array_size
- 1)
660 /* Realloc the scratch area since we've run out of
665 xrealloc (sparsearray
,
666 sp_array_size
* sizeof (struct sp_array
));
668 if (s
->numbytes
[0] == 0)
670 sparsearray
[counter
+ ind
].offset
=
671 OFF_FROM_HEADER (s
->offset
);
672 sparsearray
[counter
+ ind
].numbytes
=
673 SIZE_FROM_HEADER (s
->numbytes
);
675 if (!exhdr
->sparse_header
.isextended
)
679 ind
+= SPARSES_IN_SPARSE_HEADER
;
680 set_next_block_after (exhdr
);
683 set_next_block_after (exhdr
);
691 /* Appears to be a file. But BSD tar uses the convention that a slash
692 suffix means a directory. */
694 name_length
= strlen (CURRENT_FILE_NAME
);
695 if (name_length
&& CURRENT_FILE_NAME
[name_length
- 1] == '/')
698 /* FIXME: deal with protection issues. */
701 openflag
= (O_WRONLY
| O_BINARY
| O_CREAT
702 | (old_files_option
== OVERWRITE_OLD_FILES
705 mode
= current_stat
.st_mode
& MODE_RWX
& ~ current_umask
;
707 if (to_stdout_option
)
713 if (! prepare_to_extract (CURRENT_FILE_NAME
))
722 /* Contiguous files (on the Masscomp) have to specify the size in
723 the open call that creates them. */
725 if (typeflag
== CONTTYPE
)
726 fd
= open (CURRENT_FILE_NAME
, openflag
| O_CTG
,
727 mode
, current_stat
.st_size
);
729 fd
= open (CURRENT_FILE_NAME
, openflag
, mode
);
731 #else /* not O_CTG */
732 if (typeflag
== CONTTYPE
)
734 static int conttype_diagnosed
;
736 if (!conttype_diagnosed
)
738 conttype_diagnosed
= 1;
739 WARN ((0, 0, _("Extracting contiguous files as regular files")));
742 fd
= open (CURRENT_FILE_NAME
, openflag
, mode
);
744 #endif /* not O_CTG */
748 if (maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
751 open_error (CURRENT_FILE_NAME
);
759 if (typeflag
== GNUTYPE_SPARSE
)
762 size_t name_length_bis
;
764 /* Kludge alert. NAME is assigned to header.name because
765 during the extraction, the space that contains the header
766 will get scribbled on, and the name will get munged, so any
767 error messages that happen to contain the filename will look
768 REAL interesting unless we do this. */
770 name_length_bis
= strlen (CURRENT_FILE_NAME
) + 1;
771 name
= xmalloc (name_length_bis
);
772 memcpy (name
, CURRENT_FILE_NAME
, name_length_bis
);
773 size
= current_stat
.st_size
;
774 extract_sparse_file (fd
, &size
, current_stat
.st_size
, name
);
777 for (size
= current_stat
.st_size
;
781 if (multi_volume_option
)
783 assign_string (&save_name
, current_file_name
);
784 save_totsize
= current_stat
.st_size
;
785 save_sizeleft
= size
;
788 /* Locate data, determine max length writeable, write it,
789 block that we have used the data, then check if the write
792 data_block
= find_next_block ();
795 ERROR ((0, 0, _("Unexpected EOF in archive")));
796 break; /* FIXME: What happens, then? */
799 written
= available_space_after (data_block
);
804 sstatus
= full_write (fd
, data_block
->buffer
, written
);
806 set_next_block_after ((union block
*)
807 (data_block
->buffer
+ written
- 1));
808 if (sstatus
== written
)
811 /* Error in writing to file. Print it, skip to next file in
814 write_error_details (CURRENT_FILE_NAME
, sstatus
, written
);
815 skip_file (size
- written
);
816 break; /* still do the close, mod time, chmod, etc */
819 if (multi_volume_option
)
820 assign_string (&save_name
, 0);
822 /* If writing to stdout, don't try to do anything to the filename;
823 it doesn't exist, or we don't want to touch it anyway. */
825 if (to_stdout_option
)
831 close_error (CURRENT_FILE_NAME
);
836 set_stat (CURRENT_FILE_NAME
, ¤t_stat
, 0,
837 (old_files_option
== OVERWRITE_OLD_FILES
839 : ARCHIVED_PERMSTATUS
),
845 if (! prepare_to_extract (CURRENT_FILE_NAME
))
848 if (absolute_names_option
849 || (current_link_name
[0] != '/'
850 && ! contains_dot_dot (current_link_name
)))
852 while (status
= symlink (current_link_name
, CURRENT_FILE_NAME
),
854 if (!maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
858 set_stat (CURRENT_FILE_NAME
, ¤t_stat
, 0, 0, SYMTYPE
);
860 symlink_error (current_link_name
, CURRENT_FILE_NAME
);
864 /* This symbolic link is potentially dangerous. Don't
865 create it now; instead, create a placeholder file, which
866 will be replaced after other extraction is done. */
869 while (fd
= open (CURRENT_FILE_NAME
, O_WRONLY
| O_CREAT
| O_EXCL
, 0),
871 if (! maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
876 open_error (CURRENT_FILE_NAME
);
877 else if (fstat (fd
, &st
) != 0)
879 stat_error (CURRENT_FILE_NAME
);
882 else if (close (fd
) != 0)
883 close_error (CURRENT_FILE_NAME
);
886 size_t filelen
= strlen (CURRENT_FILE_NAME
);
887 size_t linklen
= strlen (current_link_name
);
888 struct delayed_symlink
*p
=
889 xmalloc (sizeof *p
+ filelen
+ linklen
+ 1);
890 p
->next
= delayed_symlink_head
;
891 delayed_symlink_head
= p
;
894 p
->mtime
= st
.st_mtime
;
895 p
->uid
= current_stat
.st_uid
;
896 p
->gid
= current_stat
.st_gid
;
897 memcpy (p
->names
, CURRENT_FILE_NAME
, filelen
+ 1);
898 memcpy (p
->names
+ filelen
+ 1, current_link_name
, linklen
+ 1);
903 if (status
!= 0 && backup_option
)
909 static int warned_once
;
915 _("Attempting extraction of symbolic links as hard links")));
923 if (! prepare_to_extract (CURRENT_FILE_NAME
))
928 struct stat st1
, st2
;
931 /* MSDOS does not implement links. However, djgpp's link() actually
933 status
= link (current_link_name
, CURRENT_FILE_NAME
);
937 if (maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
940 if (incremental_option
&& errno
== EEXIST
)
943 if (stat (current_link_name
, &st1
) == 0
944 && stat (CURRENT_FILE_NAME
, &st2
) == 0
945 && st1
.st_dev
== st2
.st_dev
946 && st1
.st_ino
== st2
.st_ino
)
949 ERROR ((0, e
, _("%s: Cannot link to %s"),
950 quotearg_colon (CURRENT_FILE_NAME
),
951 quote (current_link_name
)));
959 current_stat
.st_mode
|= S_IFCHR
;
965 current_stat
.st_mode
|= S_IFBLK
;
968 #if S_IFCHR || S_IFBLK
970 if (! prepare_to_extract (CURRENT_FILE_NAME
))
973 status
= mknod (CURRENT_FILE_NAME
, current_stat
.st_mode
,
974 current_stat
.st_rdev
);
977 if (maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
979 mknod_error (CURRENT_FILE_NAME
);
984 set_stat (CURRENT_FILE_NAME
, ¤t_stat
, 0,
985 ARCHIVED_PERMSTATUS
, typeflag
);
989 #if HAVE_MKFIFO || defined mkfifo
991 if (! prepare_to_extract (CURRENT_FILE_NAME
))
994 while (status
= mkfifo (CURRENT_FILE_NAME
, current_stat
.st_mode
),
996 if (!maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
1000 set_stat (CURRENT_FILE_NAME
, ¤t_stat
, 0,
1001 ARCHIVED_PERMSTATUS
, typeflag
);
1004 mkfifo_error (CURRENT_FILE_NAME
);
1006 undo_last_backup ();
1012 case GNUTYPE_DUMPDIR
:
1013 name_length
= strlen (CURRENT_FILE_NAME
);
1016 if (incremental_option
)
1018 /* Read the entry and delete files that aren't listed in the
1021 gnu_restore (skipcrud
);
1023 else if (typeflag
== GNUTYPE_DUMPDIR
)
1026 if (! prepare_to_extract (CURRENT_FILE_NAME
))
1029 mode
= ((current_stat
.st_mode
1030 | (we_are_root
? 0 : MODE_WXUSR
))
1034 status
= mkdir (CURRENT_FILE_NAME
, mode
);
1037 if (errno
== EEXIST
&& interdir_made
)
1040 if (stat (CURRENT_FILE_NAME
, &st
) == 0)
1042 repair_delayed_set_stat (CURRENT_FILE_NAME
, &st
);
1048 if (maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
1051 if (errno
!= EEXIST
|| old_files_option
== KEEP_OLD_FILES
)
1053 mkdir_error (CURRENT_FILE_NAME
);
1055 undo_last_backup ();
1061 || old_files_option
== OVERWRITE_OLD_FILES
)
1062 delay_set_stat (CURRENT_FILE_NAME
, ¤t_stat
,
1063 mode
& ~ current_stat
.st_mode
,
1065 ? ARCHIVED_PERMSTATUS
1066 : UNKNOWN_PERMSTATUS
));
1069 case GNUTYPE_VOLHDR
:
1071 fprintf (stdlis
, _("Reading %s\n"), quote (current_file_name
));
1078 case GNUTYPE_MULTIVOL
:
1080 _("%s: Cannot extract -- file is continued from another volume"),
1081 quotearg_colon (current_file_name
)));
1084 undo_last_backup ();
1087 case GNUTYPE_LONGNAME
:
1088 case GNUTYPE_LONGLINK
:
1089 ERROR ((0, 0, _("Visible long name error")));
1092 undo_last_backup ();
1097 _("%s: Unknown file type '%c', extracted as normal file"),
1098 quotearg_colon (CURRENT_FILE_NAME
), typeflag
));
1102 #undef CURRENT_FILE_NAME
1105 /* Extract the symbolic links whose final extraction were delayed. */
1107 apply_delayed_symlinks (void)
1109 struct delayed_symlink
*p
;
1110 struct delayed_symlink
*next
;
1112 for (p
= delayed_symlink_head
; p
; p
= next
)
1114 char const *file
= p
->names
;
1117 /* Before doing anything, make sure the placeholder file is still
1118 there. If the placeholder isn't there, don't worry about it, as
1119 it may have been removed by a later extraction. */
1120 if (lstat (file
, &st
) == 0
1121 && st
.st_dev
== p
->dev
1122 && st
.st_ino
== p
->ino
1123 && st
.st_mtime
== p
->mtime
)
1125 if (unlink (file
) != 0)
1126 unlink_error (file
);
1129 char const *contents
= file
+ strlen (file
) + 1;
1130 if (symlink (contents
, file
) != 0)
1131 symlink_error (contents
, file
);
1136 set_stat (file
, &st
, 0, 0, SYMTYPE
);
1145 delayed_symlink_head
= 0;
1148 /* Finish the extraction of an archive. */
1150 extract_finish (void)
1152 /* Apply delayed symlinks last, so that they don't affect
1153 delayed directory status-setting. */
1154 apply_nonancestor_delayed_set_stat ("");
1155 apply_delayed_symlinks ();
1162 error (TAREXIT_FAILURE
, 0, _("Error is not recoverable: exiting now"));