1 /* Extract files from a tar archive.
3 Copyright 1988-2019 Free Software Foundation, Inc.
5 This file is part of GNU tar.
7 GNU tar is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 GNU tar is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 Written by John Gilmore, on 1985-11-19. */
31 static bool we_are_root
; /* true if our effective uid == 0 */
32 static mode_t newdir_umask
; /* umask when creating new directories */
33 static mode_t current_umask
; /* current umask (which is set to 0 if -p) */
35 #define ALL_MODE_BITS ((mode_t) ~ (mode_t) 0)
37 #if ! HAVE_FCHMOD && ! defined fchmod
38 # define fchmod(fd, mode) (errno = ENOSYS, -1)
40 #if ! HAVE_FCHOWN && ! defined fchown
41 # define fchown(fd, uid, gid) (errno = ENOSYS, -1)
44 /* Return true if an error number ERR means the system call is
45 supported in this case. */
49 return ! (err
== ENOSYS
51 || (EOPNOTSUPP
!= ENOTSUP
&& err
== EOPNOTSUPP
));
54 /* List of directories whose statuses we need to extract after we've
55 finished extracting their subsidiary files. If you consider each
56 contiguous subsequence of elements of the form [D]?[^D]*, where [D]
57 represents an element where AFTER_LINKS is nonzero and [^D]
58 represents an element where AFTER_LINKS is zero, then the head
59 of the subsequence has the longest name, and each non-head element
60 in the prefix is an ancestor (in the directory hierarchy) of the
63 struct delayed_set_stat
65 /* Next directory in list. */
66 struct delayed_set_stat
*next
;
68 /* Metadata for this directory. */
71 mode_t mode
; /* The desired mode is MODE & ~ current_umask. */
74 struct timespec atime
;
75 struct timespec mtime
;
77 /* An estimate of the directory's current mode, along with a mask
78 specifying which bits of this estimate are known to be correct.
79 If CURRENT_MODE_MASK is zero, CURRENT_MODE's value doesn't
82 mode_t current_mode_mask
;
84 /* This directory is an intermediate directory that was created
85 as an ancestor of some other directory; it was not mentioned
86 in the archive, so do not set its uid, gid, atime, or mtime,
87 and don't alter its mode outside of MODE_RWX. */
90 /* Whether symbolic links should be followed when accessing the
94 /* Do not set the status of this directory until after delayed
98 /* Directory that the name is relative to. */
101 /* extended attributes*/
107 size_t xattr_map_size
;
108 struct xattr_array
*xattr_map
;
109 /* Length and contents of name. */
110 size_t file_name_len
;
114 static struct delayed_set_stat
*delayed_set_stat_head
;
116 /* List of links whose creation we have delayed. */
119 /* The next delayed link in the list. */
120 struct delayed_link
*next
;
122 /* The device, inode number and birthtime of the placeholder.
123 birthtime.tv_nsec is negative if the birthtime is not available.
124 Don't use mtime as this would allow for false matches if some
125 other process removes the placeholder. Don't use ctime as
126 this would cause race conditions and other screwups, e.g.,
127 when restoring hard-linked symlinks. */
130 struct timespec birthtime
;
132 /* True if the link is symbolic. */
135 /* The desired metadata, valid only the link is symbolic. */
139 struct timespec atime
;
140 struct timespec mtime
;
142 /* The directory that the sources and target are relative to. */
145 /* A list of sources for this link. The sources are all to be
146 hard-linked together. */
147 struct string_list
*sources
;
149 /* SELinux context */
158 size_t xattr_map_size
;
159 struct xattr_array
*xattr_map
;
161 /* The desired target of the desired link. */
165 static struct delayed_link
*delayed_link_head
;
169 struct string_list
*next
;
173 /* Set up to extract files. */
177 we_are_root
= geteuid () == ROOT_UID
;
178 same_permissions_option
+= we_are_root
;
179 same_owner_option
+= we_are_root
;
181 /* Option -p clears the kernel umask, so it does not affect proper
182 restoration of file permissions. New intermediate directories will
183 comply with umask at start of program. */
185 newdir_umask
= umask (0);
186 if (0 < same_permissions_option
)
190 umask (newdir_umask
); /* restore the kernel umask */
191 current_umask
= newdir_umask
;
195 /* Use fchmod if possible, fchmodat otherwise. */
197 fd_chmod (int fd
, char const *file
, mode_t mode
, int atflag
)
201 int result
= fchmod (fd
, mode
);
202 if (result
== 0 || implemented (errno
))
205 return fchmodat (chdir_fd
, file
, mode
, atflag
);
208 /* Use fchown if possible, fchownat otherwise. */
210 fd_chown (int fd
, char const *file
, uid_t uid
, gid_t gid
, int atflag
)
214 int result
= fchown (fd
, uid
, gid
);
215 if (result
== 0 || implemented (errno
))
218 return fchownat (chdir_fd
, file
, uid
, gid
, atflag
);
221 /* Use fstat if possible, fstatat otherwise. */
223 fd_stat (int fd
, char const *file
, struct stat
*st
, int atflag
)
227 : fstatat (chdir_fd
, file
, st
, atflag
));
230 /* Set the mode for FILE_NAME to MODE.
231 MODE_MASK specifies the bits of MODE that we care about;
232 thus if MODE_MASK is zero, do nothing.
233 If FD is nonnegative, it is a file descriptor for the file.
234 CURRENT_MODE and CURRENT_MODE_MASK specify information known about
235 the file's current mode, using the style of struct delayed_set_stat.
236 TYPEFLAG specifies the type of the file.
237 ATFLAG specifies the flag to use when statting the file. */
239 set_mode (char const *file_name
,
240 mode_t mode
, mode_t mode_mask
, int fd
,
241 mode_t current_mode
, mode_t current_mode_mask
,
242 char typeflag
, int atflag
)
244 if (((current_mode
^ mode
) | ~ current_mode_mask
) & mode_mask
)
246 if (MODE_ALL
& ~ mode_mask
& ~ current_mode_mask
)
249 if (fd_stat (fd
, file_name
, &st
, atflag
) != 0)
251 stat_error (file_name
);
254 current_mode
= st
.st_mode
;
257 current_mode
&= MODE_ALL
;
258 mode
= (current_mode
& ~ mode_mask
) | (mode
& mode_mask
);
260 if (current_mode
!= mode
)
263 fd_chmod (fd
, file_name
, mode
, atflag
) == 0 ? 0 : errno
;
265 /* On Solaris, chmod may fail if we don't have PRIV_ALL, because
266 setuid-root files would otherwise be a backdoor. See
267 http://opensolaris.org/jive/thread.jspa?threadID=95826
269 if (chmod_errno
== EPERM
&& (mode
& S_ISUID
)
270 && priv_set_restore_linkdir () == 0)
273 fd_chmod (fd
, file_name
, mode
, atflag
) == 0 ? 0 : errno
;
274 priv_set_remove_linkdir ();
277 /* Linux fchmodat does not support AT_SYMLINK_NOFOLLOW, and
278 returns ENOTSUP even when operating on non-symlinks, try
279 again with the flag disabled if it does not appear to be
280 supported and if the file is not a symlink. This
281 introduces a race, alas. */
282 if (atflag
&& typeflag
!= SYMTYPE
&& ! implemented (chmod_errno
))
283 chmod_errno
= fd_chmod (fd
, file_name
, mode
, 0) == 0 ? 0 : errno
;
286 && (typeflag
!= SYMTYPE
|| implemented (chmod_errno
)))
289 chmod_error_details (file_name
, mode
);
295 /* Check time after successfully setting FILE_NAME's time stamp to T. */
297 check_time (char const *file_name
, struct timespec t
)
300 WARNOPT (WARN_TIMESTAMP
,
301 (0, 0, _("%s: implausibly old time stamp %s"),
302 file_name
, tartime (t
, true)));
303 else if (timespec_cmp (volume_start_time
, t
) < 0)
307 if (timespec_cmp (now
, t
) < 0)
309 char buf
[TIMESPEC_STRSIZE_BOUND
];
310 struct timespec diff
;
311 diff
.tv_sec
= t
.tv_sec
- now
.tv_sec
;
312 diff
.tv_nsec
= t
.tv_nsec
- now
.tv_nsec
;
313 if (diff
.tv_nsec
< 0)
315 diff
.tv_nsec
+= BILLION
;
318 WARNOPT (WARN_TIMESTAMP
,
319 (0, 0, _("%s: time stamp %s is %s s in the future"),
320 file_name
, tartime (t
, true), code_timespec (diff
, buf
)));
325 /* Restore stat attributes (owner, group, mode and times) for
326 FILE_NAME, using information given in *ST.
327 If FD is nonnegative, it is a file descriptor for the file.
328 CURRENT_MODE and CURRENT_MODE_MASK specify information known about
329 the file's current mode, using the style of struct delayed_set_stat.
330 TYPEFLAG specifies the type of the file.
331 If INTERDIR, this is an intermediate directory.
332 ATFLAG specifies the flag to use when statting the file. */
335 set_stat (char const *file_name
,
336 struct tar_stat_info
const *st
,
337 int fd
, mode_t current_mode
, mode_t current_mode_mask
,
338 char typeflag
, bool interdir
, int atflag
)
340 /* Do the utime before the chmod because some versions of utime are
341 broken and trash the modes of the file. */
343 if (! touch_option
&& ! interdir
)
345 struct timespec ts
[2];
346 if (incremental_option
)
349 ts
[0].tv_nsec
= UTIME_OMIT
;
352 if (fdutimensat (fd
, chdir_fd
, file_name
, ts
, atflag
) == 0)
354 if (incremental_option
)
355 check_time (file_name
, ts
[0]);
356 check_time (file_name
, ts
[1]);
358 else if (typeflag
!= SYMTYPE
|| implemented (errno
))
359 utime_error (file_name
);
362 if (0 < same_owner_option
&& ! interdir
)
364 /* Some systems allow non-root users to give files away. Once this
365 done, it is not possible anymore to change file permissions.
366 However, setting file permissions now would be incorrect, since
367 they would apply to the wrong user, and there would be a race
368 condition. So, don't use systems that allow non-root users to
370 uid_t uid
= st
->stat
.st_uid
;
371 gid_t gid
= st
->stat
.st_gid
;
373 if (fd_chown (fd
, file_name
, uid
, gid
, atflag
) == 0)
375 /* Changing the owner can clear st_mode bits in some cases. */
376 if ((current_mode
| ~ current_mode_mask
) & S_IXUGO
)
377 current_mode_mask
&= ~ (current_mode
& (S_ISUID
| S_ISGID
));
379 else if (typeflag
!= SYMTYPE
|| implemented (errno
))
380 chown_error_details (file_name
, uid
, gid
);
384 st
->stat
.st_mode
& ~ current_umask
,
385 0 < same_permissions_option
&& ! interdir
? MODE_ALL
: MODE_RWX
,
386 fd
, current_mode
, current_mode_mask
, typeflag
, atflag
);
388 /* these three calls must be done *after* fd_chown() call because fd_chown
389 causes that linux capabilities becomes cleared. */
390 xattrs_xattrs_set (st
, file_name
, typeflag
, 1);
391 xattrs_acls_set (st
, file_name
, typeflag
);
392 xattrs_selinux_set (st
, file_name
, typeflag
);
395 /* Find the direct ancestor of FILE_NAME in the delayed_set_stat list.
397 static struct delayed_set_stat
*
398 find_direct_ancestor (char const *file_name
)
400 struct delayed_set_stat
*h
= delayed_set_stat_head
;
403 if (h
&& ! h
->after_links
404 && strncmp (file_name
, h
->file_name
, h
->file_name_len
) == 0
405 && ISSLASH (file_name
[h
->file_name_len
])
406 && (last_component (file_name
) == file_name
+ h
->file_name_len
+ 1))
413 /* For each entry H in the leading prefix of entries in HEAD that do
414 not have after_links marked, mark H and fill in its dev and ino
415 members. Assume HEAD && ! HEAD->after_links. */
417 mark_after_links (struct delayed_set_stat
*head
)
419 struct delayed_set_stat
*h
= head
;
426 if (deref_stat (h
->file_name
, &st
) != 0)
427 stat_error (h
->file_name
);
434 while ((h
= h
->next
) && ! h
->after_links
);
437 /* Remember to restore stat attributes (owner, group, mode and times)
438 for the directory FILE_NAME, using information given in *ST,
439 once we stop extracting files into that directory.
441 If ST is null, merely create a placeholder node for an intermediate
442 directory that was created by make_directories.
444 NOTICE: this works only if the archive has usual member order, i.e.
445 directory, then the files in that directory. Incremental archive have
446 somewhat reversed order: first go subdirectories, then all other
447 members. To help cope with this case the variable
448 delay_directory_restore_option is set by prepare_to_extract.
450 If an archive was explicitely created so that its member order is
451 reversed, some directory timestamps can be restored incorrectly,
453 tar --no-recursion -cf archive dir dir/file1 foo dir/file2
456 delay_set_stat (char const *file_name
, struct tar_stat_info
const *st
,
457 mode_t current_mode
, mode_t current_mode_mask
,
458 mode_t mode
, int atflag
)
460 size_t file_name_len
= strlen (file_name
);
461 struct delayed_set_stat
*data
= xmalloc (sizeof (*data
));
462 data
->next
= delayed_set_stat_head
;
466 data
->dev
= st
->stat
.st_dev
;
467 data
->ino
= st
->stat
.st_ino
;
468 data
->uid
= st
->stat
.st_uid
;
469 data
->gid
= st
->stat
.st_gid
;
470 data
->atime
= st
->atime
;
471 data
->mtime
= st
->mtime
;
473 data
->file_name_len
= file_name_len
;
474 data
->file_name
= xstrdup (file_name
);
475 data
->current_mode
= current_mode
;
476 data
->current_mode_mask
= current_mode_mask
;
477 data
->interdir
= ! st
;
478 data
->atflag
= atflag
;
479 data
->after_links
= 0;
480 data
->change_dir
= chdir_current
;
481 data
->cntx_name
= NULL
;
483 assign_string (&data
->cntx_name
, st
->cntx_name
);
484 if (st
&& st
->acls_a_ptr
)
486 data
->acls_a_ptr
= xmemdup (st
->acls_a_ptr
, st
->acls_a_len
+ 1);
487 data
->acls_a_len
= st
->acls_a_len
;
491 data
->acls_a_ptr
= NULL
;
492 data
->acls_a_len
= 0;
494 if (st
&& st
->acls_d_ptr
)
496 data
->acls_d_ptr
= xmemdup (st
->acls_d_ptr
, st
->acls_d_len
+ 1);
497 data
->acls_d_len
= st
->acls_d_len
;
501 data
->acls_d_ptr
= NULL
;
502 data
->acls_d_len
= 0;
505 xheader_xattr_copy (st
, &data
->xattr_map
, &data
->xattr_map_size
);
508 data
->xattr_map
= NULL
;
509 data
->xattr_map_size
= 0;
511 strcpy (data
->file_name
, file_name
);
512 delayed_set_stat_head
= data
;
513 if (must_be_dot_or_slash (file_name
))
514 mark_after_links (data
);
517 /* Update the delayed_set_stat info for an intermediate directory
518 created within the file name of DIR. The intermediate directory turned
519 out to be the same as this directory, e.g. due to ".." or symbolic
520 links. *DIR_STAT_INFO is the status of the directory. */
522 repair_delayed_set_stat (char const *dir
,
523 struct stat
const *dir_stat_info
)
525 struct delayed_set_stat
*data
;
526 for (data
= delayed_set_stat_head
; data
; data
= data
->next
)
529 if (fstatat (chdir_fd
, data
->file_name
, &st
, data
->atflag
) != 0)
531 stat_error (data
->file_name
);
535 if (st
.st_dev
== dir_stat_info
->st_dev
536 && st
.st_ino
== dir_stat_info
->st_ino
)
538 data
->dev
= current_stat_info
.stat
.st_dev
;
539 data
->ino
= current_stat_info
.stat
.st_ino
;
540 data
->mode
= current_stat_info
.stat
.st_mode
;
541 data
->uid
= current_stat_info
.stat
.st_uid
;
542 data
->gid
= current_stat_info
.stat
.st_gid
;
543 data
->atime
= current_stat_info
.atime
;
544 data
->mtime
= current_stat_info
.mtime
;
545 data
->current_mode
= st
.st_mode
;
546 data
->current_mode_mask
= ALL_MODE_BITS
;
547 data
->interdir
= false;
552 ERROR ((0, 0, _("%s: Unexpected inconsistency when making directory"),
553 quotearg_colon (dir
)));
557 free_delayed_set_stat (struct delayed_set_stat
*data
)
559 free (data
->file_name
);
560 xheader_xattr_free (data
->xattr_map
, data
->xattr_map_size
);
561 free (data
->cntx_name
);
562 free (data
->acls_a_ptr
);
563 free (data
->acls_d_ptr
);
568 remove_delayed_set_stat (const char *fname
)
570 struct delayed_set_stat
*data
, *next
, *prev
= NULL
;
571 for (data
= delayed_set_stat_head
; data
; data
= next
)
574 if (chdir_current
== data
->change_dir
575 && strcmp (data
->file_name
, fname
) == 0)
577 free_delayed_set_stat (data
);
581 delayed_set_stat_head
= next
;
590 fixup_delayed_set_stat (char const *src
, char const *dst
)
592 struct delayed_set_stat
*data
;
593 for (data
= delayed_set_stat_head
; data
; data
= data
->next
)
595 if (chdir_current
== data
->change_dir
596 && strcmp (data
->file_name
, src
) == 0)
598 free (data
->file_name
);
599 data
->file_name
= xstrdup (dst
);
600 data
->file_name_len
= strlen (dst
);
606 /* After a file/link/directory creation has failed, see if
607 it's because some required directory was not present, and if so,
608 create all required directories. Return zero if all the required
609 directories were created, nonzero (issuing a diagnostic) otherwise.
610 Set *INTERDIR_MADE if at least one directory was created. */
612 make_directories (char *file_name
, bool *interdir_made
)
614 char *cursor0
= file_name
+ FILE_SYSTEM_PREFIX_LEN (file_name
);
615 char *cursor
; /* points into the file name */
617 for (cursor
= cursor0
; *cursor
; cursor
++)
623 if (! ISSLASH (*cursor
))
626 /* Avoid mkdir of empty string, if leading or double '/'. */
628 if (cursor
== cursor0
|| ISSLASH (cursor
[-1]))
631 /* Avoid mkdir where last part of file name is "." or "..". */
633 if (cursor
[-1] == '.'
634 && (cursor
== cursor0
+ 1 || ISSLASH (cursor
[-2])
635 || (cursor
[-2] == '.'
636 && (cursor
== cursor0
+ 2 || ISSLASH (cursor
[-3])))))
639 *cursor
= '\0'; /* truncate the name there */
640 desired_mode
= MODE_RWX
& ~ newdir_umask
;
641 mode
= desired_mode
| (we_are_root
? 0 : MODE_WXUSR
);
642 status
= mkdirat (chdir_fd
, file_name
, mode
);
646 /* Create a struct delayed_set_stat even if
647 mode == desired_mode, because
648 repair_delayed_set_stat may need to update the struct. */
649 delay_set_stat (file_name
,
650 0, mode
& ~ current_umask
, MODE_RWX
,
651 desired_mode
, AT_SYMLINK_NOFOLLOW
);
653 print_for_mkdir (file_name
, cursor
- file_name
, desired_mode
);
654 *interdir_made
= true;
656 else if (errno
== EEXIST
)
660 /* Check whether the desired file exists. Even when the
661 file exists, mkdir can fail with some errno value E other
662 than EEXIST, so long as E describes an error condition
663 that also applies. */
666 status
= fstatat (chdir_fd
, file_name
, &st
, 0);
670 mkdir_error (file_name
);
682 /* Return true if FILE_NAME (with status *STP, if STP) is not a
683 directory, and has a time stamp newer than (or equal to) that of
686 file_newer_p (const char *file_name
, struct stat
const *stp
,
687 struct tar_stat_info
*tar_stat
)
693 if (deref_stat (file_name
, &st
) != 0)
697 stat_warn (file_name
);
698 /* Be safer: if the file exists, assume it is newer. */
706 return (! S_ISDIR (stp
->st_mode
)
707 && tar_timespec_cmp (tar_stat
->mtime
, get_stat_mtime (stp
)) <= 0);
712 #define RECOVER_SKIP 2
714 /* Attempt repairing what went wrong with the extraction. Delete an
715 already existing file or create missing intermediate directories.
716 Return RECOVER_OK if we somewhat increased our chances at a successful
717 extraction, RECOVER_NO if there are no chances, and RECOVER_SKIP if the
718 caller should skip extraction of that member. The value of errno is
719 properly restored on returning RECOVER_NO.
721 If REGULAR, the caller was trying to extract onto a regular file.
723 Set *INTERDIR_MADE if an intermediate directory is made as part of
724 the recovery process. */
727 maybe_recoverable (char *file_name
, bool regular
, bool *interdir_made
)
731 struct stat
const *stp
= 0;
740 /* With open ("symlink", O_NOFOLLOW|...), POSIX says errno == ELOOP,
741 but some operating systems do not conform to the standard. */
743 /* NetBSD uses errno == EFTYPE; see <http://gnats.netbsd.org/43154>. */
746 /* FreeBSD 8.1 uses errno == EMLINK. */
748 /* Tru64 5.1B uses errno == ENOTSUP. */
752 || old_files_option
!= OVERWRITE_OLD_FILES
|| dereference_option
)
754 if (strchr (file_name
, '/'))
756 if (deref_stat (file_name
, &st
) != 0)
760 /* The caller tried to open a symbolic link with O_NOFOLLOW.
761 Fall through, treating it as an already-existing file. */
764 /* Remove an old file, if the options allow this. */
766 switch (old_files_option
)
769 WARNOPT (WARN_EXISTING_FILE
,
770 (0, 0, _("%s: skipping existing file"), file_name
));
776 case KEEP_NEWER_FILES
:
777 if (file_newer_p (file_name
, stp
, ¤t_stat_info
))
780 case DEFAULT_OLD_FILES
:
781 case NO_OVERWRITE_DIR_OLD_FILES
:
782 case OVERWRITE_OLD_FILES
:
783 if (0 < remove_any_file (file_name
, ORDINARY_REMOVE_OPTION
))
787 case UNLINK_FIRST_OLD_FILES
:
790 abort (); /* notreached */
793 /* Attempt creating missing intermediate directories. */
794 if (make_directories (file_name
, interdir_made
) == 0 && *interdir_made
)
799 /* Just say we can't do anything about it... */
807 /* Restore stat extended attributes (xattr) for FILE_NAME, using information
808 given in *ST. Restore before extraction because they may affect file layout
809 (e.g. on Lustre distributed parallel filesystem - setting info about how many
810 servers is this file striped over, stripe size, mirror copies, etc.
811 in advance dramatically improves the following performance of reading and
812 writing a file). If not restoring permissions, invert the INVERT_PERMISSIONS
813 bits from the file's current permissions. TYPEFLAG specifies the type of the
814 file. Returns non-zero when error occurs (while un-available xattrs is not
815 an error, rather no-op). Non-zero FILE_CREATED indicates set_xattr has
818 set_xattr (char const *file_name
, struct tar_stat_info
const *st
,
819 mode_t invert_permissions
, char typeflag
, int *file_created
)
822 bool interdir_made
= false;
824 if ((xattrs_option
> 0) && st
->xattr_map_size
)
826 mode_t mode
= current_stat_info
.stat
.st_mode
& MODE_RWX
& ~ current_umask
;
830 if (!mknodat (chdir_fd
, file_name
, mode
^ invert_permissions
, 0))
832 /* Successfully created file */
833 xattrs_xattrs_set (st
, file_name
, typeflag
, 0);
838 switch (maybe_recoverable ((char *)file_name
, false, &interdir_made
))
844 open_error (file_name
);
856 /* Fix the statuses of all directories whose statuses need fixing, and
857 which are not ancestors of FILE_NAME. If AFTER_LINKS is
858 nonzero, do this for all such directories; otherwise, stop at the
859 first directory that is marked to be fixed up only after delayed
860 links are applied. */
862 apply_nonancestor_delayed_set_stat (char const *file_name
, bool after_links
)
864 size_t file_name_len
= strlen (file_name
);
865 bool check_for_renamed_directories
= 0;
867 while (delayed_set_stat_head
)
869 struct delayed_set_stat
*data
= delayed_set_stat_head
;
870 bool skip_this_one
= 0;
872 mode_t current_mode
= data
->current_mode
;
873 mode_t current_mode_mask
= data
->current_mode_mask
;
875 check_for_renamed_directories
|= data
->after_links
;
877 if (after_links
< data
->after_links
878 || (data
->file_name_len
< file_name_len
879 && file_name
[data
->file_name_len
]
880 && (ISSLASH (file_name
[data
->file_name_len
])
881 || ISSLASH (file_name
[data
->file_name_len
- 1]))
882 && memcmp (file_name
, data
->file_name
, data
->file_name_len
) == 0))
885 chdir_do (data
->change_dir
);
887 if (check_for_renamed_directories
)
889 if (fstatat (chdir_fd
, data
->file_name
, &st
, data
->atflag
) != 0)
891 stat_error (data
->file_name
);
896 current_mode
= st
.st_mode
;
897 current_mode_mask
= ALL_MODE_BITS
;
898 if (! (st
.st_dev
== data
->dev
&& st
.st_ino
== data
->ino
))
901 _("%s: Directory renamed before its status could be extracted"),
902 quotearg_colon (data
->file_name
)));
910 struct tar_stat_info sb
;
911 sb
.stat
.st_mode
= data
->mode
;
912 sb
.stat
.st_uid
= data
->uid
;
913 sb
.stat
.st_gid
= data
->gid
;
914 sb
.atime
= data
->atime
;
915 sb
.mtime
= data
->mtime
;
916 sb
.cntx_name
= data
->cntx_name
;
917 sb
.acls_a_ptr
= data
->acls_a_ptr
;
918 sb
.acls_a_len
= data
->acls_a_len
;
919 sb
.acls_d_ptr
= data
->acls_d_ptr
;
920 sb
.acls_d_len
= data
->acls_d_len
;
921 sb
.xattr_map
= data
->xattr_map
;
922 sb
.xattr_map_size
= data
->xattr_map_size
;
923 set_stat (data
->file_name
, &sb
,
924 -1, current_mode
, current_mode_mask
,
925 DIRTYPE
, data
->interdir
, data
->atflag
);
928 delayed_set_stat_head
= data
->next
;
929 free_delayed_set_stat (data
);
935 is_directory_link (const char *file_name
)
941 res
= (fstatat (chdir_fd
, file_name
, &st
, AT_SYMLINK_NOFOLLOW
) == 0 &&
942 S_ISLNK (st
.st_mode
) &&
943 fstatat (chdir_fd
, file_name
, &st
, 0) == 0 &&
944 S_ISDIR (st
.st_mode
));
949 /* Extractor functions for various member types */
952 extract_dir (char *file_name
, int typeflag
)
956 mode_t current_mode
= 0;
957 mode_t current_mode_mask
= 0;
959 bool interdir_made
= false;
961 /* Save 'root device' to avoid purging mount points. */
962 if (one_file_system_option
&& root_device
== 0)
966 if (fstatat (chdir_fd
, ".", &st
, 0) != 0)
969 root_device
= st
.st_dev
;
972 if (incremental_option
)
973 /* Read the entry and delete files that aren't listed in the archive. */
974 purge_directory (file_name
);
975 else if (typeflag
== GNUTYPE_DUMPDIR
)
978 /* If ownership or permissions will be restored later, create the
979 directory with restrictive permissions at first, so that in the
980 meantime processes owned by other users do not inadvertently
981 create files under this directory that inherit the wrong owner,
982 group, or permissions from the directory. If not root, though,
983 make the directory writeable and searchable at first, so that
984 files can be created under it. */
985 mode
= ((current_stat_info
.stat
.st_mode
986 & (0 < same_owner_option
|| 0 < same_permissions_option
989 | (we_are_root
? 0 : MODE_WXUSR
));
993 status
= mkdirat (chdir_fd
, file_name
, mode
);
996 current_mode
= mode
& ~ current_umask
;
997 current_mode_mask
= MODE_RWX
;
998 atflag
= AT_SYMLINK_NOFOLLOW
;
1004 || keep_directory_symlink_option
1005 || old_files_option
== DEFAULT_OLD_FILES
1006 || old_files_option
== OVERWRITE_OLD_FILES
))
1010 if (keep_directory_symlink_option
&& is_directory_link (file_name
))
1013 if (deref_stat (file_name
, &st
) == 0)
1015 current_mode
= st
.st_mode
;
1016 current_mode_mask
= ALL_MODE_BITS
;
1018 if (S_ISDIR (current_mode
))
1022 repair_delayed_set_stat (file_name
, &st
);
1031 switch (maybe_recoverable (file_name
, false, &interdir_made
))
1040 if (errno
!= EEXIST
)
1042 mkdir_error (file_name
);
1051 || old_files_option
== DEFAULT_OLD_FILES
1052 || old_files_option
== OVERWRITE_OLD_FILES
)
1053 delay_set_stat (file_name
, ¤t_stat_info
,
1054 current_mode
, current_mode_mask
,
1055 current_stat_info
.stat
.st_mode
, atflag
);
1062 open_output_file (char const *file_name
, int typeflag
, mode_t mode
,
1063 int file_created
, mode_t
*current_mode
,
1064 mode_t
*current_mode_mask
)
1067 bool overwriting_old_files
= old_files_option
== OVERWRITE_OLD_FILES
;
1068 int openflag
= (O_WRONLY
| O_BINARY
| O_CLOEXEC
| O_NOCTTY
| O_NONBLOCK
1070 | (overwriting_old_files
1071 ? O_TRUNC
| (dereference_option
? 0 : O_NOFOLLOW
)
1074 /* File might be created in set_xattr. So clear O_EXCL to avoid open() fail */
1076 openflag
= openflag
& ~O_EXCL
;
1078 if (typeflag
== CONTTYPE
)
1080 static int conttype_diagnosed
;
1082 if (!conttype_diagnosed
)
1084 conttype_diagnosed
= 1;
1085 WARNOPT (WARN_CONTIGUOUS_CAST
,
1086 (0, 0, _("Extracting contiguous files as regular files")));
1090 /* If O_NOFOLLOW is needed but does not work, check for a symlink
1091 separately. There's a race condition, but that cannot be avoided
1092 on hosts lacking O_NOFOLLOW. */
1093 if (! HAVE_WORKING_O_NOFOLLOW
1094 && overwriting_old_files
&& ! dereference_option
)
1097 if (fstatat (chdir_fd
, file_name
, &st
, AT_SYMLINK_NOFOLLOW
) == 0
1098 && S_ISLNK (st
.st_mode
))
1105 fd
= openat (chdir_fd
, file_name
, openflag
, mode
);
1108 if (overwriting_old_files
)
1111 if (fstat (fd
, &st
) != 0)
1118 if (! S_ISREG (st
.st_mode
))
1124 *current_mode
= st
.st_mode
;
1125 *current_mode_mask
= ALL_MODE_BITS
;
1129 *current_mode
= mode
& ~ current_umask
;
1130 *current_mode_mask
= MODE_RWX
;
1138 extract_file (char *file_name
, int typeflag
)
1142 union block
*data_block
;
1146 bool interdir_made
= false;
1147 mode_t mode
= (current_stat_info
.stat
.st_mode
& MODE_RWX
1148 & ~ (0 < same_owner_option
? S_IRWXG
| S_IRWXO
: 0));
1149 mode_t invert_permissions
= 0 < same_owner_option
? mode
& (S_IRWXG
| S_IRWXO
)
1151 mode_t current_mode
= 0;
1152 mode_t current_mode_mask
= 0;
1154 if (to_stdout_option
)
1156 else if (to_command_option
)
1158 fd
= sys_exec_command (file_name
, 'f', ¤t_stat_info
);
1167 int file_created
= 0;
1168 if (set_xattr (file_name
, ¤t_stat_info
, invert_permissions
,
1169 typeflag
, &file_created
))
1172 while ((fd
= open_output_file (file_name
, typeflag
, mode
,
1173 file_created
, ¤t_mode
,
1174 ¤t_mode_mask
))
1177 int recover
= maybe_recoverable (file_name
, true, &interdir_made
);
1178 if (recover
!= RECOVER_OK
)
1181 if (recover
== RECOVER_SKIP
)
1183 open_error (file_name
);
1189 mv_begin_read (¤t_stat_info
);
1190 if (current_stat_info
.is_sparse
)
1191 sparse_extract_file (fd
, ¤t_stat_info
, &size
);
1193 for (size
= current_stat_info
.stat
.st_size
; size
> 0; )
1195 mv_size_left (size
);
1197 /* Locate data, determine max length writeable, write it,
1198 block that we have used the data, then check if the write
1201 data_block
= find_next_block ();
1204 ERROR ((0, 0, _("Unexpected EOF in archive")));
1205 break; /* FIXME: What happens, then? */
1208 written
= available_space_after (data_block
);
1213 count
= blocking_write (fd
, data_block
->buffer
, written
);
1216 set_next_block_after ((union block
*)
1217 (data_block
->buffer
+ written
- 1));
1218 if (count
!= written
)
1220 if (!to_command_option
)
1221 write_error_details (file_name
, count
, written
);
1222 /* FIXME: shouldn't we restore from backup? */
1231 /* If writing to stdout, don't try to do anything to the filename;
1232 it doesn't exist, or we don't want to touch it anyway. */
1234 if (to_stdout_option
)
1237 if (! to_command_option
)
1238 set_stat (file_name
, ¤t_stat_info
, fd
,
1239 current_mode
, current_mode_mask
, typeflag
, false,
1240 (old_files_option
== OVERWRITE_OLD_FILES
1241 ? 0 : AT_SYMLINK_NOFOLLOW
));
1243 status
= close (fd
);
1245 close_error (file_name
);
1247 if (to_command_option
)
1248 sys_wait_command ();
1253 /* Create a placeholder file with name FILE_NAME, which will be
1254 replaced after other extraction is done by a symbolic link if
1255 IS_SYMLINK is true, and by a hard link otherwise. Set
1256 *INTERDIR_MADE if an intermediate directory is made in the
1260 create_placeholder_file (char *file_name
, bool is_symlink
, bool *interdir_made
)
1265 while ((fd
= openat (chdir_fd
, file_name
, O_WRONLY
| O_CREAT
| O_EXCL
, 0)) < 0)
1267 switch (maybe_recoverable (file_name
, false, interdir_made
))
1276 open_error (file_name
);
1281 if (fstat (fd
, &st
) != 0)
1283 stat_error (file_name
);
1286 else if (close (fd
) != 0)
1287 close_error (file_name
);
1290 struct delayed_set_stat
*h
;
1291 struct delayed_link
*p
=
1292 xmalloc (offsetof (struct delayed_link
, target
)
1293 + strlen (current_stat_info
.link_name
)
1295 p
->next
= delayed_link_head
;
1296 delayed_link_head
= p
;
1299 p
->birthtime
= get_stat_birthtime (&st
);
1300 p
->is_symlink
= is_symlink
;
1303 p
->mode
= current_stat_info
.stat
.st_mode
;
1304 p
->uid
= current_stat_info
.stat
.st_uid
;
1305 p
->gid
= current_stat_info
.stat
.st_gid
;
1306 p
->atime
= current_stat_info
.atime
;
1307 p
->mtime
= current_stat_info
.mtime
;
1309 p
->change_dir
= chdir_current
;
1310 p
->sources
= xmalloc (offsetof (struct string_list
, string
)
1311 + strlen (file_name
) + 1);
1312 p
->sources
->next
= 0;
1313 strcpy (p
->sources
->string
, file_name
);
1314 p
->cntx_name
= NULL
;
1315 assign_string (&p
->cntx_name
, current_stat_info
.cntx_name
);
1316 p
->acls_a_ptr
= NULL
;
1318 p
->acls_d_ptr
= NULL
;
1320 xheader_xattr_copy (¤t_stat_info
, &p
->xattr_map
, &p
->xattr_map_size
);
1321 strcpy (p
->target
, current_stat_info
.link_name
);
1323 if ((h
= find_direct_ancestor (file_name
)) != NULL
)
1324 mark_after_links (h
);
1333 extract_link (char *file_name
, int typeflag
)
1335 bool interdir_made
= false;
1336 char const *link_name
;
1339 link_name
= current_stat_info
.link_name
;
1341 if (! absolute_names_option
&& contains_dot_dot (link_name
))
1342 return create_placeholder_file (file_name
, false, &interdir_made
);
1346 struct stat st1
, st2
;
1348 int status
= linkat (chdir_fd
, link_name
, chdir_fd
, file_name
, 0);
1353 struct delayed_link
*ds
= delayed_link_head
;
1355 && fstatat (chdir_fd
, link_name
, &st1
, AT_SYMLINK_NOFOLLOW
) == 0)
1356 for (; ds
; ds
= ds
->next
)
1357 if (ds
->change_dir
== chdir_current
1358 && ds
->dev
== st1
.st_dev
1359 && ds
->ino
== st1
.st_ino
1360 && (timespec_cmp (ds
->birthtime
, get_stat_birthtime (&st1
))
1363 struct string_list
*p
= xmalloc (offsetof (struct string_list
, string
)
1364 + strlen (file_name
) + 1);
1365 strcpy (p
->string
, file_name
);
1366 p
->next
= ds
->sources
;
1372 else if ((e
== EEXIST
&& strcmp (link_name
, file_name
) == 0)
1373 || ((fstatat (chdir_fd
, link_name
, &st1
, AT_SYMLINK_NOFOLLOW
)
1375 && (fstatat (chdir_fd
, file_name
, &st2
, AT_SYMLINK_NOFOLLOW
)
1377 && st1
.st_dev
== st2
.st_dev
1378 && st1
.st_ino
== st2
.st_ino
))
1383 while ((rc
= maybe_recoverable (file_name
, false, &interdir_made
))
1386 if (rc
== RECOVER_SKIP
)
1388 if (!(incremental_option
&& errno
== EEXIST
))
1390 link_error (link_name
, file_name
);
1397 extract_symlink (char *file_name
, int typeflag
)
1400 bool interdir_made
= false;
1402 if (! absolute_names_option
1403 && (IS_ABSOLUTE_FILE_NAME (current_stat_info
.link_name
)
1404 || contains_dot_dot (current_stat_info
.link_name
)))
1405 return create_placeholder_file (file_name
, true, &interdir_made
);
1407 while (symlinkat (current_stat_info
.link_name
, chdir_fd
, file_name
) != 0)
1408 switch (maybe_recoverable (file_name
, false, &interdir_made
))
1417 symlink_error (current_stat_info
.link_name
, file_name
);
1421 set_stat (file_name
, ¤t_stat_info
, -1, 0, 0,
1422 SYMTYPE
, false, AT_SYMLINK_NOFOLLOW
);
1426 static int warned_once
;
1431 WARNOPT (WARN_SYMLINK_CAST
,
1433 _("Attempting extraction of symbolic links as hard links")));
1435 return extract_link (file_name
, typeflag
);
1439 #if S_IFCHR || S_IFBLK
1441 extract_node (char *file_name
, int typeflag
)
1443 bool interdir_made
= false;
1444 mode_t mode
= (current_stat_info
.stat
.st_mode
& (MODE_RWX
| S_IFBLK
| S_IFCHR
)
1445 & ~ (0 < same_owner_option
? S_IRWXG
| S_IRWXO
: 0));
1447 while (mknodat (chdir_fd
, file_name
, mode
, current_stat_info
.stat
.st_rdev
)
1449 switch (maybe_recoverable (file_name
, false, &interdir_made
))
1458 mknod_error (file_name
);
1462 set_stat (file_name
, ¤t_stat_info
, -1,
1463 mode
& ~ current_umask
, MODE_RWX
,
1464 typeflag
, false, AT_SYMLINK_NOFOLLOW
);
1469 #if HAVE_MKFIFO || defined mkfifo
1471 extract_fifo (char *file_name
, int typeflag
)
1473 bool interdir_made
= false;
1474 mode_t mode
= (current_stat_info
.stat
.st_mode
& MODE_RWX
1475 & ~ (0 < same_owner_option
? S_IRWXG
| S_IRWXO
: 0));
1477 while (mkfifoat (chdir_fd
, file_name
, mode
) != 0)
1478 switch (maybe_recoverable (file_name
, false, &interdir_made
))
1487 mkfifo_error (file_name
);
1491 set_stat (file_name
, ¤t_stat_info
, -1,
1492 mode
& ~ current_umask
, MODE_RWX
,
1493 typeflag
, false, AT_SYMLINK_NOFOLLOW
);
1499 extract_volhdr (char *file_name
, int typeflag
)
1506 extract_failure (char *file_name
, int typeflag
)
1512 extract_skip (char *file_name
, int typeflag
)
1518 typedef int (*tar_extractor_t
) (char *file_name
, int typeflag
);
1522 /* Prepare to extract a file. Find extractor function.
1523 Return zero if extraction should not proceed. */
1526 prepare_to_extract (char const *file_name
, int typeflag
, tar_extractor_t
*fun
)
1530 if (EXTRACT_OVER_PIPE
)
1533 /* Select the extractor */
1536 case GNUTYPE_SPARSE
:
1537 *fun
= extract_file
;
1544 /* Appears to be a file. But BSD tar uses the convention that a slash
1545 suffix means a directory. */
1546 if (current_stat_info
.had_trailing_slash
)
1550 *fun
= extract_file
;
1556 *fun
= extract_symlink
;
1560 *fun
= extract_link
;
1565 current_stat_info
.stat
.st_mode
|= S_IFCHR
;
1566 *fun
= extract_node
;
1572 current_stat_info
.stat
.st_mode
|= S_IFBLK
;
1573 *fun
= extract_node
;
1577 #if HAVE_MKFIFO || defined mkfifo
1579 *fun
= extract_fifo
;
1584 case GNUTYPE_DUMPDIR
:
1586 if (current_stat_info
.is_dumpdir
)
1587 delay_directory_restore_option
= true;
1590 case GNUTYPE_VOLHDR
:
1591 *fun
= extract_volhdr
;
1594 case GNUTYPE_MULTIVOL
:
1596 _("%s: Cannot extract -- file is continued from another volume"),
1597 quotearg_colon (current_stat_info
.file_name
)));
1598 *fun
= extract_skip
;
1601 case GNUTYPE_LONGNAME
:
1602 case GNUTYPE_LONGLINK
:
1603 ERROR ((0, 0, _("Unexpected long name header")));
1604 *fun
= extract_failure
;
1608 WARNOPT (WARN_UNKNOWN_CAST
,
1610 _("%s: Unknown file type '%c', extracted as normal file"),
1611 quotearg_colon (file_name
), typeflag
));
1612 *fun
= extract_file
;
1615 /* Determine whether the extraction should proceed */
1619 switch (old_files_option
)
1621 case UNLINK_FIRST_OLD_FILES
:
1622 if (!remove_any_file (file_name
,
1623 recursive_unlink_option
? RECURSIVE_REMOVE_OPTION
1624 : ORDINARY_REMOVE_OPTION
)
1625 && errno
&& errno
!= ENOENT
)
1627 unlink_error (file_name
);
1632 case KEEP_NEWER_FILES
:
1633 if (file_newer_p (file_name
, 0, ¤t_stat_info
))
1635 WARNOPT (WARN_IGNORE_NEWER
,
1636 (0, 0, _("Current %s is newer or same age"),
1637 quote (file_name
)));
1649 /* Extract a file from the archive. */
1651 extract_archive (void)
1654 tar_extractor_t fun
;
1655 bool skip_dotdot_name
;
1657 fatal_exit_hook
= extract_finish
;
1659 set_next_block_after (current_header
);
1661 skip_dotdot_name
= (!absolute_names_option
1662 && contains_dot_dot (current_stat_info
.orig_file_name
));
1663 if (skip_dotdot_name
)
1664 ERROR ((0, 0, _("%s: Member name contains '..'"),
1665 quotearg_colon (current_stat_info
.orig_file_name
)));
1667 if (!current_stat_info
.file_name
[0]
1669 || (interactive_option
1670 && !confirm ("extract", current_stat_info
.file_name
)))
1676 /* Print the block from current_header and current_stat. */
1678 print_header (¤t_stat_info
, current_header
, -1);
1680 /* Restore stats for all non-ancestor directories, unless
1681 it is an incremental archive.
1682 (see NOTICE in the comment to delay_set_stat above) */
1683 if (!delay_directory_restore_option
)
1685 int dir
= chdir_current
;
1686 apply_nonancestor_delayed_set_stat (current_stat_info
.file_name
, 0);
1690 /* Take a safety backup of a previously existing file. */
1693 if (!maybe_backup_file (current_stat_info
.file_name
, 0))
1696 ERROR ((0, e
, _("%s: Was unable to backup this file"),
1697 quotearg_colon (current_stat_info
.file_name
)));
1702 /* Extract the archive entry according to its type. */
1704 typeflag
= sparse_member_p (¤t_stat_info
) ?
1705 GNUTYPE_SPARSE
: current_header
->header
.typeflag
;
1707 if (prepare_to_extract (current_stat_info
.file_name
, typeflag
, &fun
))
1709 if (fun
&& (*fun
) (current_stat_info
.file_name
, typeflag
)
1711 undo_last_backup ();
1718 /* Extract the links whose final extraction were delayed. */
1720 apply_delayed_links (void)
1722 struct delayed_link
*ds
;
1724 for (ds
= delayed_link_head
; ds
; )
1726 struct string_list
*sources
= ds
->sources
;
1727 char const *valid_source
= 0;
1729 chdir_do (ds
->change_dir
);
1731 for (sources
= ds
->sources
; sources
; sources
= sources
->next
)
1733 char const *source
= sources
->string
;
1736 /* Make sure the placeholder file is still there. If not,
1737 don't create a link, as the placeholder was probably
1738 removed by a later extraction. */
1739 if (fstatat (chdir_fd
, source
, &st
, AT_SYMLINK_NOFOLLOW
) == 0
1740 && st
.st_dev
== ds
->dev
1741 && st
.st_ino
== ds
->ino
1742 && timespec_cmp (get_stat_birthtime (&st
), ds
->birthtime
) == 0)
1744 /* Unlink the placeholder, then create a hard link if possible,
1745 a symbolic link otherwise. */
1746 if (unlinkat (chdir_fd
, source
, 0) != 0)
1747 unlink_error (source
);
1748 else if (valid_source
1749 && (linkat (chdir_fd
, valid_source
, chdir_fd
, source
, 0)
1752 else if (!ds
->is_symlink
)
1754 if (linkat (chdir_fd
, ds
->target
, chdir_fd
, source
, 0) != 0)
1755 link_error (ds
->target
, source
);
1757 else if (symlinkat (ds
->target
, chdir_fd
, source
) != 0)
1758 symlink_error (ds
->target
, source
);
1761 struct tar_stat_info st1
;
1762 st1
.stat
.st_mode
= ds
->mode
;
1763 st1
.stat
.st_uid
= ds
->uid
;
1764 st1
.stat
.st_gid
= ds
->gid
;
1765 st1
.atime
= ds
->atime
;
1766 st1
.mtime
= ds
->mtime
;
1767 st1
.cntx_name
= ds
->cntx_name
;
1768 st1
.acls_a_ptr
= ds
->acls_a_ptr
;
1769 st1
.acls_a_len
= ds
->acls_a_len
;
1770 st1
.acls_d_ptr
= ds
->acls_d_ptr
;
1771 st1
.acls_d_len
= ds
->acls_d_len
;
1772 st1
.xattr_map
= ds
->xattr_map
;
1773 st1
.xattr_map_size
= ds
->xattr_map_size
;
1774 set_stat (source
, &st1
, -1, 0, 0, SYMTYPE
,
1775 false, AT_SYMLINK_NOFOLLOW
);
1776 valid_source
= source
;
1781 for (sources
= ds
->sources
; sources
; )
1783 struct string_list
*next
= sources
->next
;
1788 xheader_xattr_free (ds
->xattr_map
, ds
->xattr_map_size
);
1789 free (ds
->cntx_name
);
1792 struct delayed_link
*next
= ds
->next
;
1798 delayed_link_head
= 0;
1801 /* Finish the extraction of an archive. */
1803 extract_finish (void)
1805 /* First, fix the status of ordinary directories that need fixing. */
1806 apply_nonancestor_delayed_set_stat ("", 0);
1808 /* Then, apply delayed links, so that they don't affect delayed
1809 directory status-setting for ordinary directories. */
1810 apply_delayed_links ();
1812 /* Finally, fix the status of directories that are ancestors
1813 of delayed links. */
1814 apply_nonancestor_delayed_set_stat ("", 1);
1818 rename_directory (char *src
, char *dst
)
1820 if (renameat (chdir_fd
, src
, chdir_fd
, dst
) == 0)
1821 fixup_delayed_set_stat (src
, dst
);
1830 if (make_directories (dst
, &interdir_made
) == 0)
1832 if (renameat (chdir_fd
, src
, chdir_fd
, dst
) == 0)
1839 /* FIXME: Fall back to recursive copying */
1845 ERROR ((0, e
, _("Cannot rename %s to %s"),