tech-userlevel archive

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

Re: Possible enhancement to find(1)



Anyway, I don't really care one way or the other. I'll make my changes locally, and I'll get what I want. If others want to use findutils, they know where to get it; if others want my changes, ask for them.

I just won't commit them without some sort of indication of consent. (Just like my changes re resurrecting the ksem module, discussed last year...)

If anyone wants them, the diffs are attached.



+------------------+--------------------------+------------------------+
| Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:      |
| (Retired)        | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com   |
| Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd.org |
+------------------+--------------------------+------------------------+
Index: extern.h
===================================================================
RCS file: /cvsroot/src/usr.bin/find/extern.h,v
retrieving revision 1.28
diff -u -p -r1.28 extern.h
--- extern.h	19 Jul 2007 07:49:30 -0000	1.28
+++ extern.h	11 Jun 2016 00:54:42 -0000
@@ -49,9 +49,11 @@ void	 show_path(int);
 
 PLAN	*c_amin(char ***, int);
 PLAN	*c_anewer(char ***, int);
+PLAN	*c_asince(char ***, int);
 PLAN	*c_atime(char ***, int);
 PLAN	*c_cmin(char ***, int);
 PLAN	*c_cnewer(char ***, int);
+PLAN	*c_csince(char ***, int);
 PLAN	*c_ctime(char ***, int);
 PLAN	*c_delete(char ***, int);
 PLAN	*c_depth(char ***, int);
@@ -85,6 +87,7 @@ PLAN	*c_print0(char ***, int);
 PLAN	*c_printx(char ***, int);
 PLAN	*c_prune(char ***, int);
 PLAN	*c_regex(char ***, int);
+PLAN	*c_since(char ***, int);
 PLAN	*c_size(char ***, int);
 PLAN	*c_type(char ***, int);
 PLAN	*c_user(char ***, int);
Index: find.1
===================================================================
RCS file: /cvsroot/src/usr.bin/find/find.1,v
retrieving revision 1.81
diff -u -p -r1.81 find.1
--- find.1	17 May 2014 11:31:40 -0000	1.81
+++ find.1	11 Jun 2016 00:54:42 -0000
@@ -32,7 +32,7 @@
 .\"
 .\"	from: @(#)find.1	8.7 (Berkeley) 5/9/95
 .\"
-.Dd May 17, 2014
+.Dd June 10, 2016
 .Dt FIND 1
 .Os
 .Sh NAME
@@ -171,6 +171,11 @@ a preceding minus sign means
 and neither means
 .Dq exactly Ar n .
 .Pp
+For primaries which take a
+.Ar timestamp
+argument, the argument must be valid input to
+.Xr parsedate 3 .
+.Pp
 .Bl -tag -width Ds -compact
 .It Ic -amin Ar n
 True if the difference between the file last access time and the time
@@ -183,6 +188,10 @@ minutes.
 True if the current file has a more recent last access time than
 .Ar file .
 .Pp
+.It Ic -asince Ar "timestamp"
+True if the file last access time is greater than the specified
+.Ar timestamp .
+.Pp
 .It Ic -atime Ar n
 True if the difference between the file last access time and the time
 .Nm
@@ -202,6 +211,10 @@ minutes.
 True if the current file has a more recent last change time than
 .Ar file .
 .Pp
+.It Ic -csince Ar "timestamp"
+True if the file last status change time is greater than the specified
+.Ar timestamp .
+.Pp
 .It Ic -ctime Ar n
 True if the difference between the time of last change of file status
 information and the time
@@ -637,6 +650,10 @@ basic regular expression
 This is a match on the whole path, not a search for the regular expression
 within the path.
 .Pp
+.It Ic -since Ar "timestamp"
+True if the file last modification time is more recent than
+.Ar timestamp .
+.Pp
 .It Ic -size Ar n Ns Op Cm c
 True if the file's size, rounded up, in 512-byte blocks is
 .Ar n .
@@ -809,8 +826,10 @@ standard.
 The options and the
 .Ic -amin ,
 .Ic -anewer ,
+.Ic -asince ,
 .Ic -cmin ,
 .Ic -cnewer ,
+.Ic -csince ,
 .Ic -delete ,
 .Ic -empty ,
 .Ic -execdir ,
@@ -828,8 +847,9 @@ The options and the
 .Ic -print0 ,
 .Ic -printx ,
 .Ic -regex ,
+.Ic -rm ,
 and
-.Ic -rm
+.Ic -msince
 primaries are extensions to
 .St -p1003.2 .
 .Pp
Index: find.h
===================================================================
RCS file: /cvsroot/src/usr.bin/find/find.h,v
retrieving revision 1.25
diff -u -p -r1.25 find.h
--- find.h	4 May 2013 06:29:32 -0000	1.25
+++ find.h	11 Jun 2016 00:54:42 -0000
@@ -40,13 +40,13 @@
 /* node type */
 enum ntype {
 	N_AND = 1, 				/* must start > 0 */
-	N_AMIN, N_ANEWER, N_ATIME, N_CLOSEPAREN, N_CMIN, N_CNEWER, N_CTIME,
-	N_DEPTH, N_EMPTY, N_EXEC, N_EXECDIR, N_EXIT, N_EXPR, N_FALSE, N_FLAGS,
-	N_FOLLOW, N_FPRINT, N_FSTYPE, N_GROUP,
+	N_AMIN, N_ANEWER, N_ASINCE, N_ATIME, N_CLOSEPAREN, N_CMIN, N_CNEWER,
+	N_CSINCE, N_CTIME, N_DEPTH, N_EMPTY, N_EXEC, N_EXECDIR, N_EXIT,
+	N_EXPR, N_FALSE, N_FLAGS, N_FOLLOW, N_FPRINT, N_FSTYPE, N_GROUP,
 	N_INAME, N_INUM, N_IREGEX, N_LINKS, N_LS, N_MINDEPTH, N_MAXDEPTH,
 	N_MMIN, N_MTIME, N_NAME, N_NEWER, N_NOGROUP, N_NOT, N_NOUSER, N_OK,
 	N_OPENPAREN, N_OR, N_PATH, N_PERM, N_PRINT, N_PRINT0, N_PRINTX,
-	N_PRUNE, N_REGEX, N_SIZE, N_TYPE, N_USER, N_XDEV, N_DELETE
+	N_PRUNE, N_REGEX, N_SINCE, N_SIZE, N_TYPE, N_USER, N_XDEV, N_DELETE
 };
 
 /* node definition */
Index: function.c
===================================================================
RCS file: /cvsroot/src/usr.bin/find/function.c,v
retrieving revision 1.72
diff -u -p -r1.72 function.c
--- function.c	4 May 2013 06:29:32 -0000	1.72
+++ function.c	11 Jun 2016 00:54:42 -0000
@@ -83,9 +83,11 @@ static	void	run_f_exec(PLAN *);
 	int	f_always_true(PLAN *, FTSENT *);
 	int	f_amin(PLAN *, FTSENT *);
 	int	f_anewer(PLAN *, FTSENT *);
+	int	f_asince(PLAN *, FTSENT *);
 	int	f_atime(PLAN *, FTSENT *);
 	int	f_cmin(PLAN *, FTSENT *);
 	int	f_cnewer(PLAN *, FTSENT *);
+	int	f_csince(PLAN *, FTSENT *);
 	int	f_ctime(PLAN *, FTSENT *);
 	int	f_delete(PLAN *, FTSENT *);
 	int	f_empty(PLAN *, FTSENT *);
@@ -115,6 +117,7 @@ static	void	run_f_exec(PLAN *);
 	int	f_printx(PLAN *, FTSENT *);
 	int	f_prune(PLAN *, FTSENT *);
 	int	f_regex(PLAN *, FTSENT *);
+	int	f_since(PLAN *, FTSENT *);
 	int	f_size(PLAN *, FTSENT *);
 	int	f_type(PLAN *, FTSENT *);
 	int	f_user(PLAN *, FTSENT *);
@@ -170,6 +173,23 @@ find_parsenum(PLAN *plan, const char *op
 }
 
 /*
+ * find_parsedate --
+ *
+ * Validate the timestamp argument or report an error
+ */
+static time_t
+find_parsedate(PLAN *plan, const char *option, const char *vp)
+{
+	time_t timestamp;
+
+	errno = 0;
+	timestamp = parsedate(vp, NULL, NULL);
+	if (timestamp == -1 && errno != 0)
+		errx(1, "%s: %s: invalid timestamp value", option, vp);
+	return timestamp;
+}
+
+/*
  * The value of n for the inode times (atime, ctime, and mtime) is a range,
  * i.e. n matches from (n - 1) to n 24 hour periods.  This interacts with
  * -n, such that "-mtime -1" would be less than 0 days, which isn't what the
@@ -239,6 +259,32 @@ c_anewer(char ***argvp, int isok)
 }
 
 /*
+ * -asince "timestamp" functions --
+ *
+ *	True if the file access time is greater than the timestamp value
+ */
+int
+f_asince(PLAN *plan, FTSENT *entry)
+{
+	COMPARE(entry->fts_statp->st_atime, plan->t_data);
+}
+
+PLAN *
+c_asince(char ***argvp, int isok)
+{
+	char *arg = **argvp;
+	PLAN *new;
+
+	(*argvp)++;
+	ftsoptions &= ~FTS_NOSTAT;
+
+	new = palloc(N_ASINCE, f_asince);
+	new->t_data = find_parsedate(new, "-asince", arg);
+	new->flags = F_GREATER;
+	return (new);
+}
+
+/*
  * -atime n functions --
  *
  *	True if the difference between the file access time and the
@@ -326,6 +372,32 @@ c_cnewer(char ***argvp, int isok)
 }
 
 /*
+ * -csince "timestamp" functions --
+ *
+ *	True if the file status change time is greater than the timestamp value
+ */
+int
+f_csince(PLAN *plan, FTSENT *entry)
+{
+	COMPARE(entry->fts_statp->st_ctime, plan->t_data);
+}
+
+PLAN *
+c_csince(char ***argvp, int isok)
+{
+	char *arg = **argvp;
+	PLAN *new;
+
+	(*argvp)++;
+	ftsoptions &= ~FTS_NOSTAT;
+
+	new = palloc(N_CSINCE, f_csince);
+	new->t_data = find_parsedate(new, "-csince", arg);
+	new->flags = F_GREATER;
+	return (new);
+}
+
+/*
  * -ctime n functions --
  *
  *	True if the difference between the last change of file
@@ -1613,6 +1685,32 @@ c_iregex(char ***argvp, int isok)
 }
 
 /*
+ * -since "timestamp" functions --
+ *
+ *	True if the file modification time is greater than the timestamp value
+ */
+int
+f_since(PLAN *plan, FTSENT *entry)
+{
+	COMPARE(entry->fts_statp->st_mtime, plan->t_data);
+}
+
+PLAN *
+c_since(char ***argvp, int isok)
+{
+	char *arg = **argvp;
+	PLAN *new;
+
+	(*argvp)++;
+	ftsoptions &= ~FTS_NOSTAT;
+
+	new = palloc(N_SINCE, f_since);
+	new->t_data = find_parsedate(new, "-since", arg);
+	new->flags = F_GREATER;
+	return (new);
+}
+
+/*
  * -size n[c] functions --
  *
  *	True if the file size in bytes, divided by an implementation defined
Index: option.c
===================================================================
RCS file: /cvsroot/src/usr.bin/find/option.c,v
retrieving revision 1.26
diff -u -p -r1.26 option.c
--- option.c	6 Feb 2007 15:33:22 -0000	1.26
+++ option.c	11 Jun 2016 00:54:42 -0000
@@ -64,9 +64,11 @@ static OPTION const options[] = {
 	{ "-amin",	N_AMIN,		c_amin,		1 },
 	{ "-and",	N_AND,		c_null,		0 },
 	{ "-anewer",	N_ANEWER,	c_anewer,	1 },
+	{ "-asince",	N_ASINCE,	c_asince,	1 },
 	{ "-atime",	N_ATIME,	c_atime,	1 },
 	{ "-cmin",	N_CMIN,		c_cmin,		1 },
 	{ "-cnewer",	N_CNEWER,	c_cnewer,	1 },
+	{ "-csince",	N_CSINCE,	c_csince,	1 },
 	{ "-ctime",	N_CTIME,	c_ctime,	1 },
 	{ "-delete",	N_DELETE,	c_delete,	0 },
 	{ "-depth",	N_DEPTH,	c_depth,	0 },
@@ -104,6 +106,7 @@ static OPTION const options[] = {
 	{ "-prune",	N_PRUNE,	c_prune,	0 },
 	{ "-regex",	N_REGEX,	c_regex,	1 },
 	{ "-rm",	N_DELETE,	c_delete,	0 },
+	{ "-since",	N_SINCE,	c_since,	1 },
 	{ "-size",	N_SIZE,		c_size,		1 },
 	{ "-type",	N_TYPE,		c_type,		1 },
 	{ "-user",	N_USER,		c_user,		1 },


Home | Main Index | Thread Index | Old Index