Module Name:src
Committed By: wiz
Date: Fri May 10 09:14:52 UTC 2024
Modified Files:
src/usr.bin/xinstall: install.1 xinstall.c
Log Message:
nstall(1): add support for -v
Reviewed by rillig@ and thorpej@, thanks!
To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/xinstall/install.1
cvs rdiff -u -r1.127 -r1.128 src/usr.bin/xinstall/xinstall.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/xinstall/install.1
diff -u src/usr.bin/xinstall/install.1:1.47 src/usr.bin/xinstall/install.1:1.48
--- src/usr.bin/xinstall/install.1:1.47 Sun Apr 8 22:00:40 2012
+++ src/usr.bin/xinstall/install.1 Fri May 10 09:14:52 2024
@@ -1,4 +1,4 @@
-.\" $NetBSD: install.1,v 1.47 2012/04/08 22:00:40 wiz Exp $
+.\" $NetBSD: install.1,v 1.48 2024/05/10 09:14:52 wiz Exp $
.\"
.\" Copyright (c) 1987, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)install.1 8.1 (Berkeley) 6/6/93
.\"
-.Dd May 1, 2009
+.Dd May 9, 2024
.Dt INSTALL 1
.Os
.Sh NAME
@@ -37,7 +37,7 @@
.Nd install binaries
.Sh SYNOPSIS
.Nm
-.Op Fl bcprsU
+.Op Fl bcprsUv
.Op Fl a Ar command
.Op Fl B Ar suffix
.Op Fl D Ar destdir
@@ -297,6 +297,11 @@ try to change the owner, the group, or t
The information that would have been updated can be stored in a log
file with
.Fl M Ar metalog .
+.It Fl v
+Cause
+.Nm
+to be verbose,
+showing files as they are installed or backed up.
.El
.Pp
By default,
Index: src/usr.bin/xinstall/xinstall.c
diff -u src/usr.bin/xinstall/xinstall.c:1.127 src/usr.bin/xinstall/xinstall.c:1.128
--- src/usr.bin/xinstall/xinstall.c:1.127 Thu Jul 20 16:21:23 2023
+++ src/usr.bin/xinstall/xinstall.c Fri May 10 09:14:52 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: xinstall.c,v 1.127 2023/07/20 16:21:23 lukem Exp $ */
+/* $NetBSD: xinstall.c,v 1.128 2024/05/10 09:14:52 wiz Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -78,7 +78,7 @@ __COPYRIGHT("@(#) Copyright (c) 1987, 19
#if 0
static char sccsid[] = "@(#)xinstall.c 8.1 (Berkeley) 7/21/93";
#else
-__RCSID("$NetBSD: xinstall.c,v 1.127 2023/07/20 16:21:23 lukem Exp $");
+__RCSID("$NetBSD: xinstall.c,v 1.128 2024/05/10 09:14:52 wiz Exp $");
#endif
#endif /* not lint */
@@ -120,6 +120,7 @@ __RCSID("$NetBSD: xinstall.c,v 1.127 202
static int dobackup, dodir, dostrip, dolink, dopreserve, dorename, dounpriv;
static int haveopt_f, haveopt_g, haveopt_m, haveopt_o;
static int numberedbackup;
+static int verbose;
static int mode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
static char pathbuf[MAXPATHLEN];
static uid_t uid = -1;
@@ -186,7 +187,7 @@ main(int argc, char *argv[])
setprogname(argv[0]);
iflags = 0;
- while ((ch = getopt(argc, argv, "a:cbB:dD:f:g:h:l:m:M:N:o:prsS:T:U"))
+ while ((ch = getopt(argc, argv, "a:cbB:dD:f:g:h:l:m:M:N:o:prsS:T:Uv"))
!= -1)
switch((char)ch) {
case 'a':
@@ -307,6 +308,9 @@ main(int argc, char *argv[])
case 'U':
dounpriv = 1;
break;
+ case 'v':
+ verbose = 1;
+ break;
case '?':
default:
usage();
@@ -477,9 +481,12 @@ do_link(char *from_name, char *to_name)
*/
(void)unlink(tmpl);
}
- return (ret);
- } else
- return (link(from_name, to_name));
+} else {
+ ret = link(from_name, to_name);
+ }
+ if (ret == 0 && verbose)
+ (void)printf("install: link %s -> %s\n", from_name, to_name);
+ return ret;
}
/*
@@ -509,6 +516,8 @@ do_symlink(char *from_name, char *to_nam
if (symlink(from_name, to_name) == -1)
err(EXIT_FAILURE, "symlink %s -> %s", from_name, to_name);
}
+ if (verbose)
+ (void)printf("install: symlink %s -> %s\n", from_name, to_name);
}
/*
@@ -641,7 +650,7 @@ makelink(char *from_name, char *to_name)
}
/*
- * If absolute or relative was not specified,
+ * If absolute or relative was not specified,
* try the names the user provided
*/
do_symlink(from_name, to_name);
@@ -821,6 +830,8 @@ install(char *from_name, char *to_name,
err(EXIT_FAILURE, "%s: rename", to_name);
to_name = oto_name;
}
+ if (verbose)
+ (void)printf("install: %s -> %s\n", from_name, to_name);
/*
* If provided a set of flags, set them, otherwise, preserve the
@@ -1116,12 +1127,12 @@ static void
backup(const char *to_name)
{
char bname[FILENAME_MAX];
-
+
if (numberedbackup) {
/* Do numbered backup */
int cnt;
char suffix_expanded[FILENAME_MAX];
-
+
cnt=0;
do {
(void)snprintf(suffix_expanded, FILENAME_MAX, suffix,
@@ -1129,13 +1140,16 @@ backup(const char *to_name)
(void)snprintf(bname, FILENAME_MAX, "%s%s", to_name,
suffix_expanded);
cnt++;
- } while (access(bname, F_OK) == 0);
+ } while (access(bname, F_OK) == 0);
} else {
/* Do simple backup */
(void)snprintf(bname, FILENAME_MAX, "%s%s", to_name, suffix);
}
-
- (void)rename(to_name, bname);
+
+ if (rename(to_name, bname) == 0) {
+ if (verbose)
+