[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH v2] find: implement -amin, -atime, -cmin, and -ctime
From:       Ismael Luceno <ismael () iodev ! co ! uk>
Date:       2021-09-29 11:49:39
Message-ID: 20210929114939.31337-1-ismael () iodev ! co ! uk
[Download RAW message or body]

Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
---
 findutils/find.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff --git a/findutils/find.c b/findutils/find.c
index 0948de13df3d..5c9eccdd545c 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -66,6 +66,38 @@
 //config:	newlines and other whitespace to be more easily
 //config:	interpreted by other programs.
 //config:
+//config:config FEATURE_FIND_ATIME
+//config:	bool "Enable -atime: access time matching"
+//config:	default y
+//config:	depends on FIND
+//config:	help
+//config:	Allow searching based on the access time of
+//config:	files, in days.
+//config:
+//config:config FEATURE_FIND_AMIN
+//config:	bool "Enable -amin: access time matching by minutes"
+//config:	default y
+//config:	depends on FIND
+//config:	help
+//config:	Allow searching based on the access time of
+//config:	files, in minutes.
+//config:
+//config:config FEATURE_FIND_CTIME
+//config:	bool "Enable -ctime: status change timestamp matching"
+//config:	default y
+//config:	depends on FIND
+//config:	help
+//config:	Allow searching based on the status change timestamp of
+//config:	files, in days.
+//config:
+//config:config FEATURE_FIND_CMIN
+//config:	bool "Enable -cmin: status change timestamp matching by minutes"
+//config:	default y
+//config:	depends on FIND
+//config:	help
+//config:	Allow searching based on the status change timestamp of
+//config:	files, in minutes.
+//config:
 //config:config FEATURE_FIND_MTIME
 //config:	bool "Enable -mtime: modification time matching"
 //config:	default y
@@ -292,6 +324,22 @@
 //usage:     "\n	-perm MASK	At least one mask bit (+MASK), all bits (-MASK),"
 //usage:     "\n			or exactly MASK bits are set in file's mode"
 //usage:	)
+//usage:	IF_FEATURE_FIND_ATIME(
+//usage:     "\n	-atime DAYS	atime is greater than (+N), less than (-N),"
+//usage:     "\n			or exactly N days in the past"
+//usage:	)
+//usage:	IF_FEATURE_FIND_AMIN(
+//usage:     "\n	-amin MINS	atime is greater than (+N), less than (-N),"
+//usage:     "\n			or exactly N minutes in the past"
+//usage:	)
+//usage:	IF_FEATURE_FIND_CTIME(
+//usage:     "\n	-ctime DAYS	ctime is greater than (+N), less than (-N),"
+//usage:     "\n			or exactly N days in the past"
+//usage:	)
+//usage:	IF_FEATURE_FIND_CMIN(
+//usage:     "\n	-cmin MINS	ctime is greater than (+N), less than (-N),"
+//usage:     "\n			or exactly N minutes in the past"
+//usage:	)
 //usage:	IF_FEATURE_FIND_MTIME(
 //usage:     "\n	-mtime DAYS	mtime is greater than (+N), less than (-N),"
 //usage:     "\n			or exactly N days in the past"
@@ -396,6 +444,10 @@ IF_FEATURE_FIND_PRINT0( ACTS(print0))
 IF_FEATURE_FIND_TYPE(   ACTS(type,  int type_mask;))
 IF_FEATURE_FIND_EXECUTABLE(ACTS(executable))
 IF_FEATURE_FIND_PERM(   ACTS(perm,  char perm_char; mode_t perm_mask;))
+IF_FEATURE_FIND_ATIME(  ACTS(atime, char atime_char; unsigned atime_days;))
+IF_FEATURE_FIND_AMIN(   ACTS(amin,  char amin_char; unsigned amin_mins;))
+IF_FEATURE_FIND_CTIME(  ACTS(ctime, char ctime_char; unsigned ctime_days;))
+IF_FEATURE_FIND_CMIN(   ACTS(cmin,  char cmin_char; unsigned cmin_mins;))
 IF_FEATURE_FIND_MTIME(  ACTS(mtime, char mtime_char; unsigned mtime_days;))
 IF_FEATURE_FIND_MMIN(   ACTS(mmin,  char mmin_char; unsigned mmin_mins;))
 IF_FEATURE_FIND_NEWER(  ACTS(newer, time_t newer_mtime;))
@@ -620,6 +672,10 @@ ACTF(perm)
 #endif
 
 #if						\
+	ENABLE_FEATURE_FIND_AMIN  ||		\
+	ENABLE_FEATURE_FIND_ATIME ||		\
+	ENABLE_FEATURE_FIND_CMIN  ||		\
+	ENABLE_FEATURE_FIND_CTIME ||		\
 	ENABLE_FEATURE_FIND_MMIN  ||		\
 	ENABLE_FEATURE_FIND_MTIME
 static int time_cmp(time_t ftime, char time_char, time_t secs, time_t delta) {
@@ -633,6 +689,34 @@ static int time_cmp(time_t ftime, char time_char, time_t secs, time_t delta) {
 }
 #endif
 
+#if ENABLE_FEATURE_FIND_ATIME
+ACTF(atime)
+{
+	return time_cmp(statbuf->st_atime, ap->atime_char,
+			ap->atime_days * 24*60*60, 24*60*60);
+}
+#endif
+#if ENABLE_FEATURE_FIND_AMIN
+ACTF(amin)
+{
+	return time_cmp(statbuf->st_atime, ap->amin_char,
+			ap->amin_mins * 60, 60);
+}
+#endif
+#if ENABLE_FEATURE_FIND_CTIME
+ACTF(ctime)
+{
+	return time_cmp(statbuf->st_ctime, ap->ctime_char,
+			ap->ctime_days * 24*60*60, 24*60*60);
+}
+#endif
+#if ENABLE_FEATURE_FIND_CMIN
+ACTF(cmin)
+{
+	return time_cmp(statbuf->st_ctime, ap->cmin_char,
+			ap->cmin_mins * 60, 60);
+}
+#endif
 #if ENABLE_FEATURE_FIND_MTIME
 ACTF(mtime)
 {
-- 
2.33.0

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic