bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mv, cp ask anyway though bound to fail


From: Paul Eggert
Subject: Re: mv, cp ask anyway though bound to fail
Date: Fri, 16 Mar 2007 09:33:03 -0700
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

Dan Jacobson <address@hidden> writes:

> Does it "cost much more" to check first that too then before asking?
> E.g., if I were a secretary, I would double check if the lunch were
> already cancelled before asking the boss if he wants to attend.

But the only way to find out is to try.  ACLs allow file systems to
"change their minds", so you don't know for sure whether the lunch was
cancelled until you show up and try to eat.  The same principle
applies here.

That being said, the prompt could be improved, as Eric wrote.

Also, this is the only place I know of in coreutils where a mode
is output only in bare octal notation; we might as well be friendlier
and output a symbolic mode as well.

Here's a proposed patch.

2007-03-16  Paul Eggert  <address@hidden>

        * src/copy.c: Include filemode.h.
        (overwrite_prompt): Say "try to overwrite", not "overwrite", to
        make it clearer that the attempt may fail.  Problem reported by
        Dan Jacobson in:
        http://lists.gnu.org/archive/html/bug-coreutils/2007-03/msg00130.html
        Output symbolic mode as well as numeric.
        * tests/mv/i-2 (fail): Adjust to new prompt format.

diff --git a/src/copy.c b/src/copy.c
index 49bbb8c..4bdb75c 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -38,6 +38,7 @@
 #include "euidaccess.h"
 #include "error.h"
 #include "fcntl--.h"
+#include "filemode.h"
 #include "filenamecat.h"
 #include "full-write.h"
 #include "getpagesize.h"
@@ -797,10 +798,14 @@ overwrite_prompt (char const *dst_name, struct stat const 
*dst_sb)
 {
   if (euidaccess (dst_name, W_OK) != 0)
     {
+      char perms[12];          /* "-rwxrwxrwx " ls-style modes. */
+      strmode (dst_sb->st_mode, perms);
+      perms[10] = '\0';
       fprintf (stderr,
-              _("%s: overwrite %s, overriding mode %04lo? "),
+              _("%s: try to overwrite %s, overriding mode %04lo (%s)? "),
               program_name, quote (dst_name),
-              (unsigned long int) (dst_sb->st_mode & CHMOD_MODE_BITS));
+              (unsigned long int) (dst_sb->st_mode & CHMOD_MODE_BITS),
+              &perms[1]);
     }
   else
     {
diff --git a/tests/mv/i-2 b/tests/mv/i-2
index ae7c5a1..36d1ce4 100755
--- a/tests/mv/i-2
+++ b/tests/mv/i-2
@@ -2,7 +2,7 @@
 # Test both cp and mv for their behavior with -if and -fi
 # The standards (POSIX and SuS) dictate annoyingly inconsistent behavior.

-# Copyright (C) 2000, 2001, 2006 Free Software Foundation, Inc.
+# Copyright (C) 2000, 2001, 2006, 2007 Free Software Foundation, Inc.

 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -61,7 +61,7 @@ cp -if e f < y > out 2>&1 || fail=1

 # Make sure out contains the prompt.
 case "`cat out`" in
-  "cp: overwrite \`f', overriding mode 0000?"*) ;;
+  "cp: try to overwrite \`f', overriding mode 0000 (---------)?"*) ;;
   *) fail=1 ;;
 esac

M ChangeLog
M src/copy.c
M tests/mv/i-2
Committed as d903145b0efa3db0a9db7a278c3810666aef815b




reply via email to

[Prev in Thread] Current Thread [Next in Thread]