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. */
35 int we_are_root
; /* true if our effective uid == 0 */
36 static mode_t newdir_umask
; /* umask when creating new directories */
37 static mode_t current_umask
; /* current umask (which is set to 0 if -p) */
39 /* Status of the permissions of a file that we are extracting. */
42 /* This file may have existed already; its permissions are unknown. */
45 /* This file was created using the permissions from the archive. */
48 /* This is an intermediate directory; the archive did not specify
53 /* List of directories whose statuses we need to extract after we've
54 finished extracting their subsidiary files. The head of the list
55 has the longest name; each non-head element in the list is an
56 ancestor (in the directory hierarchy) of the preceding element. */
57 struct delayed_set_stat
59 struct delayed_set_stat
*next
;
60 struct stat stat_info
;
62 mode_t invert_permissions
;
63 enum permstatus permstatus
;
67 static struct delayed_set_stat
*delayed_set_stat_head
;
69 /* List of symbolic links whose creation we have delayed. */
70 struct delayed_symlink
72 /* The next delayed symbolic link in the list. */
73 struct delayed_symlink
*next
;
75 /* The device, inode number and last-modified time of the
76 placeholder symbolic link. */
81 /* The desired owner and group of the symbolic link. */
85 /* The location and desired target of the desired link, as two
86 adjacent character strings, both null-terminated. */
90 static struct delayed_symlink
*delayed_symlink_head
;
92 /* Set up to extract files. */
96 we_are_root
= geteuid () == 0;
97 same_permissions_option
+= we_are_root
;
98 same_owner_option
+= we_are_root
;
99 xalloc_fail_func
= extract_finish
;
101 /* Option -p clears the kernel umask, so it does not affect proper
102 restoration of file permissions. New intermediate directories will
103 comply with umask at start of program. */
105 newdir_umask
= umask (0);
106 if (0 < same_permissions_option
)
110 umask (newdir_umask
); /* restore the kernel umask */
111 current_umask
= newdir_umask
;
115 /* If restoring permissions, restore the mode for FILE_NAME from
116 information given in *STAT_INFO; otherwise invert the
117 INVERT_PERMISSIONS bits from the file's current permissions.
118 PERMSTATUS specifies the status of the file's permissions.
119 TYPEFLAG specifies the type of the file. */
121 set_mode (char const *file_name
, struct stat
const *stat_info
,
122 mode_t invert_permissions
, enum permstatus permstatus
,
127 if (0 < same_permissions_option
128 && permstatus
!= INTERDIR_PERMSTATUS
)
130 mode
= stat_info
->st_mode
;
132 /* If we created the file and it has a usual mode, then its mode
133 is normally set correctly already. But on many hosts, some
134 directories inherit the setgid bits from their parents, so we
135 we must set directories' modes explicitly. */
136 if (permstatus
== ARCHIVED_PERMSTATUS
137 && ! (mode
& ~ MODE_RWX
)
138 && typeflag
!= DIRTYPE
139 && typeflag
!= GNUTYPE_DUMPDIR
)
142 else if (! invert_permissions
)
146 /* We must inspect a directory's current permissions, since the
147 directory may have inherited its setgid bit from its parent.
149 INVERT_PERMISSIONS happens to be nonzero only for directories
150 that we created, so there's no point optimizing this code for
153 if (stat (file_name
, &st
) != 0)
155 stat_error (file_name
);
158 mode
= st
.st_mode
^ invert_permissions
;
161 if (chmod (file_name
, mode
) != 0)
162 chmod_error_details (file_name
, mode
);
165 /* Check time after successfully setting FILE_NAME's time stamp to T. */
167 check_time (char const *file_name
, time_t t
)
170 if (start_time
< t
&& (now
= time (0)) < t
)
171 WARN ((0, 0, _("%s: time stamp %s is %lu s in the future"),
172 file_name
, tartime (t
), (unsigned long) (t
- now
)));
175 /* Restore stat attributes (owner, group, mode and times) for
176 FILE_NAME, using information given in *STAT_INFO.
177 If not restoring permissions, invert the
178 INVERT_PERMISSIONS bits from the file's current permissions.
179 PERMSTATUS specifies the status of the file's permissions.
180 TYPEFLAG specifies the type of the file. */
182 /* FIXME: About proper restoration of symbolic link attributes, we still do
183 not have it right. Pretesters' reports tell us we need further study and
184 probably more configuration. For now, just use lchown if it exists, and
185 punt for the rest. Sigh! */
188 set_stat (char const *file_name
, struct stat
const *stat_info
,
189 mode_t invert_permissions
, enum permstatus permstatus
,
192 struct utimbuf utimbuf
;
194 if (typeflag
!= SYMTYPE
)
196 /* We do the utime before the chmod because some versions of utime are
197 broken and trash the modes of the file. */
199 if (! touch_option
&& permstatus
!= INTERDIR_PERMSTATUS
)
201 /* We set the accessed time to `now', which is really the time we
202 started extracting files, unless incremental_option is used, in
203 which case .st_atime is used. */
205 /* FIXME: incremental_option should set ctime too, but how? */
207 if (incremental_option
)
208 utimbuf
.actime
= stat_info
->st_atime
;
210 utimbuf
.actime
= start_time
;
212 utimbuf
.modtime
= stat_info
->st_mtime
;
214 if (utime (file_name
, &utimbuf
) < 0)
215 utime_error (file_name
);
218 check_time (file_name
, stat_info
->st_atime
);
219 check_time (file_name
, stat_info
->st_mtime
);
223 /* Some systems allow non-root users to give files away. Once this
224 done, it is not possible anymore to change file permissions, so we
225 have to set permissions prior to possibly giving files away. */
227 set_mode (file_name
, stat_info
,
228 invert_permissions
, permstatus
, typeflag
);
231 if (0 < same_owner_option
&& permstatus
!= INTERDIR_PERMSTATUS
)
233 /* When lchown exists, it should be used to change the attributes of
234 the symbolic link itself. In this case, a mere chown would change
235 the attributes of the file the symbolic link is pointing to, and
236 should be avoided. */
238 if (typeflag
== SYMTYPE
)
241 if (lchown (file_name
, stat_info
->st_uid
, stat_info
->st_gid
) < 0)
242 chown_error_details (file_name
,
243 stat_info
->st_uid
, stat_info
->st_gid
);
248 if (chown (file_name
, stat_info
->st_uid
, stat_info
->st_gid
) < 0)
249 chown_error_details (file_name
,
250 stat_info
->st_uid
, stat_info
->st_gid
);
252 /* On a few systems, and in particular, those allowing to give files
253 away, changing the owner or group destroys the suid or sgid bits.
254 So let's attempt setting these bits once more. */
255 if (stat_info
->st_mode
& (S_ISUID
| S_ISGID
| S_ISVTX
))
256 set_mode (file_name
, stat_info
,
257 invert_permissions
, permstatus
, typeflag
);
262 /* Remember to restore stat attributes (owner, group, mode and times)
263 for the directory FILE_NAME, using information given in *STAT_INFO,
264 once we stop extracting files into that directory.
265 If not restoring permissions, remember to invert the
266 INVERT_PERMISSIONS bits from the file's current permissions.
267 PERMSTATUS specifies the status of the file's permissions. */
269 delay_set_stat (char const *file_name
, struct stat
const *stat_info
,
270 mode_t invert_permissions
, enum permstatus permstatus
)
272 size_t file_name_len
= strlen (file_name
);
273 struct delayed_set_stat
*data
= xmalloc (sizeof *data
+ file_name_len
);
274 data
->file_name_len
= file_name_len
;
275 strcpy (data
->file_name
, file_name
);
276 data
->invert_permissions
= invert_permissions
;
277 data
->permstatus
= permstatus
;
278 data
->stat_info
= *stat_info
;
279 data
->next
= delayed_set_stat_head
;
280 delayed_set_stat_head
= data
;
283 /* Update the delayed_set_stat info for an intermediate directory
284 created on the path to DIR_NAME. The intermediate directory turned
285 out to be the same as this directory, e.g. due trailing slash or
286 ".." or symbolic links. *DIR_STAT_INFO is the status of the
289 repair_delayed_set_stat (char const *dir_name
,
290 struct stat
const *dir_stat_info
)
292 struct delayed_set_stat
*data
;
293 for (data
= delayed_set_stat_head
; data
; data
= data
->next
)
296 if (stat (data
->file_name
, &st
) != 0)
298 stat_error (data
->file_name
);
302 if (st
.st_dev
== dir_stat_info
->st_dev
303 && st
.st_ino
== dir_stat_info
->st_ino
)
305 data
->stat_info
= current_stat
;
306 data
->invert_permissions
= (MODE_RWX
307 & (current_stat
.st_mode
^ st
.st_mode
));
308 data
->permstatus
= ARCHIVED_PERMSTATUS
;
313 ERROR ((0, 0, _("%s: Unexpected inconsistency when making directory"),
314 quotearg_colon (dir_name
)));
317 /* After a file/link/symlink/directory creation has failed, see if
318 it's because some required directory was not present, and if so,
319 create all required directories. Return non-zero if a directory
322 make_directories (char *file_name
)
324 char *cursor
; /* points into path */
325 int did_something
= 0; /* did we do anything yet? */
327 int invert_permissions
;
330 for (cursor
= strchr (file_name
, '/');
332 cursor
= strchr (cursor
+ 1, '/'))
334 /* Avoid mkdir of empty string, if leading or double '/'. */
336 if (cursor
== file_name
|| cursor
[-1] == '/')
339 /* Avoid mkdir where last part of path is "." or "..". */
341 if (cursor
[-1] == '.'
342 && (cursor
== file_name
+ 1 || cursor
[-2] == '/'
343 || (cursor
[-2] == '.'
344 && (cursor
== file_name
+ 2 || cursor
[-3] == '/'))))
347 *cursor
= '\0'; /* truncate the path there */
348 mode
= MODE_RWX
& ~ newdir_umask
;
349 invert_permissions
= we_are_root
? 0 : MODE_WXUSR
& ~ mode
;
350 status
= mkdir (file_name
, mode
^ invert_permissions
);
354 /* Create a struct delayed_set_stat even if
355 invert_permissions is zero, because
356 repair_delayed_set_stat may need to update the struct. */
357 delay_set_stat (file_name
,
358 ¤t_stat
/* ignored */,
359 invert_permissions
, INTERDIR_PERMSTATUS
);
361 print_for_mkdir (file_name
, cursor
- file_name
, mode
);
372 /* Turbo C mkdir gives a funny errno. */
376 /* Directory already exists. */
379 /* Some other error in the mkdir. We return to the caller. */
383 return did_something
; /* tell them to retry if we made one */
386 /* Prepare to extract a file.
387 Return zero if extraction should not proceed. */
390 prepare_to_extract (char const *file_name
)
392 if (to_stdout_option
)
395 if (old_files_option
== UNLINK_FIRST_OLD_FILES
396 && !remove_any_file (file_name
, recursive_unlink_option
)
397 && errno
&& errno
!= ENOENT
)
399 unlink_error (file_name
);
406 /* Attempt repairing what went wrong with the extraction. Delete an
407 already existing file or create missing intermediate directories.
408 Return nonzero if we somewhat increased our chances at a successful
409 extraction. errno is properly restored on zero return. */
411 maybe_recoverable (char *file_name
, int *interdir_made
)
419 /* Remove an old file, if the options allow this. */
421 switch (old_files_option
)
426 case DEFAULT_OLD_FILES
:
427 case OVERWRITE_OLD_FILES
:
429 int r
= remove_any_file (file_name
, 0);
436 /* Attempt creating missing intermediate directories. */
437 if (! make_directories (file_name
))
446 /* Just say we can't do anything about it... */
453 extract_sparse_file (int fd
, off_t
*sizeleft
, off_t totalsize
, char *name
)
459 /* assuming sizeleft is initially totalsize */
461 while (*sizeleft
> 0)
463 union block
*data_block
= find_next_block ();
466 ERROR ((0, 0, _("Unexpected EOF in archive")));
469 if (lseek (fd
, sparsearray
[sparse_ind
].offset
, SEEK_SET
) < 0)
471 seek_error_details (name
, sparsearray
[sparse_ind
].offset
);
474 written
= sparsearray
[sparse_ind
++].numbytes
;
475 while (written
> BLOCKSIZE
)
477 count
= full_write (fd
, data_block
->buffer
, BLOCKSIZE
);
482 set_next_block_after (data_block
);
483 data_block
= find_next_block ();
486 ERROR ((0, 0, _("Unexpected EOF in archive")));
491 count
= full_write (fd
, data_block
->buffer
, written
);
495 else if (count
!= written
)
497 write_error_details (name
, count
, written
);
498 skip_file (*sizeleft
);
503 set_next_block_after (data_block
);
509 /* Fix the statuses of all directories whose statuses need fixing, and
510 which are not ancestors of FILE_NAME. */
512 apply_nonancestor_delayed_set_stat (char const *file_name
)
514 size_t file_name_len
= strlen (file_name
);
516 while (delayed_set_stat_head
)
518 struct delayed_set_stat
*data
= delayed_set_stat_head
;
519 if (data
->file_name_len
< file_name_len
520 && file_name
[data
->file_name_len
]
521 && (file_name
[data
->file_name_len
] == '/'
522 || file_name
[data
->file_name_len
- 1] == '/')
523 && memcmp (file_name
, data
->file_name
, data
->file_name_len
) == 0)
525 delayed_set_stat_head
= data
->next
;
526 set_stat (data
->file_name
, &data
->stat_info
,
527 data
->invert_permissions
, data
->permstatus
, DIRTYPE
);
532 /* Extract a file from the archive. */
534 extract_archive (void)
536 union block
*data_block
;
547 int interdir_made
= 0;
551 #define CURRENT_FILE_NAME (skipcrud + current_file_name)
553 set_next_block_after (current_header
);
554 decode_header (current_header
, ¤t_stat
, ¤t_format
, 1);
556 if (interactive_option
&& !confirm ("extract", current_file_name
))
562 /* Print the block from current_header and current_stat. */
567 /* Check for fully specified file names and other atrocities. */
570 if (! absolute_names_option
)
572 while (CURRENT_FILE_NAME
[0] == '/')
574 static int warned_once
;
579 WARN ((0, 0, _("Removing leading `/' from member names")));
581 skipcrud
++; /* force relative path */
584 if (contains_dot_dot (CURRENT_FILE_NAME
))
586 ERROR ((0, 0, _("%s: Member name contains `..'"),
587 quotearg_colon (CURRENT_FILE_NAME
)));
593 apply_nonancestor_delayed_set_stat (CURRENT_FILE_NAME
);
595 /* Take a safety backup of a previously existing file. */
597 if (backup_option
&& !to_stdout_option
)
598 if (!maybe_backup_file (CURRENT_FILE_NAME
, 0))
601 ERROR ((0, e
, _("%s: Was unable to backup this file"),
602 quotearg_colon (CURRENT_FILE_NAME
)));
607 /* Extract the archive entry according to its type. */
609 typeflag
= current_header
->header
.typeflag
;
612 /* JK - What we want to do if the file is sparse is loop through
613 the array of sparse structures in the header and read in and
614 translate the character strings representing 1) the offset at
615 which to write and 2) how many bytes to write into numbers,
616 which we store into the scratch array, "sparsearray". This
617 array makes our life easier the same way it did in creating the
618 tar file that had to deal with a sparse file.
620 After we read in the first five (at most) sparse structures, we
621 check to see if the file has an extended header, i.e., if more
622 sparse structures are needed to describe the contents of the new
623 file. If so, we read in the extended headers and continue to
624 store their contents into the sparsearray. */
629 xmalloc (sp_array_size
* sizeof (struct sp_array
));
631 for (counter
= 0; counter
< SPARSES_IN_OLDGNU_HEADER
; counter
++)
633 struct sparse
const *s
= ¤t_header
->oldgnu_header
.sp
[counter
];
634 sparsearray
[counter
].offset
= OFF_FROM_HEADER (s
->offset
);
635 sparsearray
[counter
].numbytes
= SIZE_FROM_HEADER (s
->numbytes
);
636 if (!sparsearray
[counter
].numbytes
)
640 if (current_header
->oldgnu_header
.isextended
)
642 /* Read in the list of extended headers and translate them
643 into the sparsearray as before. Note that this
644 invalidates current_header. */
646 /* static */ int ind
= SPARSES_IN_OLDGNU_HEADER
;
650 exhdr
= find_next_block ();
653 ERROR ((0, 0, _("Unexpected EOF in archive")));
656 for (counter
= 0; counter
< SPARSES_IN_SPARSE_HEADER
; counter
++)
658 struct sparse
const *s
= &exhdr
->sparse_header
.sp
[counter
];
659 if (counter
+ ind
> sp_array_size
- 1)
661 /* Realloc the scratch area since we've run out of
666 xrealloc (sparsearray
,
667 sp_array_size
* sizeof (struct sp_array
));
669 if (s
->numbytes
[0] == 0)
671 sparsearray
[counter
+ ind
].offset
=
672 OFF_FROM_HEADER (s
->offset
);
673 sparsearray
[counter
+ ind
].numbytes
=
674 SIZE_FROM_HEADER (s
->numbytes
);
676 if (!exhdr
->sparse_header
.isextended
)
680 ind
+= SPARSES_IN_SPARSE_HEADER
;
681 set_next_block_after (exhdr
);
684 set_next_block_after (exhdr
);
692 /* Appears to be a file. But BSD tar uses the convention that a slash
693 suffix means a directory. */
695 name_length
= strlen (CURRENT_FILE_NAME
);
696 if (name_length
&& CURRENT_FILE_NAME
[name_length
- 1] == '/')
699 /* FIXME: deal with protection issues. */
702 openflag
= (O_WRONLY
| O_BINARY
| O_CREAT
703 | (old_files_option
== OVERWRITE_OLD_FILES
706 mode
= current_stat
.st_mode
& MODE_RWX
& ~ current_umask
;
708 if (to_stdout_option
)
714 if (! prepare_to_extract (CURRENT_FILE_NAME
))
723 /* Contiguous files (on the Masscomp) have to specify the size in
724 the open call that creates them. */
726 if (typeflag
== CONTTYPE
)
727 fd
= open (CURRENT_FILE_NAME
, openflag
| O_CTG
,
728 mode
, current_stat
.st_size
);
730 fd
= open (CURRENT_FILE_NAME
, openflag
, mode
);
732 #else /* not O_CTG */
733 if (typeflag
== CONTTYPE
)
735 static int conttype_diagnosed
;
737 if (!conttype_diagnosed
)
739 conttype_diagnosed
= 1;
740 WARN ((0, 0, _("Extracting contiguous files as regular files")));
743 fd
= open (CURRENT_FILE_NAME
, openflag
, mode
);
745 #endif /* not O_CTG */
749 if (maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
752 open_error (CURRENT_FILE_NAME
);
760 if (typeflag
== GNUTYPE_SPARSE
)
763 size_t name_length_bis
;
765 /* Kludge alert. NAME is assigned to header.name because
766 during the extraction, the space that contains the header
767 will get scribbled on, and the name will get munged, so any
768 error messages that happen to contain the filename will look
769 REAL interesting unless we do this. */
771 name_length_bis
= strlen (CURRENT_FILE_NAME
) + 1;
772 name
= xmalloc (name_length_bis
);
773 memcpy (name
, CURRENT_FILE_NAME
, name_length_bis
);
774 size
= current_stat
.st_size
;
775 extract_sparse_file (fd
, &size
, current_stat
.st_size
, name
);
778 for (size
= current_stat
.st_size
;
782 if (multi_volume_option
)
784 assign_string (&save_name
, current_file_name
);
785 save_totsize
= current_stat
.st_size
;
786 save_sizeleft
= size
;
789 /* Locate data, determine max length writeable, write it,
790 block that we have used the data, then check if the write
793 data_block
= find_next_block ();
796 ERROR ((0, 0, _("Unexpected EOF in archive")));
797 break; /* FIXME: What happens, then? */
800 written
= available_space_after (data_block
);
805 sstatus
= full_write (fd
, data_block
->buffer
, written
);
807 set_next_block_after ((union block
*)
808 (data_block
->buffer
+ written
- 1));
809 if (sstatus
== written
)
812 /* Error in writing to file. Print it, skip to next file in
815 write_error_details (CURRENT_FILE_NAME
, sstatus
, written
);
816 skip_file (size
- written
);
817 break; /* still do the close, mod time, chmod, etc */
820 if (multi_volume_option
)
821 assign_string (&save_name
, 0);
823 /* If writing to stdout, don't try to do anything to the filename;
824 it doesn't exist, or we don't want to touch it anyway. */
826 if (to_stdout_option
)
832 close_error (CURRENT_FILE_NAME
);
837 set_stat (CURRENT_FILE_NAME
, ¤t_stat
, 0,
838 (old_files_option
== OVERWRITE_OLD_FILES
840 : ARCHIVED_PERMSTATUS
),
846 if (! prepare_to_extract (CURRENT_FILE_NAME
))
849 if (absolute_names_option
850 || (current_link_name
[0] != '/'
851 && ! contains_dot_dot (current_link_name
)))
853 while (status
= symlink (current_link_name
, CURRENT_FILE_NAME
),
855 if (!maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
859 set_stat (CURRENT_FILE_NAME
, ¤t_stat
, 0, 0, SYMTYPE
);
861 symlink_error (current_link_name
, CURRENT_FILE_NAME
);
865 /* This symbolic link is potentially dangerous. Don't
866 create it now; instead, create a placeholder file, which
867 will be replaced after other extraction is done. */
870 while (fd
= open (CURRENT_FILE_NAME
, O_WRONLY
| O_CREAT
| O_EXCL
, 0),
872 if (! maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
877 open_error (CURRENT_FILE_NAME
);
878 else if (fstat (fd
, &st
) != 0)
880 stat_error (CURRENT_FILE_NAME
);
883 else if (close (fd
) != 0)
884 close_error (CURRENT_FILE_NAME
);
887 size_t filelen
= strlen (CURRENT_FILE_NAME
);
888 size_t linklen
= strlen (current_link_name
);
889 struct delayed_symlink
*p
=
890 xmalloc (sizeof *p
+ filelen
+ linklen
+ 1);
891 p
->next
= delayed_symlink_head
;
892 delayed_symlink_head
= p
;
895 p
->mtime
= st
.st_mtime
;
896 p
->uid
= current_stat
.st_uid
;
897 p
->gid
= current_stat
.st_gid
;
898 memcpy (p
->names
, CURRENT_FILE_NAME
, filelen
+ 1);
899 memcpy (p
->names
+ filelen
+ 1, current_link_name
, linklen
+ 1);
904 if (status
!= 0 && backup_option
)
910 static int warned_once
;
916 _("Attempting extraction of symbolic links as hard links")));
924 if (! prepare_to_extract (CURRENT_FILE_NAME
))
929 struct stat st1
, st2
;
932 /* MSDOS does not implement links. However, djgpp's link() actually
934 status
= link (current_link_name
, CURRENT_FILE_NAME
);
938 if (maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
941 if (incremental_option
&& errno
== EEXIST
)
944 if (stat (current_link_name
, &st1
) == 0
945 && stat (CURRENT_FILE_NAME
, &st2
) == 0
946 && st1
.st_dev
== st2
.st_dev
947 && st1
.st_ino
== st2
.st_ino
)
950 ERROR ((0, e
, _("%s: Cannot link to %s"),
951 quotearg_colon (CURRENT_FILE_NAME
),
952 quote (current_link_name
)));
960 current_stat
.st_mode
|= S_IFCHR
;
966 current_stat
.st_mode
|= S_IFBLK
;
969 #if S_IFCHR || S_IFBLK
971 if (! prepare_to_extract (CURRENT_FILE_NAME
))
974 status
= mknod (CURRENT_FILE_NAME
, current_stat
.st_mode
,
975 current_stat
.st_rdev
);
978 if (maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
980 mknod_error (CURRENT_FILE_NAME
);
985 set_stat (CURRENT_FILE_NAME
, ¤t_stat
, 0,
986 ARCHIVED_PERMSTATUS
, typeflag
);
990 #if HAVE_MKFIFO || defined mkfifo
992 if (! prepare_to_extract (CURRENT_FILE_NAME
))
995 while (status
= mkfifo (CURRENT_FILE_NAME
, current_stat
.st_mode
),
997 if (!maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
1001 set_stat (CURRENT_FILE_NAME
, ¤t_stat
, 0,
1002 ARCHIVED_PERMSTATUS
, typeflag
);
1005 mkfifo_error (CURRENT_FILE_NAME
);
1007 undo_last_backup ();
1013 case GNUTYPE_DUMPDIR
:
1014 name_length
= strlen (CURRENT_FILE_NAME
);
1017 if (incremental_option
)
1019 /* Read the entry and delete files that aren't listed in the
1022 gnu_restore (skipcrud
);
1024 else if (typeflag
== GNUTYPE_DUMPDIR
)
1027 if (! prepare_to_extract (CURRENT_FILE_NAME
))
1030 mode
= ((current_stat
.st_mode
1031 | (we_are_root
? 0 : MODE_WXUSR
))
1035 status
= mkdir (CURRENT_FILE_NAME
, mode
);
1038 if (errno
== EEXIST
&& interdir_made
)
1041 if (stat (CURRENT_FILE_NAME
, &st
) == 0)
1043 repair_delayed_set_stat (CURRENT_FILE_NAME
, &st
);
1049 if (maybe_recoverable (CURRENT_FILE_NAME
, &interdir_made
))
1052 if (errno
!= EEXIST
|| old_files_option
== KEEP_OLD_FILES
)
1054 mkdir_error (CURRENT_FILE_NAME
);
1056 undo_last_backup ();
1062 || old_files_option
== OVERWRITE_OLD_FILES
)
1063 delay_set_stat (CURRENT_FILE_NAME
, ¤t_stat
,
1064 mode
& ~ current_stat
.st_mode
,
1066 ? ARCHIVED_PERMSTATUS
1067 : UNKNOWN_PERMSTATUS
));
1070 case GNUTYPE_VOLHDR
:
1072 fprintf (stdlis
, _("Reading %s\n"), quote (current_file_name
));
1079 case GNUTYPE_MULTIVOL
:
1081 _("%s: Cannot extract -- file is continued from another volume"),
1082 quotearg_colon (current_file_name
)));
1085 undo_last_backup ();
1088 case GNUTYPE_LONGNAME
:
1089 case GNUTYPE_LONGLINK
:
1090 ERROR ((0, 0, _("Visible long name error")));
1093 undo_last_backup ();
1098 _("%s: Unknown file type '%c', extracted as normal file"),
1099 quotearg_colon (CURRENT_FILE_NAME
), typeflag
));
1103 #undef CURRENT_FILE_NAME
1106 /* Extract the symbolic links whose final extraction were delayed. */
1108 apply_delayed_symlinks (void)
1110 struct delayed_symlink
*p
;
1111 struct delayed_symlink
*next
;
1113 for (p
= delayed_symlink_head
; p
; p
= next
)
1115 char const *file
= p
->names
;
1118 /* Before doing anything, make sure the placeholder file is still
1119 there. If the placeholder isn't there, don't worry about it, as
1120 it may have been removed by a later extraction. */
1121 if (lstat (file
, &st
) == 0
1122 && st
.st_dev
== p
->dev
1123 && st
.st_ino
== p
->ino
1124 && st
.st_mtime
== p
->mtime
)
1126 if (unlink (file
) != 0)
1127 unlink_error (file
);
1130 char const *contents
= file
+ strlen (file
) + 1;
1131 if (symlink (contents
, file
) != 0)
1132 symlink_error (contents
, file
);
1137 set_stat (file
, &st
, 0, 0, SYMTYPE
);
1146 delayed_symlink_head
= 0;
1149 /* Finish the extraction of an archive. */
1151 extract_finish (void)
1153 /* Apply delayed symlinks last, so that they don't affect
1154 delayed directory status-setting. */
1155 apply_nonancestor_delayed_set_stat ("");
1156 apply_delayed_symlinks ();
1163 error (TAREXIT_FAILURE
, 0, _("Error is not recoverable: exiting now"));