about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2019-03-03 17:40:32 +0100
committerLeah Neukirchen <leah@vuxu.org>2019-03-03 17:40:32 +0100
commit13ceb77f59f5d001ba3e71dff75340278d8a73a8 (patch)
treebd4ff5a04e453634ab8404968b00763f8d208f52
parent0a1473ede9ee999ad23dd548c34518b8342fc928 (diff)
downloadrwc-13ceb77f59f5d001ba3e71dff75340278d8a73a8.tar.gz
rwc-13ceb77f59f5d001ba3e71dff75340278d8a73a8.tar.xz
rwc-13ceb77f59f5d001ba3e71dff75340278d8a73a8.zip
rwc: add -c to detect all file creations
-rw-r--r--README15
-rw-r--r--rwc.120
-rw-r--r--rwc.c12
3 files changed, 34 insertions, 13 deletions
diff --git a/README b/README
index 8aa2324..a06a16a 100644
--- a/README
+++ b/README
@@ -4,7 +4,7 @@ NAME
      rwc – report when changed
 
 SYNOPSIS
-     rwc [-0dep] [path ...]
+     rwc [-0cdep] [path ...]
 
 DESCRIPTION
      rwc takes a list of files or directories, watches them using inotify(7),
@@ -19,6 +19,11 @@ DESCRIPTION
      -0      Read input filenames seperated by NUL bytes.  Likewise, output
              filenames seperated by NUL bytes.
 
+     -c      Detect all file creations, including open(2) with O_CREAT,
+             mkdir(2), link(2), symlink(2), and bind(2).  This has the side-
+             effect of printing files twice that are created and immediately
+             changed after.
+
      -d      Also detect file deletion.  In this case, deleted files are
              prefixed by ‘- ’ (that is, a dash and a space).
 
@@ -43,6 +48,9 @@ EXAMPLES
 SEE ALSO
      entr(1), inotifywatch(1), wendy(1)
 
+AUTHORS
+     Leah Neukirchen <leah@vuxu.org>
+
 CAVEATS
      rwc is limited by some restrictions of inotify(7).  You can only watch
      files and directories you can read, and the amount of inotify descriptors
@@ -55,9 +63,6 @@ CAVEATS
      Many tools like to create temporary files in their working directory,
      which may distort the output.
 
-AUTHORS
-     Leah Neukirchen <leah@vuxu.org>
-
 LICENSE
      rwc is in the public domain.
 
@@ -66,4 +71,4 @@ LICENSE
 
      http://creativecommons.org/publicdomain/zero/1.0/
 
-Void Linux                       May 19, 2017                       Void Linux
+Void Linux                       March 3, 2019                      Void Linux
diff --git a/rwc.1 b/rwc.1
index cfd7714..c793b0c 100644
--- a/rwc.1
+++ b/rwc.1
@@ -1,4 +1,4 @@
-.Dd May 19, 2017
+.Dd March 3, 2019
 .Dt RWC 1
 .Os
 .Sh NAME
@@ -6,7 +6,7 @@
 .Nd report when changed
 .Sh SYNOPSIS
 .Nm
-.Op Fl 0dep
+.Op Fl 0cdep
 .Op Ar path\ ...
 .Sh DESCRIPTION
 .Nm
@@ -29,6 +29,18 @@ The options are as follows:
 .It Fl 0
 Read input filenames seperated by NUL bytes.
 Likewise, output filenames seperated by NUL bytes.
+.It Fl c
+Detect all file creations, including
+.Xr open 2
+with
+.Dv O_CREAT ,
+.Xr mkdir 2 ,
+.Xr link 2 ,
+.Xr symlink 2 ,
+and
+.Xr bind 2 .
+This has the side-effect of printing files twice
+that are created and immediately changed after.
 .It Fl d
 Also detect file deletion.
 In this case, deleted files are prefixed by
@@ -59,6 +71,8 @@ Make a sound when a download is done:
 .Xr entr 1 ,
 .Xr inotifywatch 1 ,
 .Xr wendy 1
+.Sh AUTHORS
+.An Leah Neukirchen Aq Mt leah@vuxu.org
 .Sh CAVEATS
 .Nm
 is limited by some restrictions of
@@ -78,8 +92,6 @@ and also watching files which don't exist yet.
 .Pp
 Many tools like to create temporary files in their working directory,
 which may distort the output.
-.Sh AUTHORS
-.An Leah Neukirchen Aq Mt leah@vuxu.org
 .Sh LICENSE
 .Nm
 is in the public domain.
diff --git a/rwc.c b/rwc.c
index 4ff2b1a..c828644 100644
--- a/rwc.c
+++ b/rwc.c
@@ -1,6 +1,7 @@
 /*
- * rwc [-0dep] [PATH...] - report when changed
+ * rwc [-0cdep] [PATH...] - report when changed
  *  -0  use NUL instead of newline for input/output separator
+ *  -c  detect all creations (open/O_CREAT, mkdir, link, symlink, bind)
  *  -d  detect deletions too (prefixed with "- ")
  *  -e  exit after the first reported change
  *  -p  pipe mode, don't generate new events if stdout pipe is not empty
@@ -27,6 +28,7 @@ char *argv0;
 char ibuf[8192];
 int ifd;
 
+int cflag;
 int dflag;
 int eflag;
 int pflag;
@@ -75,7 +77,8 @@ add(char *file)
 	if (lstat(file, &st) < 0 || !S_ISDIR(st.st_mode))
 		dir = dirname(file);
 
-	wd = inotify_add_watch(ifd, dir, IN_MOVED_TO | IN_CLOSE_WRITE | dflag);
+	wd = inotify_add_watch(ifd, dir,
+	    IN_MOVED_TO | IN_CLOSE_WRITE | cflag | dflag);
 	if (wd < 0) {
 		fprintf(stderr, "%s: inotify_add_watch: %s: %s\n",
 		    argv0, dir, strerror(errno));
@@ -95,14 +98,15 @@ main(int argc, char *argv[])
 
 	argv0 = argv[0];
 
-	while ((c = getopt(argc, argv, "0dep")) != -1)
+	while ((c = getopt(argc, argv, "0cdep")) != -1)
 		switch (c) {
 		case '0': input_delim = 0; break;
+		case 'c': cflag = IN_CREATE; break;
 		case 'd': dflag = IN_DELETE|IN_DELETE_SELF|IN_MOVED_FROM; break;
 		case 'e': eflag++; break;
 		case 'p': pflag++; break;
 		default:
-			fprintf(stderr, "Usage: %s [-0dep] [PATH...]\n", argv0);
+			fprintf(stderr, "Usage: %s [-0cdep] [PATH...]\n", argv0);
 			exit(2);
 		}