1 /* Extract files from a tar archive.
3 Copyright 1988, 1992-1994, 1996-2001, 2003-2007, 2010, 2012-2013
4 Free Software Foundation, Inc.
6 This file is part of GNU tar.
8 GNU tar is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 GNU tar is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 Written by John Gilmore, on 1985-11-19. */
32 static bool we_are_root
; /* true if our effective uid == 0 */
33 static mode_t newdir_umask
; /* umask when creating new directories */
34 static mode_t current_umask
; /* current umask (which is set to 0 if -p) */
36 #define ALL_MODE_BITS ((mode_t) ~ (mode_t) 0)
38 #if ! HAVE_FCHMOD && ! defined fchmod
39 # define fchmod(fd, mode) (errno = ENOSYS, -1)
41 #if ! HAVE_FCHOWN && ! defined fchown
42 # define fchown(fd, uid, gid) (errno = ENOSYS, -1)
45 /* Return true if an error number ERR means the system call is
46 supported in this case. */
50 return ! (err
== ENOSYS
52 || (EOPNOTSUPP
!= ENOTSUP
&& err
== EOPNOTSUPP
));
55 /* List of directories whose statuses we need to extract after we've
56 finished extracting their subsidiary files. If you consider each
57 contiguous subsequence of elements of the form [D]?[^D]*, where [D]
58 represents an element where AFTER_LINKS is nonzero and [^D]
59 represents an element where AFTER_LINKS is zero, then the head
60 of the subsequence has the longest name, and each non-head element
61 in the prefix is an ancestor (in the directory hierarchy) of the
64 struct delayed_set_stat
66 /* Next directory in list. */
67 struct delayed_set_stat
*next
;
69 /* Metadata for this directory. */
72 mode_t mode
; /* The desired mode is MODE & ~ current_umask. */
75 struct timespec atime
;
76 struct timespec mtime
;
78 /* An estimate of the directory's current mode, along with a mask
79 specifying which bits of this estimate are known to be correct.
80 If CURRENT_MODE_MASK is zero, CURRENT_MODE's value doesn't
83 mode_t current_mode_mask
;
85 /* This directory is an intermediate directory that was created
86 as an ancestor of some other directory; it was not mentioned
87 in the archive, so do not set its uid, gid, atime, or mtime,
88 and don't alter its mode outside of MODE_RWX. */
91 /* Whether symbolic links should be followed when accessing the
95 /* Do not set the status of this directory until after delayed
99 /* Directory that the name is relative to. */
102 /* extended attributes*/
108 size_t xattr_map_size
;
109 struct xattr_array
*xattr_map
;
110 /* Length and contents of name. */
111 size_t file_name_len
;
115 static struct delayed_set_stat
*delayed_set_stat_head
;
117 /* List of links whose creation we have delayed. */
120 /* The next delayed link in the list. */
121 struct delayed_link
*next
;
123 /* The device, inode number and birthtime of the placeholder.
124 birthtime.tv_nsec is negative if the birthtime is not available.
125 Don't use mtime as this would allow for false matches if some
126 other process removes the placeholder. Don't use ctime as
127 this would cause race conditions and other screwups, e.g.,
128 when restoring hard-linked symlinks. */
131 struct timespec birthtime
;
133 /* True if the link is symbolic. */
136 /* The desired metadata, valid only the link is symbolic. */
140 struct timespec atime
;
141 struct timespec mtime
;
143 /* The directory that the sources and target are relative to. */
146 /* A list of sources for this link. The sources are all to be
147 hard-linked together. */
148 struct string_list
*sources
;
150 /* SELinux context */
159 size_t xattr_map_size
;
160 struct xattr_array
*xattr_map
;
162 /* The desired target of the desired link. */
166 static struct delayed_link
*delayed_link_head
;
170 struct string_list
*next
;
174 /* Set up to extract files. */
178 we_are_root
= geteuid () == ROOT_UID
;
179 same_permissions_option
+= we_are_root
;
180 same_owner_option
+= we_are_root
;
182 /* Option -p clears the kernel umask, so it does not affect proper
183 restoration of file permissions. New intermediate directories will
184 comply with umask at start of program. */
186 newdir_umask
= umask (0);
187 if (0 < same_permissions_option
)
191 umask (newdir_umask
); /* restore the kernel umask */
192 current_umask
= newdir_umask
;
195 /* If the user wants to guarantee that everything is under one directory,
196 determine its name now and let it be created later. */
197 if (one_top_level_option
)
200 char *base
= base_name (archive_name_array
[0]);
202 for (i
= strlen (base
) - 1; i
> 2; i
--)
203 if (!strncmp (base
+ i
- 3, ".tar", 4) ||
204 !strncmp (base
+ i
- 3, ".taz", 4) ||
205 !strncmp (base
+ i
- 3, ".tbz", 4) ||
206 !strncmp (base
+ i
- 3, ".tb2", 4) ||
207 !strncmp (base
+ i
- 3, ".tgz", 4) ||
208 !strncmp (base
+ i
- 3, ".tlz", 4) ||
209 !strncmp (base
+ i
- 3, ".txz", 4)) break;
213 one_top_level_option
= false;
218 one_top_level
= xmalloc (i
- 2);
219 strncpy (one_top_level
, base
, i
- 3);
220 one_top_level
[i
- 3] = '\0';
225 /* Use fchmod if possible, fchmodat otherwise. */
227 fd_chmod (int fd
, char const *file
, mode_t mode
, int atflag
)
231 int result
= fchmod (fd
, mode
);
232 if (result
== 0 || implemented (errno
))
235 return fchmodat (chdir_fd
, file
, mode
, atflag
);
238 /* Use fchown if possible, fchownat otherwise. */
240 fd_chown (int fd
, char const *file
, uid_t uid
, gid_t gid
, int atflag
)
244 int result
= fchown (fd
, uid
, gid
);
245 if (result
== 0 || implemented (errno
))
248 return fchownat (chdir_fd
, file
, uid
, gid
, atflag
);
251 /* Use fstat if possible, fstatat otherwise. */
253 fd_stat (int fd
, char const *file
, struct stat
*st
, int atflag
)
257 : fstatat (chdir_fd
, file
, st
, atflag
));
260 /* Set the mode for FILE_NAME to MODE.
261 MODE_MASK specifies the bits of MODE that we care about;
262 thus if MODE_MASK is zero, do nothing.
263 If FD is nonnegative, it is a file descriptor for the file.
264 CURRENT_MODE and CURRENT_MODE_MASK specify information known about
265 the file's current mode, using the style of struct delayed_set_stat.
266 TYPEFLAG specifies the type of the file.
267 ATFLAG specifies the flag to use when statting the file. */
269 set_mode (char const *file_name
,
270 mode_t mode
, mode_t mode_mask
, int fd
,
271 mode_t current_mode
, mode_t current_mode_mask
,
272 char typeflag
, int atflag
)
274 if (((current_mode
^ mode
) | ~ current_mode_mask
) & mode_mask
)
276 if (MODE_ALL
& ~ mode_mask
& ~ current_mode_mask
)
279 if (fd_stat (fd
, file_name
, &st
, atflag
) != 0)
281 stat_error (file_name
);
284 current_mode
= st
.st_mode
;
287 current_mode
&= MODE_ALL
;
288 mode
= (current_mode
& ~ mode_mask
) | (mode
& mode_mask
);
290 if (current_mode
!= mode
)
293 fd_chmod (fd
, file_name
, mode
, atflag
) == 0 ? 0 : errno
;
295 /* On Solaris, chmod may fail if we don't have PRIV_ALL, because
296 setuid-root files would otherwise be a backdoor. See
297 http://opensolaris.org/jive/thread.jspa?threadID=95826
299 if (chmod_errno
== EPERM
&& (mode
& S_ISUID
)
300 && priv_set_restore_linkdir () == 0)
303 fd_chmod (fd
, file_name
, mode
, atflag
) == 0 ? 0 : errno
;
304 priv_set_remove_linkdir ();
307 /* Linux fchmodat does not support AT_SYMLINK_NOFOLLOW, and
308 returns ENOTSUP even when operating on non-symlinks, try
309 again with the flag disabled if it does not appear to be
310 supported and if the file is not a symlink. This
311 introduces a race, alas. */
312 if (atflag
&& typeflag
!= SYMTYPE
&& ! implemented (chmod_errno
))
313 chmod_errno
= fd_chmod (fd
, file_name
, mode
, 0) == 0 ? 0 : errno
;
316 && (typeflag
!= SYMTYPE
|| implemented (chmod_errno
)))
319 chmod_error_details (file_name
, mode
);
325 /* Check time after successfully setting FILE_NAME's time stamp to T. */
327 check_time (char const *file_name
, struct timespec t
)
330 WARNOPT (WARN_TIMESTAMP
,
331 (0, 0, _("%s: implausibly old time stamp %s"),
332 file_name
, tartime (t
, true)));
333 else if (timespec_cmp (volume_start_time
, t
) < 0)
337 if (timespec_cmp (now
, t
) < 0)
339 char buf
[TIMESPEC_STRSIZE_BOUND
];
340 struct timespec diff
;
341 diff
.tv_sec
= t
.tv_sec
- now
.tv_sec
;
342 diff
.tv_nsec
= t
.tv_nsec
- now
.tv_nsec
;
343 if (diff
.tv_nsec
< 0)
345 diff
.tv_nsec
+= BILLION
;
348 WARNOPT (WARN_TIMESTAMP
,
349 (0, 0, _("%s: time stamp %s is %s s in the future"),
350 file_name
, tartime (t
, true), code_timespec (diff
, buf
)));
355 /* Restore stat attributes (owner, group, mode and times) for
356 FILE_NAME, using information given in *ST.
357 If FD is nonnegative, it is a file descriptor for the file.
358 CURRENT_MODE and CURRENT_MODE_MASK specify information known about
359 the file's current mode, using the style of struct delayed_set_stat.
360 TYPEFLAG specifies the type of the file.
361 If INTERDIR, this is an intermediate directory.
362 ATFLAG specifies the flag to use when statting the file. */
365 set_stat (char const *file_name
,
366 struct tar_stat_info
const *st
,
367 int fd
, mode_t current_mode
, mode_t current_mode_mask
,
368 char typeflag
, bool interdir
, int atflag
)
370 /* Do the utime before the chmod because some versions of utime are
371 broken and trash the modes of the file. */
373 if (! touch_option
&& ! interdir
)
375 struct timespec ts
[2];
376 if (incremental_option
)
379 ts
[0].tv_nsec
= UTIME_OMIT
;
382 if (fdutimensat (fd
, chdir_fd
, file_name
, ts
, atflag
) == 0)
384 if (incremental_option
)
385 check_time (file_name
, ts
[0]);
386 check_time (file_name
, ts
[1]);
388 else if (typeflag
!= SYMTYPE
|| implemented (errno
))
389 utime_error (file_name
);
392 if (0 < same_owner_option
&& ! interdir
)
394 /* Some systems allow non-root users to give files away. Once this
395 done, it is not possible anymore to change file permissions.
396 However, setting file permissions now would be incorrect, since
397 they would apply to the wrong user, and there would be a race
398 condition. So, don't use systems that allow non-root users to
400 uid_t uid
= st
->stat
.st_uid
;
401 gid_t gid
= st
->stat
.st_gid
;
403 if (fd_chown (fd
, file_name
, uid
, gid
, atflag
) == 0)
405 /* Changing the owner can clear st_mode bits in some cases. */
406 if ((current_mode
| ~ current_mode_mask
) & S_IXUGO
)
407 current_mode_mask
&= ~ (current_mode
& (S_ISUID
| S_ISGID
));
409 else if (typeflag
!= SYMTYPE
|| implemented (errno
))
410 chown_error_details (file_name
, uid
, gid
);
414 st
->stat
.st_mode
& ~ current_umask
,
415 0 < same_permissions_option
&& ! interdir
? MODE_ALL
: MODE_RWX
,
416 fd
, current_mode
, current_mode_mask
, typeflag
, atflag
);
418 /* these three calls must be done *after* fd_chown() call because fd_chown
419 causes that linux capabilities becomes cleared. */
420 xattrs_xattrs_set (st
, file_name
, typeflag
, 1);
421 xattrs_acls_set (st
, file_name
, typeflag
);
422 xattrs_selinux_set (st
, file_name
, typeflag
);
425 /* For each entry H in the leading prefix of entries in HEAD that do
426 not have after_links marked, mark H and fill in its dev and ino
427 members. Assume HEAD && ! HEAD->after_links. */
429 mark_after_links (struct delayed_set_stat
*head
)
431 struct delayed_set_stat
*h
= head
;
438 if (deref_stat (h
->file_name
, &st
) != 0)
439 stat_error (h
->file_name
);
446 while ((h
= h
->next
) && ! h
->after_links
);
449 /* Remember to restore stat attributes (owner, group, mode and times)
450 for the directory FILE_NAME, using information given in *ST,
451 once we stop extracting files into that directory.
453 If ST is null, merely create a placeholder node for an intermediate
454 directory that was created by make_directories.
456 NOTICE: this works only if the archive has usual member order, i.e.
457 directory, then the files in that directory. Incremental archive have
458 somewhat reversed order: first go subdirectories, then all other
459 members. To help cope with this case the variable
460 delay_directory_restore_option is set by prepare_to_extract.
462 If an archive was explicitely created so that its member order is
463 reversed, some directory timestamps can be restored incorrectly,
465 tar --no-recursion -cf archive dir dir/file1 foo dir/file2
468 delay_set_stat (char const *file_name
, struct tar_stat_info
const *st
,
469 mode_t current_mode
, mode_t current_mode_mask
,
470 mode_t mode
, int atflag
)
472 size_t file_name_len
= strlen (file_name
);
473 struct delayed_set_stat
*data
=
474 xmalloc (offsetof (struct delayed_set_stat
, file_name
)
475 + file_name_len
+ 1);
476 data
->next
= delayed_set_stat_head
;
480 data
->dev
= st
->stat
.st_dev
;
481 data
->ino
= st
->stat
.st_ino
;
482 data
->uid
= st
->stat
.st_uid
;
483 data
->gid
= st
->stat
.st_gid
;
484 data
->atime
= st
->atime
;
485 data
->mtime
= st
->mtime
;
487 data
->file_name_len
= file_name_len
;
488 data
->current_mode
= current_mode
;
489 data
->current_mode_mask
= current_mode_mask
;
490 data
->interdir
= ! st
;
491 data
->atflag
= atflag
;
492 data
->after_links
= 0;
493 data
->change_dir
= chdir_current
;
494 data
->cntx_name
= NULL
;
496 assign_string (&data
->cntx_name
, st
->cntx_name
);
497 if (st
&& st
->acls_a_ptr
)
499 data
->acls_a_ptr
= xmemdup (st
->acls_a_ptr
, st
->acls_a_len
+ 1);
500 data
->acls_a_len
= st
->acls_a_len
;
504 data
->acls_a_ptr
= NULL
;
505 data
->acls_a_len
= 0;
507 if (st
&& st
->acls_d_ptr
)
509 data
->acls_d_ptr
= xmemdup (st
->acls_d_ptr
, st
->acls_d_len
+ 1);
510 data
->acls_d_len
= st
->acls_d_len
;
514 data
->acls_d_ptr
= NULL
;
515 data
->acls_d_len
= 0;
518 xheader_xattr_copy (st
, &data
->xattr_map
, &data
->xattr_map_size
);
521 data
->xattr_map
= NULL
;
522 data
->xattr_map_size
= 0;
524 strcpy (data
->file_name
, file_name
);
525 delayed_set_stat_head
= data
;
526 if (must_be_dot_or_slash (file_name
))
527 mark_after_links (data
);
530 /* Update the delayed_set_stat info for an intermediate directory
531 created within the file name of DIR. The intermediate directory turned
532 out to be the same as this directory, e.g. due to ".." or symbolic
533 links. *DIR_STAT_INFO is the status of the directory. */
535 repair_delayed_set_stat (char const *dir
,
536 struct stat
const *dir_stat_info
)
538 struct delayed_set_stat
*data
;
539 for (data
= delayed_set_stat_head
; data
; data
= data
->next
)
542 if (fstatat (chdir_fd
, data
->file_name
, &st
, data
->atflag
) != 0)
544 stat_error (data
->file_name
);
548 if (st
.st_dev
== dir_stat_info
->st_dev
549 && st
.st_ino
== dir_stat_info
->st_ino
)
551 data
->dev
= current_stat_info
.stat
.st_dev
;
552 data
->ino
= current_stat_info
.stat
.st_ino
;
553 data
->mode
= current_stat_info
.stat
.st_mode
;
554 data
->uid
= current_stat_info
.stat
.st_uid
;
555 data
->gid
= current_stat_info
.stat
.st_gid
;
556 data
->atime
= current_stat_info
.atime
;
557 data
->mtime
= current_stat_info
.mtime
;
558 data
->current_mode
= st
.st_mode
;
559 data
->current_mode_mask
= ALL_MODE_BITS
;
560 data
->interdir
= false;
565 ERROR ((0, 0, _("%s: Unexpected inconsistency when making directory"),
566 quotearg_colon (dir
)));
569 /* After a file/link/directory creation has failed, see if
570 it's because some required directory was not present, and if so,
571 create all required directories. Return zero if all the required
572 directories were created, nonzero (issuing a diagnostic) otherwise.
573 Set *INTERDIR_MADE if at least one directory was created. */
575 make_directories (char *file_name
, bool *interdir_made
)
577 char *cursor0
= file_name
+ FILE_SYSTEM_PREFIX_LEN (file_name
);
578 char *cursor
; /* points into the file name */
580 for (cursor
= cursor0
; *cursor
; cursor
++)
586 if (! ISSLASH (*cursor
))
589 /* Avoid mkdir of empty string, if leading or double '/'. */
591 if (cursor
== cursor0
|| ISSLASH (cursor
[-1]))
594 /* Avoid mkdir where last part of file name is "." or "..". */
596 if (cursor
[-1] == '.'
597 && (cursor
== cursor0
+ 1 || ISSLASH (cursor
[-2])
598 || (cursor
[-2] == '.'
599 && (cursor
== cursor0
+ 2 || ISSLASH (cursor
[-3])))))
602 *cursor
= '\0'; /* truncate the name there */
603 desired_mode
= MODE_RWX
& ~ newdir_umask
;
604 mode
= desired_mode
| (we_are_root
? 0 : MODE_WXUSR
);
605 status
= mkdirat (chdir_fd
, file_name
, mode
);
609 /* Create a struct delayed_set_stat even if
610 mode == desired_mode, because
611 repair_delayed_set_stat may need to update the struct. */
612 delay_set_stat (file_name
,
613 0, mode
& ~ current_umask
, MODE_RWX
,
614 desired_mode
, AT_SYMLINK_NOFOLLOW
);
616 print_for_mkdir (file_name
, cursor
- file_name
, desired_mode
);
617 *interdir_made
= true;
619 else if (errno
== EEXIST
)
623 /* Check whether the desired file exists. Even when the
624 file exists, mkdir can fail with some errno value E other
625 than EEXIST, so long as E describes an error condition
626 that also applies. */
629 status
= fstatat (chdir_fd
, file_name
, &st
, 0);
633 mkdir_error (file_name
);
645 /* Return true if FILE_NAME (with status *STP, if STP) is not a
646 directory, and has a time stamp newer than (or equal to) that of
649 file_newer_p (const char *file_name
, struct stat
const *stp
,
650 struct tar_stat_info
*tar_stat
)
656 if (deref_stat (file_name
, &st
) != 0)
660 stat_warn (file_name
);
661 /* Be safer: if the file exists, assume it is newer. */
669 return (! S_ISDIR (stp
->st_mode
)
670 && tar_timespec_cmp (tar_stat
->mtime
, get_stat_mtime (stp
)) <= 0);
675 #define RECOVER_SKIP 2
677 /* Attempt repairing what went wrong with the extraction. Delete an
678 already existing file or create missing intermediate directories.
679 Return RECOVER_OK if we somewhat increased our chances at a successful
680 extraction, RECOVER_NO if there are no chances, and RECOVER_SKIP if the
681 caller should skip extraction of that member. The value of errno is
682 properly restored on returning RECOVER_NO.
684 If REGULAR, the caller was trying to extract onto a regular file.
686 Set *INTERDIR_MADE if an intermediate directory is made as part of
687 the recovery process. */
690 maybe_recoverable (char *file_name
, bool regular
, bool *interdir_made
)
694 struct stat
const *stp
= 0;
703 /* With open ("symlink", O_NOFOLLOW|...), POSIX says errno == ELOOP,
704 but some operating systems do not conform to the standard. */
706 /* NetBSD uses errno == EFTYPE; see <http://gnats.netbsd.org/43154>. */
709 /* FreeBSD 8.1 uses errno == EMLINK. */
711 /* Tru64 5.1B uses errno == ENOTSUP. */
715 || old_files_option
!= OVERWRITE_OLD_FILES
|| dereference_option
)
717 if (strchr (file_name
, '/'))
719 if (deref_stat (file_name
, &st
) != 0)
724 /* The caller tried to open a symbolic link with O_NOFOLLOW.
725 Fall through, treating it as an already-existing file. */
728 /* Remove an old file, if the options allow this. */
730 switch (old_files_option
)
733 WARNOPT (WARN_EXISTING_FILE
,
734 (0, 0, _("%s: skipping existing file"), file_name
));
740 case KEEP_NEWER_FILES
:
741 if (file_newer_p (file_name
, stp
, ¤t_stat_info
))
745 case DEFAULT_OLD_FILES
:
746 case NO_OVERWRITE_DIR_OLD_FILES
:
747 case OVERWRITE_OLD_FILES
:
748 if (0 < remove_any_file (file_name
, ORDINARY_REMOVE_OPTION
))
752 case UNLINK_FIRST_OLD_FILES
:
757 /* Attempt creating missing intermediate directories. */
758 if (make_directories (file_name
, interdir_made
) == 0 && *interdir_made
)
763 /* Just say we can't do anything about it... */
771 /* Restore stat extended attributes (xattr) for FILE_NAME, using information
772 given in *ST. Restore before extraction because they may affect file layout
773 (e.g. on Lustre distributed parallel filesystem - setting info about how many
774 servers is this file striped over, stripe size, mirror copies, etc.
775 in advance dramatically improves the following performance of reading and
776 writing a file). If not restoring permissions, invert the INVERT_PERMISSIONS
777 bits from the file's current permissions. TYPEFLAG specifies the type of the
778 file. FILE_CREATED indicates set_xattr has created the file */
780 set_xattr (char const *file_name
, struct tar_stat_info
const *st
,
781 mode_t invert_permissions
, char typeflag
, int *file_created
)
786 bool interdir_made
= false;
788 if ((xattrs_option
> 0) && st
->xattr_map_size
)
790 mode_t mode
= current_stat_info
.stat
.st_mode
& MODE_RWX
& ~ current_umask
;
793 status
= mknodat (chdir_fd
, file_name
, mode
^ invert_permissions
, 0);
794 while (status
&& maybe_recoverable ((char *)file_name
, false,
797 xattrs_xattrs_set (st
, file_name
, typeflag
, 0);
805 /* Fix the statuses of all directories whose statuses need fixing, and
806 which are not ancestors of FILE_NAME. If AFTER_LINKS is
807 nonzero, do this for all such directories; otherwise, stop at the
808 first directory that is marked to be fixed up only after delayed
809 links are applied. */
811 apply_nonancestor_delayed_set_stat (char const *file_name
, bool after_links
)
813 size_t file_name_len
= strlen (file_name
);
814 bool check_for_renamed_directories
= 0;
816 while (delayed_set_stat_head
)
818 struct delayed_set_stat
*data
= delayed_set_stat_head
;
819 bool skip_this_one
= 0;
821 mode_t current_mode
= data
->current_mode
;
822 mode_t current_mode_mask
= data
->current_mode_mask
;
824 check_for_renamed_directories
|= data
->after_links
;
826 if (after_links
< data
->after_links
827 || (data
->file_name_len
< file_name_len
828 && file_name
[data
->file_name_len
]
829 && (ISSLASH (file_name
[data
->file_name_len
])
830 || ISSLASH (file_name
[data
->file_name_len
- 1]))
831 && memcmp (file_name
, data
->file_name
, data
->file_name_len
) == 0))
834 chdir_do (data
->change_dir
);
836 if (check_for_renamed_directories
)
838 if (fstatat (chdir_fd
, data
->file_name
, &st
, data
->atflag
) != 0)
840 stat_error (data
->file_name
);
845 current_mode
= st
.st_mode
;
846 current_mode_mask
= ALL_MODE_BITS
;
847 if (! (st
.st_dev
== data
->dev
&& st
.st_ino
== data
->ino
))
850 _("%s: Directory renamed before its status could be extracted"),
851 quotearg_colon (data
->file_name
)));
859 struct tar_stat_info sb
;
860 sb
.stat
.st_mode
= data
->mode
;
861 sb
.stat
.st_uid
= data
->uid
;
862 sb
.stat
.st_gid
= data
->gid
;
863 sb
.atime
= data
->atime
;
864 sb
.mtime
= data
->mtime
;
865 sb
.cntx_name
= data
->cntx_name
;
866 sb
.acls_a_ptr
= data
->acls_a_ptr
;
867 sb
.acls_a_len
= data
->acls_a_len
;
868 sb
.acls_d_ptr
= data
->acls_d_ptr
;
869 sb
.acls_d_len
= data
->acls_d_len
;
870 sb
.xattr_map
= data
->xattr_map
;
871 sb
.xattr_map_size
= data
->xattr_map_size
;
872 set_stat (data
->file_name
, &sb
,
873 -1, current_mode
, current_mode_mask
,
874 DIRTYPE
, data
->interdir
, data
->atflag
);
877 delayed_set_stat_head
= data
->next
;
878 xheader_xattr_free (data
->xattr_map
, data
->xattr_map_size
);
879 free (data
->cntx_name
);
880 free (data
->acls_a_ptr
);
881 free (data
->acls_d_ptr
);
888 is_directory_link (const char *file_name
)
894 res
= (fstatat (chdir_fd
, file_name
, &st
, AT_SYMLINK_NOFOLLOW
) == 0 &&
895 S_ISLNK (st
.st_mode
) &&
896 fstatat (chdir_fd
, file_name
, &st
, 0) == 0 &&
897 S_ISDIR (st
.st_mode
));
902 /* Extractor functions for various member types */
905 extract_dir (char *file_name
, int typeflag
)
909 mode_t current_mode
= 0;
910 mode_t current_mode_mask
= 0;
912 bool interdir_made
= false;
914 /* Save 'root device' to avoid purging mount points. */
915 if (one_file_system_option
&& root_device
== 0)
919 if (fstatat (chdir_fd
, ".", &st
, 0) != 0)
922 root_device
= st
.st_dev
;
925 if (incremental_option
)
926 /* Read the entry and delete files that aren't listed in the archive. */
927 purge_directory (file_name
);
928 else if (typeflag
== GNUTYPE_DUMPDIR
)
931 /* If ownership or permissions will be restored later, create the
932 directory with restrictive permissions at first, so that in the
933 meantime processes owned by other users do not inadvertently
934 create files under this directory that inherit the wrong owner,
935 group, or permissions from the directory. If not root, though,
936 make the directory writeable and searchable at first, so that
937 files can be created under it. */
938 mode
= ((current_stat_info
.stat
.st_mode
939 & (0 < same_owner_option
|| 0 < same_permissions_option
942 | (we_are_root
? 0 : MODE_WXUSR
));
946 status
= mkdirat (chdir_fd
, file_name
, mode
);
949 current_mode
= mode
& ~ current_umask
;
950 current_mode_mask
= MODE_RWX
;
951 atflag
= AT_SYMLINK_NOFOLLOW
;
957 || keep_directory_symlink_option
958 || old_files_option
== DEFAULT_OLD_FILES
959 || old_files_option
== OVERWRITE_OLD_FILES
))
963 if (keep_directory_symlink_option
&& is_directory_link (file_name
))
966 if (deref_stat (file_name
, &st
) == 0)
968 current_mode
= st
.st_mode
;
969 current_mode_mask
= ALL_MODE_BITS
;
971 if (S_ISDIR (current_mode
))
975 repair_delayed_set_stat (file_name
, &st
);
984 switch (maybe_recoverable (file_name
, false, &interdir_made
))
995 mkdir_error (file_name
);
1004 || old_files_option
== DEFAULT_OLD_FILES
1005 || old_files_option
== OVERWRITE_OLD_FILES
)
1006 delay_set_stat (file_name
, ¤t_stat_info
,
1007 current_mode
, current_mode_mask
,
1008 current_stat_info
.stat
.st_mode
, atflag
);
1015 open_output_file (char const *file_name
, int typeflag
, mode_t mode
,
1016 int file_created
, mode_t
*current_mode
,
1017 mode_t
*current_mode_mask
)
1020 bool overwriting_old_files
= old_files_option
== OVERWRITE_OLD_FILES
;
1021 int openflag
= (O_WRONLY
| O_BINARY
| O_CLOEXEC
| O_NOCTTY
| O_NONBLOCK
1023 | (overwriting_old_files
1024 ? O_TRUNC
| (dereference_option
? 0 : O_NOFOLLOW
)
1027 /* File might be created in set_xattr. So clear O_EXCL to avoid open() fail */
1029 openflag
= openflag
& ~O_EXCL
;
1031 if (typeflag
== CONTTYPE
)
1033 static int conttype_diagnosed
;
1035 if (!conttype_diagnosed
)
1037 conttype_diagnosed
= 1;
1038 WARNOPT (WARN_CONTIGUOUS_CAST
,
1039 (0, 0, _("Extracting contiguous files as regular files")));
1043 /* If O_NOFOLLOW is needed but does not work, check for a symlink
1044 separately. There's a race condition, but that cannot be avoided
1045 on hosts lacking O_NOFOLLOW. */
1046 if (! HAVE_WORKING_O_NOFOLLOW
1047 && overwriting_old_files
&& ! dereference_option
)
1050 if (fstatat (chdir_fd
, file_name
, &st
, AT_SYMLINK_NOFOLLOW
) == 0
1051 && S_ISLNK (st
.st_mode
))
1058 fd
= openat (chdir_fd
, file_name
, openflag
, mode
);
1061 if (overwriting_old_files
)
1064 if (fstat (fd
, &st
) != 0)
1071 if (! S_ISREG (st
.st_mode
))
1077 *current_mode
= st
.st_mode
;
1078 *current_mode_mask
= ALL_MODE_BITS
;
1082 *current_mode
= mode
& ~ current_umask
;
1083 *current_mode_mask
= MODE_RWX
;
1091 extract_file (char *file_name
, int typeflag
)
1095 union block
*data_block
;
1099 bool interdir_made
= false;
1100 mode_t mode
= (current_stat_info
.stat
.st_mode
& MODE_RWX
1101 & ~ (0 < same_owner_option
? S_IRWXG
| S_IRWXO
: 0));
1102 mode_t invert_permissions
= 0 < same_owner_option
? mode
& (S_IRWXG
| S_IRWXO
)
1104 mode_t current_mode
= 0;
1105 mode_t current_mode_mask
= 0;
1107 if (to_stdout_option
)
1109 else if (to_command_option
)
1111 fd
= sys_exec_command (file_name
, 'f', ¤t_stat_info
);
1120 int file_created
= 0;
1121 if (set_xattr (file_name
, ¤t_stat_info
, invert_permissions
,
1122 typeflag
, &file_created
))
1125 open_error (file_name
);
1129 while ((fd
= open_output_file (file_name
, typeflag
, mode
,
1130 file_created
, ¤t_mode
,
1131 ¤t_mode_mask
))
1134 int recover
= maybe_recoverable (file_name
, true, &interdir_made
);
1135 if (recover
!= RECOVER_OK
)
1138 if (recover
== RECOVER_SKIP
)
1140 open_error (file_name
);
1146 mv_begin_read (¤t_stat_info
);
1147 if (current_stat_info
.is_sparse
)
1148 sparse_extract_file (fd
, ¤t_stat_info
, &size
);
1150 for (size
= current_stat_info
.stat
.st_size
; size
> 0; )
1152 mv_size_left (size
);
1154 /* Locate data, determine max length writeable, write it,
1155 block that we have used the data, then check if the write
1158 data_block
= find_next_block ();
1161 ERROR ((0, 0, _("Unexpected EOF in archive")));
1162 break; /* FIXME: What happens, then? */
1165 written
= available_space_after (data_block
);
1170 count
= blocking_write (fd
, data_block
->buffer
, written
);
1173 set_next_block_after ((union block
*)
1174 (data_block
->buffer
+ written
- 1));
1175 if (count
!= written
)
1177 if (!to_command_option
)
1178 write_error_details (file_name
, count
, written
);
1179 /* FIXME: shouldn't we restore from backup? */
1188 /* If writing to stdout, don't try to do anything to the filename;
1189 it doesn't exist, or we don't want to touch it anyway. */
1191 if (to_stdout_option
)
1194 if (! to_command_option
)
1195 set_stat (file_name
, ¤t_stat_info
, fd
,
1196 current_mode
, current_mode_mask
, typeflag
, false,
1197 (old_files_option
== OVERWRITE_OLD_FILES
1198 ? 0 : AT_SYMLINK_NOFOLLOW
));
1200 status
= close (fd
);
1202 close_error (file_name
);
1204 if (to_command_option
)
1205 sys_wait_command ();
1210 /* Create a placeholder file with name FILE_NAME, which will be
1211 replaced after other extraction is done by a symbolic link if
1212 IS_SYMLINK is true, and by a hard link otherwise. Set
1213 *INTERDIR_MADE if an intermediate directory is made in the
1217 create_placeholder_file (char *file_name
, bool is_symlink
, bool *interdir_made
)
1222 while ((fd
= openat (chdir_fd
, file_name
, O_WRONLY
| O_CREAT
| O_EXCL
, 0)) < 0)
1224 switch (maybe_recoverable (file_name
, false, interdir_made
))
1233 open_error (file_name
);
1238 if (fstat (fd
, &st
) != 0)
1240 stat_error (file_name
);
1243 else if (close (fd
) != 0)
1244 close_error (file_name
);
1247 struct delayed_set_stat
*h
;
1248 struct delayed_link
*p
=
1249 xmalloc (offsetof (struct delayed_link
, target
)
1250 + strlen (current_stat_info
.link_name
)
1252 p
->next
= delayed_link_head
;
1253 delayed_link_head
= p
;
1256 p
->birthtime
= get_stat_birthtime (&st
);
1257 p
->is_symlink
= is_symlink
;
1260 p
->mode
= current_stat_info
.stat
.st_mode
;
1261 p
->uid
= current_stat_info
.stat
.st_uid
;
1262 p
->gid
= current_stat_info
.stat
.st_gid
;
1263 p
->atime
= current_stat_info
.atime
;
1264 p
->mtime
= current_stat_info
.mtime
;
1266 p
->change_dir
= chdir_current
;
1267 p
->sources
= xmalloc (offsetof (struct string_list
, string
)
1268 + strlen (file_name
) + 1);
1269 p
->sources
->next
= 0;
1270 strcpy (p
->sources
->string
, file_name
);
1271 p
->cntx_name
= NULL
;
1272 assign_string (&p
->cntx_name
, current_stat_info
.cntx_name
);
1273 p
->acls_a_ptr
= NULL
;
1275 p
->acls_d_ptr
= NULL
;
1277 xheader_xattr_copy (¤t_stat_info
, &p
->xattr_map
, &p
->xattr_map_size
);
1278 strcpy (p
->target
, current_stat_info
.link_name
);
1280 h
= delayed_set_stat_head
;
1281 if (h
&& ! h
->after_links
1282 && strncmp (file_name
, h
->file_name
, h
->file_name_len
) == 0
1283 && ISSLASH (file_name
[h
->file_name_len
])
1284 && (last_component (file_name
) == file_name
+ h
->file_name_len
+ 1))
1285 mark_after_links (h
);
1294 extract_link (char *file_name
, int typeflag
)
1296 bool interdir_made
= false;
1297 char const *link_name
;
1300 link_name
= current_stat_info
.link_name
;
1302 if (! absolute_names_option
&& contains_dot_dot (link_name
))
1303 return create_placeholder_file (file_name
, false, &interdir_made
);
1307 struct stat st1
, st2
;
1309 int status
= linkat (chdir_fd
, link_name
, chdir_fd
, file_name
, 0);
1314 struct delayed_link
*ds
= delayed_link_head
;
1316 && fstatat (chdir_fd
, link_name
, &st1
, AT_SYMLINK_NOFOLLOW
) == 0)
1317 for (; ds
; ds
= ds
->next
)
1318 if (ds
->change_dir
== chdir_current
1319 && ds
->dev
== st1
.st_dev
1320 && ds
->ino
== st1
.st_ino
1321 && (timespec_cmp (ds
->birthtime
, get_stat_birthtime (&st1
))
1324 struct string_list
*p
= xmalloc (offsetof (struct string_list
, string
)
1325 + strlen (file_name
) + 1);
1326 strcpy (p
->string
, file_name
);
1327 p
->next
= ds
->sources
;
1333 else if ((e
== EEXIST
&& strcmp (link_name
, file_name
) == 0)
1334 || ((fstatat (chdir_fd
, link_name
, &st1
, AT_SYMLINK_NOFOLLOW
)
1336 && (fstatat (chdir_fd
, file_name
, &st2
, AT_SYMLINK_NOFOLLOW
)
1338 && st1
.st_dev
== st2
.st_dev
1339 && st1
.st_ino
== st2
.st_ino
))
1344 while ((rc
= maybe_recoverable (file_name
, false, &interdir_made
))
1347 if (rc
== RECOVER_SKIP
)
1349 if (!(incremental_option
&& errno
== EEXIST
))
1351 link_error (link_name
, file_name
);
1358 extract_symlink (char *file_name
, int typeflag
)
1361 bool interdir_made
= false;
1363 if (! absolute_names_option
1364 && (IS_ABSOLUTE_FILE_NAME (current_stat_info
.link_name
)
1365 || contains_dot_dot (current_stat_info
.link_name
)))
1366 return create_placeholder_file (file_name
, true, &interdir_made
);
1368 while (symlinkat (current_stat_info
.link_name
, chdir_fd
, file_name
) != 0)
1369 switch (maybe_recoverable (file_name
, false, &interdir_made
))
1378 symlink_error (current_stat_info
.link_name
, file_name
);
1382 set_stat (file_name
, ¤t_stat_info
, -1, 0, 0,
1383 SYMTYPE
, false, AT_SYMLINK_NOFOLLOW
);
1387 static int warned_once
;
1392 WARNOPT (WARN_SYMLINK_CAST
,
1394 _("Attempting extraction of symbolic links as hard links")));
1396 return extract_link (file_name
, typeflag
);
1400 #if S_IFCHR || S_IFBLK
1402 extract_node (char *file_name
, int typeflag
)
1404 bool interdir_made
= false;
1405 mode_t mode
= (current_stat_info
.stat
.st_mode
& (MODE_RWX
| S_IFBLK
| S_IFCHR
)
1406 & ~ (0 < same_owner_option
? S_IRWXG
| S_IRWXO
: 0));
1408 while (mknodat (chdir_fd
, file_name
, mode
, current_stat_info
.stat
.st_rdev
)
1410 switch (maybe_recoverable (file_name
, false, &interdir_made
))
1419 mknod_error (file_name
);
1423 set_stat (file_name
, ¤t_stat_info
, -1,
1424 mode
& ~ current_umask
, MODE_RWX
,
1425 typeflag
, false, AT_SYMLINK_NOFOLLOW
);
1430 #if HAVE_MKFIFO || defined mkfifo
1432 extract_fifo (char *file_name
, int typeflag
)
1434 bool interdir_made
= false;
1435 mode_t mode
= (current_stat_info
.stat
.st_mode
& MODE_RWX
1436 & ~ (0 < same_owner_option
? S_IRWXG
| S_IRWXO
: 0));
1438 while (mkfifoat (chdir_fd
, file_name
, mode
) != 0)
1439 switch (maybe_recoverable (file_name
, false, &interdir_made
))
1448 mkfifo_error (file_name
);
1452 set_stat (file_name
, ¤t_stat_info
, -1,
1453 mode
& ~ current_umask
, MODE_RWX
,
1454 typeflag
, false, AT_SYMLINK_NOFOLLOW
);
1460 extract_volhdr (char *file_name
, int typeflag
)
1467 extract_failure (char *file_name
, int typeflag
)
1473 extract_skip (char *file_name
, int typeflag
)
1479 typedef int (*tar_extractor_t
) (char *file_name
, int typeflag
);
1483 /* Prepare to extract a file. Find extractor function.
1484 Return zero if extraction should not proceed. */
1487 prepare_to_extract (char const *file_name
, int typeflag
, tar_extractor_t
*fun
)
1491 if (EXTRACT_OVER_PIPE
)
1494 /* Select the extractor */
1497 case GNUTYPE_SPARSE
:
1498 *fun
= extract_file
;
1505 /* Appears to be a file. But BSD tar uses the convention that a slash
1506 suffix means a directory. */
1507 if (current_stat_info
.had_trailing_slash
)
1511 *fun
= extract_file
;
1517 *fun
= extract_symlink
;
1521 *fun
= extract_link
;
1526 current_stat_info
.stat
.st_mode
|= S_IFCHR
;
1527 *fun
= extract_node
;
1533 current_stat_info
.stat
.st_mode
|= S_IFBLK
;
1534 *fun
= extract_node
;
1538 #if HAVE_MKFIFO || defined mkfifo
1540 *fun
= extract_fifo
;
1545 case GNUTYPE_DUMPDIR
:
1547 if (current_stat_info
.is_dumpdir
)
1548 delay_directory_restore_option
= true;
1551 case GNUTYPE_VOLHDR
:
1552 *fun
= extract_volhdr
;
1555 case GNUTYPE_MULTIVOL
:
1557 _("%s: Cannot extract -- file is continued from another volume"),
1558 quotearg_colon (current_stat_info
.file_name
)));
1559 *fun
= extract_skip
;
1562 case GNUTYPE_LONGNAME
:
1563 case GNUTYPE_LONGLINK
:
1564 ERROR ((0, 0, _("Unexpected long name header")));
1565 *fun
= extract_failure
;
1569 WARNOPT (WARN_UNKNOWN_CAST
,
1571 _("%s: Unknown file type '%c', extracted as normal file"),
1572 quotearg_colon (file_name
), typeflag
));
1573 *fun
= extract_file
;
1576 /* Determine whether the extraction should proceed */
1580 switch (old_files_option
)
1582 case UNLINK_FIRST_OLD_FILES
:
1583 if (!remove_any_file (file_name
,
1584 recursive_unlink_option
? RECURSIVE_REMOVE_OPTION
1585 : ORDINARY_REMOVE_OPTION
)
1586 && errno
&& errno
!= ENOENT
)
1588 unlink_error (file_name
);
1593 case KEEP_NEWER_FILES
:
1594 if (file_newer_p (file_name
, 0, ¤t_stat_info
))
1596 WARNOPT (WARN_IGNORE_NEWER
,
1597 (0, 0, _("Current %s is newer or same age"),
1598 quote (file_name
)));
1611 maybe_prepend_name (char **file_name
)
1615 for (i
= 0; i
< strlen (*file_name
); i
++)
1616 if (!ISSLASH ((*file_name
)[i
]) && (*file_name
)[i
] != '.') break;
1618 if (i
== strlen (*file_name
))
1621 if (!strncmp (*file_name
+ i
, one_top_level
, strlen (one_top_level
)))
1623 int pos
= i
+ strlen (one_top_level
);
1624 if (ISSLASH ((*file_name
)[pos
]) || (*file_name
)[pos
] == '\0') return;
1627 char *new_name
= xmalloc (strlen (one_top_level
) + strlen (*file_name
) + 2);
1629 strcpy (new_name
, one_top_level
);
1630 strcat (new_name
, "/");
1631 strcat (new_name
, *file_name
);
1634 *file_name
= new_name
;
1637 /* Extract a file from the archive. */
1639 extract_archive (void)
1642 tar_extractor_t fun
;
1644 fatal_exit_hook
= extract_finish
;
1646 set_next_block_after (current_header
);
1648 if (!current_stat_info
.file_name
[0]
1649 || (interactive_option
1650 && !confirm ("extract", current_stat_info
.file_name
)))
1656 /* Print the block from current_header and current_stat. */
1658 print_header (¤t_stat_info
, current_header
, -1);
1660 /* Restore stats for all non-ancestor directories, unless
1661 it is an incremental archive.
1662 (see NOTICE in the comment to delay_set_stat above) */
1663 if (!delay_directory_restore_option
)
1665 int dir
= chdir_current
;
1666 apply_nonancestor_delayed_set_stat (current_stat_info
.file_name
, 0);
1670 /* Take a safety backup of a previously existing file. */
1673 if (!maybe_backup_file (current_stat_info
.file_name
, 0))
1676 ERROR ((0, e
, _("%s: Was unable to backup this file"),
1677 quotearg_colon (current_stat_info
.file_name
)));
1682 /* Extract the archive entry according to its type. */
1684 typeflag
= sparse_member_p (¤t_stat_info
) ?
1685 GNUTYPE_SPARSE
: current_header
->header
.typeflag
;
1687 if (one_top_level_option
)
1688 maybe_prepend_name (¤t_stat_info
.file_name
);
1690 if (prepare_to_extract (current_stat_info
.file_name
, typeflag
, &fun
))
1692 if (fun
&& (*fun
) (current_stat_info
.file_name
, typeflag
)
1694 undo_last_backup ();
1701 /* Extract the links whose final extraction were delayed. */
1703 apply_delayed_links (void)
1705 struct delayed_link
*ds
;
1707 for (ds
= delayed_link_head
; ds
; )
1709 struct string_list
*sources
= ds
->sources
;
1710 char const *valid_source
= 0;
1712 chdir_do (ds
->change_dir
);
1714 for (sources
= ds
->sources
; sources
; sources
= sources
->next
)
1716 char const *source
= sources
->string
;
1719 /* Make sure the placeholder file is still there. If not,
1720 don't create a link, as the placeholder was probably
1721 removed by a later extraction. */
1722 if (fstatat (chdir_fd
, source
, &st
, AT_SYMLINK_NOFOLLOW
) == 0
1723 && st
.st_dev
== ds
->dev
1724 && st
.st_ino
== ds
->ino
1725 && timespec_cmp (get_stat_birthtime (&st
), ds
->birthtime
) == 0)
1727 /* Unlink the placeholder, then create a hard link if possible,
1728 a symbolic link otherwise. */
1729 if (unlinkat (chdir_fd
, source
, 0) != 0)
1730 unlink_error (source
);
1731 else if (valid_source
1732 && (linkat (chdir_fd
, valid_source
, chdir_fd
, source
, 0)
1735 else if (!ds
->is_symlink
)
1737 if (linkat (chdir_fd
, ds
->target
, chdir_fd
, source
, 0) != 0)
1738 link_error (ds
->target
, source
);
1740 else if (symlinkat (ds
->target
, chdir_fd
, source
) != 0)
1741 symlink_error (ds
->target
, source
);
1744 struct tar_stat_info st1
;
1745 st1
.stat
.st_mode
= ds
->mode
;
1746 st1
.stat
.st_uid
= ds
->uid
;
1747 st1
.stat
.st_gid
= ds
->gid
;
1748 st1
.atime
= ds
->atime
;
1749 st1
.mtime
= ds
->mtime
;
1750 st1
.cntx_name
= ds
->cntx_name
;
1751 st1
.acls_a_ptr
= ds
->acls_a_ptr
;
1752 st1
.acls_a_len
= ds
->acls_a_len
;
1753 st1
.acls_d_ptr
= ds
->acls_d_ptr
;
1754 st1
.acls_d_len
= ds
->acls_d_len
;
1755 st1
.xattr_map
= ds
->xattr_map
;
1756 st1
.xattr_map_size
= ds
->xattr_map_size
;
1757 set_stat (source
, &st1
, -1, 0, 0, SYMTYPE
,
1758 false, AT_SYMLINK_NOFOLLOW
);
1759 valid_source
= source
;
1764 for (sources
= ds
->sources
; sources
; )
1766 struct string_list
*next
= sources
->next
;
1771 xheader_xattr_free (ds
->xattr_map
, ds
->xattr_map_size
);
1772 free (ds
->cntx_name
);
1775 struct delayed_link
*next
= ds
->next
;
1781 delayed_link_head
= 0;
1784 /* Finish the extraction of an archive. */
1786 extract_finish (void)
1788 /* First, fix the status of ordinary directories that need fixing. */
1789 apply_nonancestor_delayed_set_stat ("", 0);
1791 /* Then, apply delayed links, so that they don't affect delayed
1792 directory status-setting for ordinary directories. */
1793 apply_delayed_links ();
1795 /* Finally, fix the status of directories that are ancestors
1796 of delayed links. */
1797 apply_nonancestor_delayed_set_stat ("", 1);
1801 rename_directory (char *src
, char *dst
)
1803 if (renameat (chdir_fd
, src
, chdir_fd
, dst
) != 0)
1811 if (make_directories (dst
, &interdir_made
) == 0)
1813 if (renameat (chdir_fd
, src
, chdir_fd
, dst
) == 0)
1820 /* FIXME: Fall back to recursive copying */
1826 ERROR ((0, e
, _("Cannot rename %s to %s"),