CVS commit: [netbsd-7] src/bin/mv

2016-03-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Mar  6 18:40:09 UTC 2016

Modified Files:
src/bin/mv [netbsd-7]: mv.c

Log Message:
Pull up following revision(s) (requested by mrg in ticket #1129):
bin/mv/mv.c: revision 1.45
add SIGINFO for mv(1), largely based upon the support in cp(1).


To generate a diff of this commit:
cvs rdiff -u -r1.43.22.1 -r1.43.22.2 src/bin/mv/mv.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/mv/mv.c
diff -u src/bin/mv/mv.c:1.43.22.1 src/bin/mv/mv.c:1.43.22.2
--- src/bin/mv/mv.c:1.43.22.1	Fri Mar  4 21:25:36 2016
+++ src/bin/mv/mv.c	Sun Mar  6 18:40:09 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: mv.c,v 1.43.22.1 2016/03/04 21:25:36 martin Exp $ */
+/* $NetBSD: mv.c,v 1.43.22.2 2016/03/06 18:40:09 martin Exp $ */
 
 /*
  * Copyright (c) 1989, 1993, 1994
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
 #if 0
 static char sccsid[] = "@(#)mv.c	8.2 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: mv.c,v 1.43.22.1 2016/03/04 21:25:36 martin Exp $");
+__RCSID("$NetBSD: mv.c,v 1.43.22.2 2016/03/06 18:40:09 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -67,12 +67,20 @@ __RCSID("$NetBSD: mv.c,v 1.43.22.1 2016/
 
 static int fflg, iflg, vflg;
 static int stdin_ok;
+static sig_atomic_t pinfo;
 
 static int	copy(char *, char *);
 static int	do_move(char *, char *);
 static int	fastcopy(char *, char *, struct stat *);
 __dead static void	usage(void);
 
+static void
+progress(int sig __unused)
+{
+
+	pinfo++;
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -109,6 +117,8 @@ main(int argc, char *argv[])
 
 	stdin_ok = isatty(STDIN_FILENO);
 
+	(void)signal(SIGINFO, progress);
+
 	/*
 	 * 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.
@@ -262,7 +272,9 @@ fastcopy(char *from, char *to, struct st
 #endif
 	static blksize_t blen;
 	static char *bp;
-	int nread, from_fd, to_fd;
+	int from_fd, to_fd;
+	ssize_t nread;
+	off_t total = 0;
 
 	if ((from_fd = open(from, O_RDONLY, 0)) < 0) {
 		warn("%s", from);
@@ -281,11 +293,21 @@ fastcopy(char *from, char *to, struct st
 		(void)close(to_fd);
 		return (1);
 	}
-	while ((nread = read(from_fd, bp, blen)) > 0)
+	while ((nread = read(from_fd, bp, blen)) > 0) {
 		if (write(to_fd, bp, nread) != nread) {
 			warn("%s", to);
 			goto err;
 		}
+		total += nread;
+		if (pinfo) {
+			int pcent = (int)((100.0 * total) / sbp->st_size);
+
+			pinfo = 0;
+			(void)fprintf(stderr, "%s => %s %llu/%llu bytes %d%% "
+			"written\n", from, to, (unsigned long long)total,
+			(unsigned long long)sbp->st_size, pcent);
+		}
+	}
 	if (nread < 0) {
 		warn("%s", from);
 err:		if (unlink(to))



CVS commit: [netbsd-7] src/bin/mv

2016-03-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Mar  4 21:25:36 UTC 2016

Modified Files:
src/bin/mv [netbsd-7]: mv.c

Log Message:
Missing file in pullup #1096: Don't truncate at sub-microsecond while
preserving timestamps.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.43.22.1 src/bin/mv/mv.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/mv/mv.c
diff -u src/bin/mv/mv.c:1.43 src/bin/mv/mv.c:1.43.22.1
--- src/bin/mv/mv.c:1.43	Mon Aug 29 14:46:54 2011
+++ src/bin/mv/mv.c	Fri Mar  4 21:25:36 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: mv.c,v 1.43 2011/08/29 14:46:54 joerg Exp $ */
+/* $NetBSD: mv.c,v 1.43.22.1 2016/03/04 21:25:36 martin Exp $ */
 
 /*
  * Copyright (c) 1989, 1993, 1994
@@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
 #if 0
 static char sccsid[] = "@(#)mv.c	8.2 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: mv.c,v 1.43 2011/08/29 14:46:54 joerg Exp $");
+__RCSID("$NetBSD: mv.c,v 1.43.22.1 2016/03/04 21:25:36 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -255,7 +255,11 @@ do_move(char *from, char *to)
 static int
 fastcopy(char *from, char *to, struct stat *sbp)
 {
+#if defined(__NetBSD__)
+	struct timespec ts[2];
+#else
 	struct timeval tval[2];
+#endif
 	static blksize_t blen;
 	static char *bp;
 	int nread, from_fd, to_fd;
@@ -296,8 +300,13 @@ err:		if (unlink(to))
 
 	(void)close(from_fd);
 #ifdef BSD4_4
+#if defined(__NetBSD__)
+	ts[0] = sbp->st_atimespec;
+	ts[1] = sbp->st_mtimespec;
+#else
 	TIMESPEC_TO_TIMEVAL([0], >st_atimespec);
 	TIMESPEC_TO_TIMEVAL([1], >st_mtimespec);
+#endif
 #else
 	tval[0].tv_sec = sbp->st_atime;
 	tval[1].tv_sec = sbp->st_mtime;
@@ -307,8 +316,12 @@ err:		if (unlink(to))
 #ifdef __SVR4
 	if (utimes(to, tval))
 #else
+#if defined(__NetBSD__)
+	if (futimens(to_fd, ts))
+#else
 	if (futimes(to_fd, tval))
 #endif
+#endif
 		warn("%s: set times", to);
 	if (fchown(to_fd, sbp->st_uid, sbp->st_gid)) {
 		if (errno != EPERM)