Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/mv New mv -h option.
details: https://anonhg.NetBSD.org/src/rev/acabc00ef6ee
branches: trunk
changeset: 935097:acabc00ef6ee
user: riastradh <riastradh%NetBSD.org@localhost>
date: Wed Jun 24 16:58:12 2020 +0000
description:
New mv -h option.
`mv -h source target' just issues rename(source, target) without
discriminating on whether target resolves to a directory; this way
you can atomically replace a symlink to a directory.
diffstat:
bin/mv/mv.1 | 13 ++++++++++---
bin/mv/mv.c | 15 +++++++++------
2 files changed, 19 insertions(+), 9 deletions(-)
diffs (99 lines):
diff -r d1d535c8cddd -r acabc00ef6ee bin/mv/mv.1
--- a/bin/mv/mv.1 Wed Jun 24 16:49:30 2020 +0000
+++ b/bin/mv/mv.1 Wed Jun 24 16:58:12 2020 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: mv.1,v 1.30 2017/07/04 06:50:04 wiz Exp $
+.\" $NetBSD: mv.1,v 1.31 2020/06/24 16:58:12 riastradh Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -40,7 +40,7 @@
.Nd move files
.Sh SYNOPSIS
.Nm
-.Op Fl fiv
+.Op Fl fhiv
.Ar source target
.Nm
.Op Fl fiv
@@ -54,7 +54,9 @@
.Ar target
operand.
This form is assumed when the last operand does not name an already
-existing directory.
+existing directory or when the
+.Fl h
+flag is specified.
.Pp
In its second form,
.Nm
@@ -72,6 +74,11 @@
.It Fl f
Do not prompt for confirmation before overwriting the destination
path.
+.It Fl h
+Try to rename the source to the target irrespective of whether the
+target may resolve to a directory.
+This option allows atomically replacing a symbolic link to a
+directory.
.It Fl i
Causes
.Nm
diff -r d1d535c8cddd -r acabc00ef6ee bin/mv/mv.c
--- a/bin/mv/mv.c Wed Jun 24 16:49:30 2020 +0000
+++ b/bin/mv/mv.c Wed Jun 24 16:58:12 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mv.c,v 1.45 2016/02/28 10:59:29 mrg Exp $ */
+/* $NetBSD: mv.c,v 1.46 2020/06/24 16:58:12 riastradh Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)mv.c 8.2 (Berkeley) 4/2/94";
#else
-__RCSID("$NetBSD: mv.c,v 1.45 2016/02/28 10:59:29 mrg Exp $");
+__RCSID("$NetBSD: mv.c,v 1.46 2020/06/24 16:58:12 riastradh Exp $");
#endif
#endif /* not lint */
@@ -65,7 +65,7 @@
#include "pathnames.h"
-static int fflg, iflg, vflg;
+static int fflg, hflg, iflg, vflg;
static int stdin_ok;
static sig_atomic_t pinfo;
@@ -93,8 +93,11 @@
setprogname(argv[0]);
(void)setlocale(LC_ALL, "");
- while ((ch = getopt(argc, argv, "ifv")) != -1)
+ while ((ch = getopt(argc, argv, "hifv")) != -1)
switch (ch) {
+ case 'h':
+ hflg = 1;
+ break;
case 'i':
fflg = 0;
iflg = 1;
@@ -123,7 +126,7 @@
* If the stat on the target fails or the target isn't a directory,
* try the move. More than 2 arguments is an error in this case.
*/
- if (stat(argv[argc - 1], &sb) || !S_ISDIR(sb.st_mode)) {
+ if (hflg || stat(argv[argc - 1], &sb) || !S_ISDIR(sb.st_mode)) {
if (argc > 2)
usage();
exit(do_move(argv[0], argv[1]));
@@ -419,7 +422,7 @@
static void
usage(void)
{
- (void)fprintf(stderr, "usage: %s [-fiv] source target\n"
+ (void)fprintf(stderr, "usage: %s [-fhiv] source target\n"
" %s [-fiv] source ... directory\n", getprogname(),
getprogname());
exit(1);
Home |
Main Index |
Thread Index |
Old Index