summaryrefslogtreecommitdiff
path: root/src/copy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/copy.c')
-rw-r--r--src/copy.c162
1 files changed, 83 insertions, 79 deletions
diff --git a/src/copy.c b/src/copy.c
index edf022ef1..dc1cd2904 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -178,7 +178,7 @@ create_hole (int fd, char const *name, bool punch_holes, off_t size)
if (file_end < 0)
{
- error (0, errno, _("cannot lseek %s"), quote (name));
+ error (0, errno, _("cannot lseek %s"), quoteaf (name));
return false;
}
@@ -188,7 +188,7 @@ create_hole (int fd, char const *name, bool punch_holes, off_t size)
then make this allocation permanent. */
if (punch_holes && punch_hole (fd, file_end - size, size) < 0)
{
- error (0, errno, _("error deallocating %s"), quote (name));
+ error (0, errno, _("error deallocating %s"), quoteaf (name));
return false;
}
@@ -226,7 +226,7 @@ sparse_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
{
if (errno == EINTR)
continue;
- error (0, errno, _("error reading %s"), quote (src_name));
+ error (0, errno, _("error reading %s"), quoteaf (src_name));
return false;
}
if (n_read == 0)
@@ -259,7 +259,8 @@ sparse_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
{
if (full_write (dest_fd, pbuf, psize) != psize)
{
- error (0, errno, _("error writing %s"), quote (dst_name));
+ error (0, errno, _("error writing %s"),
+ quoteaf (dst_name));
return false;
}
}
@@ -289,7 +290,7 @@ sparse_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
psize += csize;
else
{
- error (0, 0, _("overflow reading %s"), quote (src_name));
+ error (0, 0, _("overflow reading %s"), quoteaf (src_name));
return false;
}
}
@@ -407,7 +408,7 @@ extent_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
}
error (0, errno, _("%s: failed to get extents info"),
- quote (src_name));
+ quotef (src_name));
return false;
}
@@ -439,7 +440,7 @@ extent_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
{
if (lseek (src_fd, ext_start, SEEK_SET) < 0)
{
- error (0, errno, _("cannot lseek %s"), quote (src_name));
+ error (0, errno, _("cannot lseek %s"), quoteaf (src_name));
fail:
extent_scan_free (&scan);
return false;
@@ -465,7 +466,8 @@ extent_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
if (! write_zeros (dest_fd, nzeros))
{
- error (0, errno, _("%s: write failed"), quote (dst_name));
+ error (0, errno, _("%s: write failed"),
+ quotef (dst_name));
goto fail;
}
@@ -534,14 +536,14 @@ extent_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
? ftruncate (dest_fd, src_total_size)
: ! write_zeros (dest_fd, src_total_size - dest_pos)))
{
- error (0, errno, _("failed to extend %s"), quote (dst_name));
+ error (0, errno, _("failed to extend %s"), quoteaf (dst_name));
return false;
}
if (sparse_mode == SPARSE_ALWAYS && dest_pos < src_total_size
&& punch_hole (dest_fd, dest_pos, src_total_size - dest_pos) < 0)
{
- error (0, errno, _("error deallocating %s"), quote (dst_name));
+ error (0, errno, _("error deallocating %s"), quoteaf (dst_name));
return false;
}
@@ -604,7 +606,7 @@ copy_attr_allerror (struct error_context *ctx _GL_UNUSED,
static char const *
copy_attr_quote (struct error_context *ctx _GL_UNUSED, char const *str)
{
- return quote (str);
+ return quoteaf (str);
}
static void
@@ -695,7 +697,7 @@ copy_dir (char const *src_name_in, char const *dst_name_in, bool new_dst,
{
/* This diagnostic is a bit vague because savedir can fail in
several different ways. */
- error (0, errno, _("cannot access %s"), quote (src_name_in));
+ error (0, errno, _("cannot access %s"), quoteaf (src_name_in));
return false;
}
@@ -777,7 +779,7 @@ set_owner (const struct cp_options *x, char const *dst_name, int dest_desc,
{
if (! owner_failure_ok (x))
error (0, errno, _("clearing permissions for %s"),
- quote (dst_name));
+ quoteaf (dst_name));
return -x->require_preserve;
}
}
@@ -812,7 +814,7 @@ set_owner (const struct cp_options *x, char const *dst_name, int dest_desc,
if (! chown_failure_ok (x))
{
error (0, errno, _("failed to preserve ownership for %s"),
- quote (dst_name));
+ quoteaf (dst_name));
if (x->require_preserve)
return -1;
}
@@ -837,13 +839,13 @@ set_author (const char *dst_name, int dest_desc, const struct stat *src_sb)
? file_name_lookup (dst_name, 0, 0)
: getdport (dest_desc));
if (file == MACH_PORT_NULL)
- error (0, errno, _("failed to lookup file %s"), quote (dst_name));
+ error (0, errno, _("failed to lookup file %s"), quoteaf (dst_name));
else
{
error_t err = file_chauthor (file, src_sb->st_author);
if (err)
error (0, err, _("failed to preserve authorship for %s"),
- quote (dst_name));
+ quoteaf (dst_name));
mach_port_deallocate (mach_task_self (), file);
}
#else
@@ -895,7 +897,7 @@ set_process_security_ctx (char const *src_name, char const *dst_name,
{
error (0, errno,
_("failed to get security context of %s"),
- quote (src_name));
+ quoteaf (src_name));
}
if (x->require_preserve_context)
return false;
@@ -910,7 +912,7 @@ set_process_security_ctx (char const *src_name, char const *dst_name,
{
error (0, errno,
_("failed to set default file creation context for %s"),
- quote (dst_name));
+ quoteaf (dst_name));
}
}
@@ -936,7 +938,7 @@ set_file_security_ctx (char const *dst_name, bool process_local,
{
if (all_errors || (some_errors && !errno_unsupported (errno)))
error (0, errno, _("failed to set the security context of %s"),
- quote_n (0, dst_name));
+ quoteaf_n (0, dst_name));
return false;
}
@@ -1008,13 +1010,13 @@ copy_reg (char const *src_name, char const *dst_name,
| (x->dereference == DEREF_NEVER ? O_NOFOLLOW : 0)));
if (source_desc < 0)
{
- error (0, errno, _("cannot open %s for reading"), quote (src_name));
+ error (0, errno, _("cannot open %s for reading"), quoteaf (src_name));
return false;
}
if (fstat (source_desc, &src_open_sb) != 0)
{
- error (0, errno, _("cannot fstat %s"), quote (src_name));
+ error (0, errno, _("cannot fstat %s"), quoteaf (src_name));
return_val = false;
goto close_src_desc;
}
@@ -1025,7 +1027,7 @@ copy_reg (char const *src_name, char const *dst_name,
{
error (0, 0,
_("skipping file %s, as it was replaced while being copied"),
- quote (src_name));
+ quoteaf (src_name));
return_val = false;
goto close_src_desc;
}
@@ -1064,12 +1066,12 @@ copy_reg (char const *src_name, char const *dst_name,
{
if (unlink (dst_name) != 0)
{
- error (0, errno, _("cannot remove %s"), quote (dst_name));
+ error (0, errno, _("cannot remove %s"), quoteaf (dst_name));
return_val = false;
goto close_src_desc;
}
if (x->verbose)
- printf (_("removed %s\n"), quote (dst_name));
+ printf (_("removed %s\n"), quoteaf (dst_name));
/* Tell caller that the destination file was unlinked. */
*new_dst = true;
@@ -1122,7 +1124,7 @@ copy_reg (char const *src_name, char const *dst_name,
else
{
error (0, 0, _("not writing through dangling symlink %s"),
- quote (dst_name));
+ quoteaf (dst_name));
return_val = false;
goto close_src_desc;
}
@@ -1160,14 +1162,14 @@ copy_reg (char const *src_name, char const *dst_name,
/* Otherwise, it's an error. */
error (0, dest_errno, _("cannot create regular file %s"),
- quote (dst_name));
+ quoteaf (dst_name));
return_val = false;
goto close_src_desc;
}
if (fstat (dest_desc, &sb) != 0)
{
- error (0, errno, _("cannot fstat %s"), quote (dst_name));
+ error (0, errno, _("cannot fstat %s"), quoteaf (dst_name));
return_val = false;
goto close_src_and_dst_desc;
}
@@ -1181,7 +1183,7 @@ copy_reg (char const *src_name, char const *dst_name,
if (!clone_ok)
{
error (0, errno, _("failed to clone %s from %s"),
- quote_n (0, dst_name), quote_n (1, src_name));
+ quoteaf_n (0, dst_name), quoteaf_n (1, src_name));
return_val = false;
goto close_src_and_dst_desc;
}
@@ -1278,7 +1280,7 @@ copy_reg (char const *src_name, char const *dst_name,
}
else if (wrote_hole_at_eof && ftruncate (dest_desc, n_read) < 0)
{
- error (0, errno, _("failed to extend %s"), quote (dst_name));
+ error (0, errno, _("failed to extend %s"), quoteaf (dst_name));
return_val = false;
goto close_src_and_dst_desc;
}
@@ -1293,7 +1295,7 @@ preserve_metadata:
if (fdutimens (dest_desc, dst_name, timespec) != 0)
{
- error (0, errno, _("preserving times for %s"), quote (dst_name));
+ error (0, errno, _("preserving times for %s"), quoteaf (dst_name));
if (x->require_preserve)
{
return_val = false;
@@ -1361,7 +1363,7 @@ preserve_metadata:
&& fchmod_or_lchmod (dest_desc, dst_name, dst_mode) != 0)
{
error (0, errno, _("preserving permissions for %s"),
- quote (dst_name));
+ quoteaf (dst_name));
if (x->require_preserve)
return_val = false;
}
@@ -1370,13 +1372,13 @@ preserve_metadata:
close_src_and_dst_desc:
if (close (dest_desc) < 0)
{
- error (0, errno, _("failed to close %s"), quote (dst_name));
+ error (0, errno, _("failed to close %s"), quoteaf (dst_name));
return_val = false;
}
close_src_desc:
if (close (source_desc) < 0)
{
- error (0, errno, _("failed to close %s"), quote (src_name));
+ error (0, errno, _("failed to close %s"), quoteaf (src_name));
return_val = false;
}
@@ -1654,14 +1656,14 @@ overwrite_ok (struct cp_options const *x, char const *dst_name,
|| x->unlink_dest_after_failed_open)
? _("%s: replace %s, overriding mode %04lo (%s)? ")
: _("%s: unwritable %s (mode %04lo, %s); try anyway? "),
- program_name, quote (dst_name),
+ program_name, quoteaf (dst_name),
(unsigned long int) (dst_sb->st_mode & CHMOD_MODE_BITS),
&perms[1]);
}
else
{
fprintf (stderr, _("%s: overwrite %s? "),
- program_name, quote (dst_name));
+ program_name, quoteaf (dst_name));
}
return yesno ();
@@ -1728,9 +1730,9 @@ abandon_move (const struct cp_options *x,
static void
emit_verbose (char const *src, char const *dst, char const *backup_dst_name)
{
- printf ("%s -> %s", quote_n (0, src), quote_n (1, dst));
+ printf ("%s -> %s", quoteaf_n (0, src), quoteaf_n (1, dst));
if (backup_dst_name)
- printf (_(" (backup: %s)"), quote (backup_dst_name));
+ printf (_(" (backup: %s)"), quoteaf (backup_dst_name));
putchar ('\n');
}
@@ -1767,11 +1769,11 @@ create_hard_link (char const *src_name, char const *dst_name,
{
if (unlink (dst_name) != 0)
{
- error (0, errno, _("cannot remove %s"), quote (dst_name));
+ error (0, errno, _("cannot remove %s"), quoteaf (dst_name));
return false;
}
if (verbose)
- printf (_("removed %s\n"), quote (dst_name));
+ printf (_("removed %s\n"), quoteaf (dst_name));
link_failed = (linkat (AT_FDCWD, src_name, AT_FDCWD, dst_name, flags)
!= 0);
}
@@ -1779,7 +1781,7 @@ create_hard_link (char const *src_name, char const *dst_name,
if (link_failed)
{
error (0, errno, _("cannot create hard link %s to %s"),
- quote_n (0, dst_name), quote_n (1, src_name));
+ quoteaf_n (0, dst_name), quoteaf_n (1, src_name));
return false;
}
@@ -1841,7 +1843,7 @@ copy_internal (char const *src_name, char const *dst_name,
if (XSTAT (x, src_name, &src_sb) != 0)
{
- error (0, errno, _("cannot stat %s"), quote (src_name));
+ error (0, errno, _("cannot stat %s"), quoteaf (src_name));
return false;
}
@@ -1849,7 +1851,7 @@ copy_internal (char const *src_name, char const *dst_name,
if (S_ISDIR (src_mode) && !x->recursive)
{
- error (0, 0, _("omitting directory %s"), quote (src_name));
+ error (0, 0, _("omitting directory %s"), quoteaf (src_name));
return false;
}
@@ -1864,7 +1866,7 @@ copy_internal (char const *src_name, char const *dst_name,
&& seen_file (x->src_info, src_name, &src_sb))
{
error (0, 0, _("warning: source file %s specified more than once"),
- quote (src_name));
+ quoteaf (src_name));
return true;
}
@@ -1895,7 +1897,7 @@ copy_internal (char const *src_name, char const *dst_name,
{
if (errno != ENOENT)
{
- error (0, errno, _("cannot stat %s"), quote (dst_name));
+ error (0, errno, _("cannot stat %s"), quoteaf (dst_name));
return false;
}
else
@@ -1913,7 +1915,7 @@ copy_internal (char const *src_name, char const *dst_name,
x, &return_now))
{
error (0, 0, _("%s and %s are the same file"),
- quote_n (0, src_name), quote_n (1, dst_name));
+ quoteaf_n (0, src_name), quoteaf_n (1, dst_name));
return false;
}
@@ -2003,7 +2005,7 @@ copy_internal (char const *src_name, char const *dst_name,
{
error (0, 0,
_("cannot overwrite non-directory %s with directory %s"),
- quote_n (0, dst_name), quote_n (1, src_name));
+ quoteaf_n (0, dst_name), quoteaf_n (1, src_name));
return false;
}
}
@@ -2021,7 +2023,7 @@ copy_internal (char const *src_name, char const *dst_name,
{
error (0, 0,
_("will not overwrite just-created %s with %s"),
- quote_n (0, dst_name), quote_n (1, src_name));
+ quoteaf_n (0, dst_name), quoteaf_n (1, src_name));
return false;
}
}
@@ -2039,7 +2041,7 @@ copy_internal (char const *src_name, char const *dst_name,
{
error (0, 0,
_("cannot overwrite directory %s with non-directory"),
- quote (dst_name));
+ quoteaf (dst_name));
return false;
}
}
@@ -2053,7 +2055,7 @@ copy_internal (char const *src_name, char const *dst_name,
{
error (0, 0,
_("cannot move directory onto non-directory: %s -> %s"),
- quote_n (0, src_name), quote_n (0, dst_name));
+ quotef_n (0, src_name), quotef_n (0, dst_name));
return false;
}
}
@@ -2085,8 +2087,8 @@ copy_internal (char const *src_name, char const *dst_name,
? _("backing up %s would destroy source; %s not moved")
: _("backing up %s would destroy source; %s not copied"));
error (0, 0, fmt,
- quote_n (0, dst_name),
- quote_n (1, src_name));
+ quoteaf_n (0, dst_name),
+ quoteaf_n (1, src_name));
free (tmp_backup);
return false;
}
@@ -2106,7 +2108,8 @@ copy_internal (char const *src_name, char const *dst_name,
{
if (errno != ENOENT)
{
- error (0, errno, _("cannot backup %s"), quote (dst_name));
+ error (0, errno, _("cannot backup %s"),
+ quoteaf (dst_name));
return false;
}
else
@@ -2131,12 +2134,12 @@ copy_internal (char const *src_name, char const *dst_name,
{
if (unlink (dst_name) != 0 && errno != ENOENT)
{
- error (0, errno, _("cannot remove %s"), quote (dst_name));
+ error (0, errno, _("cannot remove %s"), quoteaf (dst_name));
return false;
}
new_dst = true;
if (x->verbose)
- printf (_("removed %s\n"), quote (dst_name));
+ printf (_("removed %s\n"), quoteaf (dst_name));
}
}
}
@@ -2171,7 +2174,7 @@ copy_internal (char const *src_name, char const *dst_name,
{
error (0, 0,
_("will not copy %s through just-created symlink %s"),
- quote_n (0, src_name), quote_n (1, dst_name));
+ quoteaf_n (0, src_name), quoteaf_n (1, dst_name));
return false;
}
}
@@ -2248,8 +2251,8 @@ copy_internal (char const *src_name, char const *dst_name,
if (same_name (src_name, earlier_file))
{
error (0, 0, _("cannot copy a directory, %s, into itself, %s"),
- quote_n (0, top_level_src_name),
- quote_n (1, top_level_dst_name));
+ quoteaf_n (0, top_level_src_name),
+ quoteaf_n (1, top_level_dst_name));
*copy_into_self = true;
goto un_backup;
}
@@ -2257,7 +2260,7 @@ copy_internal (char const *src_name, char const *dst_name,
{
error (0, 0, _("warning: source directory %s "
"specified more than once"),
- quote (top_level_src_name));
+ quoteaf (top_level_src_name));
/* We only do backups in move mode and for non dirs,
and in move mode this won't be the issue as the source will
be missing for subsequent attempts.
@@ -2278,7 +2281,7 @@ copy_internal (char const *src_name, char const *dst_name,
else
{
error (0, 0, _("will not create hard link %s to directory %s"),
- quote_n (0, dst_name), quote_n (1, earlier_file));
+ quoteaf_n (0, dst_name), quoteaf_n (1, earlier_file));
goto un_backup;
}
}
@@ -2335,8 +2338,8 @@ copy_internal (char const *src_name, char const *dst_name,
failing with a specific errno value. Expect problems on
non-POSIX systems. */
error (0, 0, _("cannot move %s to a subdirectory of itself, %s"),
- quote_n (0, top_level_src_name),
- quote_n (1, top_level_dst_name));
+ quoteaf_n (0, top_level_src_name),
+ quoteaf_n (1, top_level_dst_name));
/* Note that there is no need to call forget_created here,
(compare with the other calls in this file) since the
@@ -2378,7 +2381,7 @@ copy_internal (char const *src_name, char const *dst_name,
fail. Etc. */
error (0, errno,
_("cannot move %s to %s"),
- quote_n (0, src_name), quote_n (1, dst_name));
+ quoteaf_n (0, src_name), quoteaf_n (1, dst_name));
forget_created (src_sb.st_ino, src_sb.st_dev);
return false;
}
@@ -2394,7 +2397,7 @@ copy_internal (char const *src_name, char const *dst_name,
{
error (0, errno,
_("inter-device move failed: %s to %s; unable to remove target"),
- quote_n (0, src_name), quote_n (1, dst_name));
+ quoteaf_n (0, src_name), quoteaf_n (1, dst_name));
forget_created (src_sb.st_ino, src_sb.st_dev);
return false;
}
@@ -2434,7 +2437,7 @@ copy_internal (char const *src_name, char const *dst_name,
if (is_ancestor (&src_sb, ancestors))
{
error (0, 0, _("cannot copy cyclic symbolic link %s"),
- quote (src_name));
+ quoteaf (src_name));
goto un_backup;
}
@@ -2454,7 +2457,7 @@ copy_internal (char const *src_name, char const *dst_name,
if (mkdir (dst_name, dst_mode_bits & ~omitted_permissions) != 0)
{
error (0, errno, _("cannot create directory %s"),
- quote (dst_name));
+ quoteaf (dst_name));
goto un_backup;
}
@@ -2464,7 +2467,7 @@ copy_internal (char const *src_name, char const *dst_name,
if (lstat (dst_name, &dst_sb) != 0)
{
- error (0, errno, _("cannot stat %s"), quote (dst_name));
+ error (0, errno, _("cannot stat %s"), quoteaf (dst_name));
goto un_backup;
}
else if ((dst_sb.st_mode & S_IRWXU) != S_IRWXU)
@@ -2477,7 +2480,7 @@ copy_internal (char const *src_name, char const *dst_name,
if (lchmod (dst_name, dst_mode | S_IRWXU) != 0)
{
error (0, errno, _("setting permissions for %s"),
- quote (dst_name));
+ quoteaf (dst_name));
goto un_backup;
}
}
@@ -2554,14 +2557,14 @@ copy_internal (char const *src_name, char const *dst_name,
{
error (0, 0,
_("%s: can make relative symbolic links only in current directory"),
- quote (dst_name));
+ quotef (dst_name));
goto un_backup;
}
}
if (symlink (src_name, dst_name) != 0)
{
error (0, errno, _("cannot create symbolic link %s to %s"),
- quote_n (0, dst_name), quote_n (1, src_name));
+ quoteaf_n (0, dst_name), quoteaf_n (1, src_name));
goto un_backup;
}
}
@@ -2612,7 +2615,7 @@ copy_internal (char const *src_name, char const *dst_name,
if (mknod (dst_name, src_mode & ~omitted_permissions, 0) != 0)
if (mkfifo (dst_name, src_mode & ~S_IFIFO & ~omitted_permissions) != 0)
{
- error (0, errno, _("cannot create fifo %s"), quote (dst_name));
+ error (0, errno, _("cannot create fifo %s"), quoteaf (dst_name));
goto un_backup;
}
}
@@ -2622,7 +2625,7 @@ copy_internal (char const *src_name, char const *dst_name,
!= 0)
{
error (0, errno, _("cannot create special file %s"),
- quote (dst_name));
+ quoteaf (dst_name));
goto un_backup;
}
}
@@ -2632,7 +2635,8 @@ copy_internal (char const *src_name, char const *dst_name,
dest_is_symlink = true;
if (src_link_val == NULL)
{
- error (0, errno, _("cannot read symbolic link %s"), quote (src_name));
+ error (0, errno, _("cannot read symbolic link %s"),
+ quoteaf (src_name));
goto un_backup;
}
@@ -2660,7 +2664,7 @@ copy_internal (char const *src_name, char const *dst_name,
if (! same_link)
{
error (0, saved_errno, _("cannot create symbolic link %s"),
- quote (dst_name));
+ quoteaf (dst_name));
goto un_backup;
}
}
@@ -2691,7 +2695,7 @@ copy_internal (char const *src_name, char const *dst_name,
}
else
{
- error (0, 0, _("%s has unknown file type"), quote (src_name));
+ error (0, 0, _("%s has unknown file type"), quoteaf (src_name));
goto un_backup;
}
@@ -2750,7 +2754,7 @@ copy_internal (char const *src_name, char const *dst_name,
: utimens (dst_name, timespec))
!= 0)
{
- error (0, errno, _("preserving times for %s"), quote (dst_name));
+ error (0, errno, _("preserving times for %s"), quoteaf (dst_name));
if (x->require_preserve)
return false;
}
@@ -2814,7 +2818,7 @@ copy_internal (char const *src_name, char const *dst_name,
rules for special mode bits. */
if (new_dst && lstat (dst_name, &dst_sb) != 0)
{
- error (0, errno, _("cannot stat %s"), quote (dst_name));
+ error (0, errno, _("cannot stat %s"), quoteaf (dst_name));
return false;
}
dst_mode = dst_sb.st_mode;
@@ -2828,7 +2832,7 @@ copy_internal (char const *src_name, char const *dst_name,
if (lchmod (dst_name, dst_mode | omitted_permissions) != 0)
{
error (0, errno, _("preserving permissions for %s"),
- quote (dst_name));
+ quoteaf (dst_name));
if (x->require_preserve)
return false;
}
@@ -2854,12 +2858,12 @@ un_backup:
if (dst_backup)
{
if (rename (dst_backup, dst_name) != 0)
- error (0, errno, _("cannot un-backup %s"), quote (dst_name));
+ error (0, errno, _("cannot un-backup %s"), quoteaf (dst_name));
else
{
if (x->verbose)
printf (_("%s -> %s (unbackup)\n"),
- quote_n (0, dst_backup), quote_n (1, dst_name));
+ quoteaf_n (0, dst_backup), quoteaf_n (1, dst_name));
}
}
return false;