#include "cp-hash.h"
#include "dirname.h"
#include "path-concat.h"
+#include "quote.h"
#include "same.h"
#define DO_CHOWN(Chown, File, New_uid, New_gid) \
name_space = savedir (src_path_in, src_sb->st_size);
if (name_space == NULL)
{
- error (0, errno, "%s", src_path_in);
+ /* This diagnostic is a bit vague because savedir can fail in
+ several different ways. */
+ error (0, errno, _("cannot access %s"), quote (src_path_in));
return -1;
}
existed to start with, but copy_internal renamed DST_PATH
with the backup suffix, thus also renaming SRC_PATH. */
if (errno == ENOENT)
- error (0, 0, _("`%s' and `%s' are the same file"),
- src_path, dst_path);
+ error (0, 0, _("%s and %s are the same file"),
+ quote_n (0, src_path), quote_n (1, dst_path));
else
- error (0, errno, _("cannot open `%s' for reading"), src_path);
+ error (0, errno, _("cannot open %s for reading"), quote (src_path));
return -1;
}
- /* Create the new regular file with small permissions initially,
- to not create a security hole. */
+ /* Create the new regular file with restrictive permissions (u=rw)
+ initially. */
dest_desc = open (dst_path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (dest_desc < 0)
{
- error (0, errno, _("cannot create regular file `%s'"), dst_path);
+ error (0, errno, _("cannot create regular file %s"), quote (dst_path));
return_val = -1;
goto ret2;
}
if (fstat (dest_desc, &sb))
{
- error (0, errno, "%s", dst_path);
+ error (0, errno, _("cannot fstat %s"), quote (dst_path));
return_val = -1;
goto ret;
}
if (fstat (source_desc, &sb))
{
- error (0, errno, "%s", src_path);
+ error (0, errno, _("cannot fstat %s"), quote (src_path));
return_val = -1;
goto ret;
}
if (errno == EINTR)
continue;
#endif
- error (0, errno, "%s", src_path);
+ error (0, errno, _("reading %s"), quote (src_path));
return_val = -1;
goto ret;
}
/* Make a hole. */
if (lseek (dest_desc, (off_t) n_read, SEEK_CUR) < 0L)
{
- error (0, errno, "%s", dst_path);
+ error (0, errno, _("cannot lseek %s"), quote (dst_path));
return_val = -1;
goto ret;
}
{
if (full_write (dest_desc, buf, n_read) < 0)
{
- error (0, errno, "%s", dst_path);
+ error (0, errno, _("writing %s"), quote (dst_path));
return_val = -1;
goto ret;
}
|| full_write (dest_desc, "", 1) < 0)
#endif
{
- error (0, errno, "%s", dst_path);
+ error (0, errno, _("writing %s"), quote (dst_path));
return_val = -1;
}
}
ret:
if (close (dest_desc) < 0)
{
- error (0, errno, "%s", dst_path);
+ error (0, errno, _("closing %s"), quote (dst_path));
return_val = -1;
}
ret2:
if (close (source_desc) < 0)
{
- error (0, errno, "%s", src_path);
+ error (0, errno, _("closing %s"), quote (src_path));
return_val = -1;
}
*copy_into_self = 0;
if ((*(x->xstat)) (src_path, &src_sb))
{
- error (0, errno, "%s", src_path);
+ error (0, errno, _("cannot stat %s"), quote (src_path));
return 1;
}
if (S_ISDIR (src_type) && !x->recursive)
{
- error (0, 0, _("%s: omitting directory"), src_path);
+ error (0, 0, _("omitting directory %s"), quote (src_path));
return 1;
}
{
if (errno != ENOENT)
{
- error (0, errno, "%s", dst_path);
+ error (0, errno, _("cannot stat %s"), quote (dst_path));
return 1;
}
else
if (x->backup_type == none
&& (!x->force || same_name (src_path, dst_path)))
{
- error (0, 0, _("`%s' and `%s' are the same file"),
- src_path, dst_path);
+ error (0, 0, _("%s and %s are the same file"),
+ quote_n (0, src_path), quote_n (1, dst_path));
return 1;
}
}
if (S_ISDIR (dst_sb.st_mode))
{
error (0, 0,
- _("%s: cannot overwrite directory with non-directory"),
- dst_path);
+ _("cannot overwrite directory %s with non-directory"),
+ quote (dst_path));
return 1;
}
if (euidaccess (dst_path, W_OK) != 0 && x->force)
{
fprintf (stderr,
- _("%s: overwrite `%s', overriding mode %04lo? "),
- program_name, dst_path,
+ _("%s: overwrite %s, overriding mode %04lo? "),
+ program_name, quote (dst_path),
(unsigned long) (dst_sb.st_mode & CHMOD_MODE_BITS));
}
else
{
- fprintf (stderr, _("%s: overwrite `%s'? "),
- program_name, dst_path);
+ fprintf (stderr, _("%s: overwrite %s? "),
+ program_name, quote (dst_path));
}
if (!yesno ())
return (move_mode ? 1 : 0);
/* In move_mode, DEST may not be an existing directory. */
if (S_ISDIR (dst_sb.st_mode))
{
- error (0, 0, _("%s: cannot overwrite directory"), dst_path);
+ error (0, 0, _("cannot overwrite directory %s"),
+ quote (dst_path));
return 1;
}
{
const char *fmt;
fmt = (move_mode
- ? _("backing up `%s' would destroy source; `%s' not moved")
- : _("backing up `%s' would destroy source; `%s' not copied"));
- error (0, 0, fmt, dst_path, src_path);
+ ? _("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_path),
+ quote_n (1, src_path));
free (tmp_backup);
return 1;
}
{
if (errno != ENOENT)
{
- error (0, errno, _("cannot backup `%s'"), dst_path);
+ error (0, errno, _("cannot backup %s"), quote (dst_path));
return 1;
}
else
{
if (chmod (dst_path, S_IRWXU))
{
- error (0, errno, "%s", dst_path);
+ error (0, errno,
+ _("cannot change permissions for %s"),
+ quote (dst_path));
return 1;
}
else
{
if (unlink (dst_path) && errno != ENOENT)
{
- error (0, errno, _("cannot remove old link to `%s'"),
- dst_path);
+ error (0, errno, _("cannot remove old link to %s"),
+ quote (dst_path));
if (x->failed_unlink_is_fatal)
return 1;
}
sure we'll create a directory. */
if (x->verbose && !S_ISDIR (src_type))
{
+ /* FIXME: do we really want to add quotes here? */
printf ("%s -> %s", src_path, dst_path);
if (backup_succeeded)
printf (_(" (backup: %s)"), dst_backup);
directories). */
if (S_ISDIR (src_type))
{
- error (0, 0, _("won't create hard link `%s' to directory `%s'"),
- dst_path, earlier_file);
+ error (0, 0, _("won't create hard link %s to directory %s"),
+ quote_n (0, dst_path), quote_n (1, earlier_file));
goto un_backup;
}
if (link (earlier_file, dst_path))
{
- error (0, errno, "%s", dst_path);
+ error (0, errno, _("cannot create hard link %s to %s"),
+ quote_n (0, dst_path), quote_n (1, earlier_file));
goto un_backup;
}
if (unlink (dst_path) && errno != ENOENT)
{
/* Use the value of errno from the failed rename. */
- error (0, rename_errno, _("cannot move `%s' to `%s'"),
- src_path, dst_path);
+ error (0, rename_errno, _("cannot move %s to %s"),
+ quote_n (0, src_path), quote_n (1, dst_path));
return 1;
}
}
if (is_ancestor (&src_sb, ancestors))
{
- error (0, 0, _("%s: cannot copy cyclic symbolic link"), src_path);
+ error (0, 0, _("cannot copy cyclic symbolic link %s"),
+ quote (src_path));
goto un_backup;
}
if (mkdir (dst_path, (src_mode & x->umask_kill) | S_IRWXU))
{
- error (0, errno, _("cannot create directory `%s'"), dst_path);
+ error (0, errno, _("cannot create directory %s"),
+ quote (dst_path));
goto un_backup;
}
{
error (0, 0,
_("%s: can make relative symbolic links only in current directory"),
- dst_path);
+ quote (dst_path));
goto un_backup;
}
}
if (symlink (src_path, dst_path))
{
- error (0, errno, "%s", dst_path);
+ error (0, errno, _("cannot create symbolic link %s to %s"),
+ quote_n (0, dst_path), quote_n (1, src_path));
goto un_backup;
}
{
if (link (src_path, dst_path))
{
- error (0, errno, _("cannot create link `%s'"), dst_path);
+ error (0, errno, _("cannot create link %s"), quote (dst_path));
goto un_backup;
}
return 0;
{
if (mkfifo (dst_path, new_nondir_mode (x, src_mode)))
{
- error (0, errno, _("cannot create fifo `%s'"), dst_path);
+ error (0, errno, _("cannot create fifo %s"), quote (dst_path));
goto un_backup;
}
}
{
if (mknod (dst_path, new_nondir_mode (x, src_mode), src_sb.st_rdev))
{
- error (0, errno, _("cannot create special file `%s'"), dst_path);
+ error (0, errno, _("cannot create special file %s"),
+ quote (dst_path));
goto un_backup;
}
}
link_size = readlink (src_path, link_val, PATH_MAX + 1);
if (link_size < 0)
{
- error (0, errno, _("cannot read symbolic link `%s'"), src_path);
+ error (0, errno, _("cannot read symbolic link %s"), quote (src_path));
goto un_backup;
}
link_val[link_size] = '\0';
if (! same_link)
{
- error (0, saved_errno, _("cannot create symbolic link `%s'"),
- dst_path);
+ error (0, saved_errno, _("cannot create symbolic link %s"),
+ quote (dst_path));
goto un_backup;
}
}
else
#endif
{
- error (0, 0, _("%s: unknown file type"), src_path);
+ error (0, 0, _("%s has unknown file type"), quote (src_path));
goto un_backup;
}
if (utime (dst_path, &utb))
{
- error (0, errno, _("preserving times for %s"), dst_path);
+ error (0, errno, _("preserving times for %s"), quote (dst_path));
if (x->require_preserve)
return 1;
}
{
if (DO_CHOWN (chown, dst_path, src_sb.st_uid, src_sb.st_gid))
{
- error (0, errno, _("preserving ownership for %s"), dst_path);
+ error (0, errno, _("preserving ownership for %s"), quote (dst_path));
if (x->require_preserve)
return 1;
}
/* This is so install's -m MODE option works. */
if (chmod (dst_path, x->mode))
{
- error (0, errno, _("setting permissions for %s"), dst_path);
+ error (0, errno, _("setting permissions for %s"), quote (dst_path));
return 1;
}
}
if (chmod (dst_path, dst_mode))
{
- error (0, errno, _("preserving permissions for %s"), dst_path);
+ error (0, errno, _("preserving permissions for %s"),
+ quote (dst_path));
if (x->require_preserve)
return 1;
}
/* Reset the temporarily changed mode. */
if (chmod (dst_path, dst_sb.st_mode))
{
- error (0, errno, _("restoring permissions of %s"), dst_path);
+ error (0, errno, _("restoring permissions of %s"), quote (dst_path));
return 1;
}
}
if (dst_backup)
{
if (rename (dst_backup, dst_path))
- error (0, errno, _("cannot un-backup `%s'"), dst_path);
+ error (0, errno, _("cannot un-backup %s"), quote (dst_path));
else
{
if (x->verbose)