bug-coreutils
[Top][All Lists]
Advanced

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

Re: Patch for "mv -s" option


From: Brendan Byrd/SineSwiper
Subject: Re: Patch for "mv -s" option
Date: Mon, 15 Nov 2004 08:27:42 -0500
User-agent: Mozilla Thunderbird 0.7.2 (Windows/20040707)

Paul Eggert wrote:
>
The mailing list supports attachments (e.g., see
<http://lists.gnu.org/archive/html/bug-coreutils/2004-10/msg00066.html>)
but your email lacked one when I got it, as does the archived copy
<http://lists.gnu.org/archive/html/bug-coreutils/2004-11/msg00040.html>.

Let's try this again, then. My attachment in the Sent Items contained a blank file, so I'm not sure what happened there.

BTW, this patch also includes the Texi manual edit. I'm not familar with the language, but it was just another C&P&Edit from the "cp -s" info, so that should work just fine. I take it this is the help file that is converted to man files?

--
Brendan Byrd/SineSwiper <address@hidden>
Computer techie, Perl hacker, and all-purpose Internet guru
Resonator Software (http://www.ResonatorSoft.org/)
*** src/mv.c.old        2004-11-05 06:27:37.000000000 -0500
--- src/mv.c    2004-11-05 06:21:47.000000000 -0500
***************
*** 73,78 ****
--- 73,79 ----
    {"force", no_argument, NULL, 'f'},
    {"interactive", no_argument, NULL, 'i'},
    {"strip-trailing-slashes", no_argument, NULL, 
STRIP_TRAILING_SLASHES_OPTION},
+   {"symbolic-link", no_argument, NULL, 's'},
    {"suffix", required_argument, NULL, 'S'},
    {"target-directory", required_argument, NULL, TARGET_DIRECTORY_OPTION},
    {"update", no_argument, NULL, 'u'},
***************
*** 176,181 ****
--- 177,193 ----
        hash_init (INITIAL_HASH_MODULE, INITIAL_ENTRY_TAB_SIZE);
      }

+   /* If we are creating symbolic links, create them -after- the move, not
+      within the copy. */
+   if (x->symbolic_link)
+     {
+       static struct cp_options x_tmp;
+       x_tmp = *x;
+       x_tmp.symbolic_link = 0;
+
+       fail = copy (source, dest, 0, &x_tmp, &copy_into_self, 
&rename_succeeded);
+     }
+   else
      fail = copy (source, dest, 0, x, &copy_into_self, &rename_succeeded);

    if (!fail)
***************
*** 257,262 ****
--- 269,321 ----
          if (fail)
            error (0, errno, _("cannot remove %s"), quote (dir_to_remove));
        }
+
+ #ifdef S_ISLNK
+       if (x->symbolic_link)
+         {
+           const char *src_path = dest;
+           const char *dst_path = source;
+
+           if (*src_path != '/')
+             {
+               /* Check that DST_PATH denotes a file in the current directory. 
 */
+               struct stat dot_sb;
+               struct stat dst_parent_sb;
+               char *dst_parent;
+               int in_current_dir;
+
+               dst_parent = dir_name (dst_path);
+               if (dst_parent == NULL)
+                 xalloc_die ();
+
+               in_current_dir = (STREQ (".", dst_parent)
+                                 /* If either stat call fails, it's ok not to 
report
+                                    the failure and say dst_path is in the 
current
+                                    directory.  Other things will fail later.  
*/
+                                 || stat (".", &dot_sb)
+                                 || stat (dst_parent, &dst_parent_sb)
+                                 || SAME_INODE (dot_sb, dst_parent_sb));
+               free (dst_parent);
+
+               if (! in_current_dir)
+                 {
+                   error (0, 0,
+                _("%s: can make relative symbolic links only in current 
directory"),
+                          quote (dst_path));
+                   // goto un_backup;  /* FIXME: backup undo not handled */
+                 }
+             }
+           if (symlink (src_path, 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;  /* FIXME: backup undo not handled */
+             }
+
+           return 0;
+         }
+ #endif
+
      }

    return fail;
***************
*** 341,346 ****
--- 400,406 ----
    -i, --interactive            prompt before overwrite\n\
        --strip-trailing-slashes  remove any trailing slashes from each 
SOURCE\n\
                                   argument\n\
+   -s, --symbolic-link          make symbolic links after moving\n\
    -S, --suffix=SUFFIX          override the usual backup suffix\n\
        --target-directory=DIRECTORY  move all SOURCE arguments into 
DIRECTORY\n\
    -u, --update                 move only older or brand new non-directories\n\
***************
*** 394,400 ****

    errors = 0;

!   while ((c = getopt_long (argc, argv, "bfiuvS:V:", long_options, NULL)) != 
-1)
      {
        switch (c)
        {
--- 454,460 ----

    errors = 0;

!   while ((c = getopt_long (argc, argv, "bfiuvsS:V:", long_options, NULL)) != 
-1)
      {
        switch (c)
        {
***************
*** 431,436 ****
--- 491,503 ----
        case 'v':
          x.verbose = 1;
          break;
+         case 's':
+ #ifdef S_ISLNK
+           x.symbolic_link = 1;
+ #else
+           error (1, 0, _("symbolic links are not supported on this system"));
+ #endif
+           break;
        case 'S':
          make_backups = 1;
          backup_suffix_string = optarg;
*** doc/coreutils.texi.old      2004-11-15 07:43:51.000000000 -0500
--- doc/coreutils.texi  2004-11-15 08:00:26.000000000 -0500
***************
*** 6774,6779 ****
--- 6774,6790 ----
  Specify @option{--reply=query} to make @command{mv} prompt the user
  about each existing destination file.

+ @item -s
+ @itemx --symbolic-link
+ @opindex -s
+ @opindex --symbolic-link
+ @cindex symbolic links, moving with
+ Make symbolic links (pointing to the destination) after the file has been
+ moved.  (This is essentially the "opposite" of the @command{cp} -s option.)
+ All source file names must be absolute (starting with @samp{/}) unless the
+ destination files are in the current directory.  This option merely
+ results in an error message on systems that do not support symbolic links.
+
  @item -u
  @itemx --update
  @opindex -u

reply via email to

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