aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmael Luceno <ismael@iodev.co.uk>2021-10-09 21:40:53 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-10-09 21:45:59 +0200
commit04ad683bf99333c2a6c6fd6549faa67978ad9a98 (patch)
tree33654089cc19caa20c272fce299523f89d2b4d73
parent49bcf9f40cff1320a761d674cf89a0c0ab97ef49 (diff)
downloadbusybox-w32-04ad683bf99333c2a6c6fd6549faa67978ad9a98.tar.gz
busybox-w32-04ad683bf99333c2a6c6fd6549faa67978ad9a98.tar.bz2
busybox-w32-04ad683bf99333c2a6c6fd6549faa67978ad9a98.zip
find: implement -amin, -atime, -cmin, and -ctime
function old new delta func_mtime 130 180 +50 func_mmin 121 171 +50 static.params 235 261 +26 parse_params 1435 1461 +26 packed_usage 34025 34033 +8 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/0 up/down: 160/0) Total: 160 bytes Signed-off-by: Ismael Luceno <ismael@iodev.co.uk> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--findutils/find.c112
1 files changed, 103 insertions, 9 deletions
diff --git a/findutils/find.c b/findutils/find.c
index f557bb762..9feb44b64 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -74,6 +74,22 @@
74//config: Allow searching based on the modification time of 74//config: Allow searching based on the modification time of
75//config: files, in days. 75//config: files, in days.
76//config: 76//config:
77//config:config FEATURE_FIND_ATIME
78//config: bool "Enable -atime: access time matching"
79//config: default y
80//config: depends on FEATURE_FIND_MTIME
81//config: help
82//config: Allow searching based on the access time of
83//config: files, in days.
84//config:
85//config:config FEATURE_FIND_CTIME
86//config: bool "Enable -ctime: status change timestamp matching"
87//config: default y
88//config: depends on FEATURE_FIND_MTIME
89//config: help
90//config: Allow searching based on the status change timestamp of
91//config: files, in days.
92//config:
77//config:config FEATURE_FIND_MMIN 93//config:config FEATURE_FIND_MMIN
78//config: bool "Enable -mmin: modification time matching by minutes" 94//config: bool "Enable -mmin: modification time matching by minutes"
79//config: default y 95//config: default y
@@ -82,6 +98,22 @@
82//config: Allow searching based on the modification time of 98//config: Allow searching based on the modification time of
83//config: files, in minutes. 99//config: files, in minutes.
84//config: 100//config:
101//config:config FEATURE_FIND_AMIN
102//config: bool "Enable -amin: access time matching by minutes"
103//config: default y
104//config: depends on FEATURE_FIND_MMIN
105//config: help
106//config: Allow searching based on the access time of
107//config: files, in minutes.
108//config:
109//config:config FEATURE_FIND_CMIN
110//config: bool "Enable -cmin: status change timestamp matching by minutes"
111//config: default y
112//config: depends on FEATURE_FIND_MMIN
113//config: help
114//config: Allow searching based on the status change timestamp of
115//config: files, in minutes.
116//config:
85//config:config FEATURE_FIND_PERM 117//config:config FEATURE_FIND_PERM
86//config: bool "Enable -perm: permissions matching" 118//config: bool "Enable -perm: permissions matching"
87//config: default y 119//config: default y
@@ -296,10 +328,22 @@
296//usage: "\n -mtime DAYS mtime is greater than (+N), less than (-N)," 328//usage: "\n -mtime DAYS mtime is greater than (+N), less than (-N),"
297//usage: "\n or exactly N days in the past" 329//usage: "\n or exactly N days in the past"
298//usage: ) 330//usage: )
331//usage: IF_FEATURE_FIND_ATIME(
332//usage: "\n -atime DAYS atime +N/-N/N days in the past"
333//usage: )
334//usage: IF_FEATURE_FIND_CTIME(
335//usage: "\n -ctime DAYS ctime +N/-N/N days in the past"
336//usage: )
299//usage: IF_FEATURE_FIND_MMIN( 337//usage: IF_FEATURE_FIND_MMIN(
300//usage: "\n -mmin MINS mtime is greater than (+N), less than (-N)," 338//usage: "\n -mmin MINS mtime is greater than (+N), less than (-N),"
301//usage: "\n or exactly N minutes in the past" 339//usage: "\n or exactly N minutes in the past"
302//usage: ) 340//usage: )
341//usage: IF_FEATURE_FIND_AMIN(
342//usage: "\n -amin MINS atime +N/-N/N minutes in the past"
343//usage: )
344//usage: IF_FEATURE_FIND_CMIN(
345//usage: "\n -cmin MINS ctime +N/-N/N minutes in the past"
346//usage: )
303//usage: IF_FEATURE_FIND_NEWER( 347//usage: IF_FEATURE_FIND_NEWER(
304//usage: "\n -newer FILE mtime is more recent than FILE's" 348//usage: "\n -newer FILE mtime is more recent than FILE's"
305//usage: ) 349//usage: )
@@ -396,8 +440,8 @@ IF_FEATURE_FIND_PRINT0( ACTS(print0))
396IF_FEATURE_FIND_TYPE( ACTS(type, int type_mask;)) 440IF_FEATURE_FIND_TYPE( ACTS(type, int type_mask;))
397IF_FEATURE_FIND_EXECUTABLE(ACTS(executable)) 441IF_FEATURE_FIND_EXECUTABLE(ACTS(executable))
398IF_FEATURE_FIND_PERM( ACTS(perm, char perm_char; mode_t perm_mask;)) 442IF_FEATURE_FIND_PERM( ACTS(perm, char perm_char; mode_t perm_mask;))
399IF_FEATURE_FIND_MTIME( ACTS(mtime, char mtime_char; unsigned mtime_days;)) 443IF_FEATURE_FIND_MTIME( ACTS(mtime, char time_type; char mtime_char; unsigned mtime_days;))
400IF_FEATURE_FIND_MMIN( ACTS(mmin, char mmin_char; unsigned mmin_mins;)) 444IF_FEATURE_FIND_MMIN( ACTS(mmin, char time_type; char mmin_char; unsigned mmin_mins;))
401IF_FEATURE_FIND_NEWER( ACTS(newer, time_t newer_mtime;)) 445IF_FEATURE_FIND_NEWER( ACTS(newer, time_t newer_mtime;))
402IF_FEATURE_FIND_INUM( ACTS(inum, ino_t inode_num;)) 446IF_FEATURE_FIND_INUM( ACTS(inum, ino_t inode_num;))
403IF_FEATURE_FIND_USER( ACTS(user, uid_t uid;)) 447IF_FEATURE_FIND_USER( ACTS(user, uid_t uid;))
@@ -619,9 +663,13 @@ ACTF(perm)
619} 663}
620#endif 664#endif
621 665
622#if \ 666#if 0 \
623 ENABLE_FEATURE_FIND_MMIN || \ 667 || ENABLE_FEATURE_FIND_AMIN \
624 ENABLE_FEATURE_FIND_MTIME 668 || ENABLE_FEATURE_FIND_ATIME \
669 || ENABLE_FEATURE_FIND_CMIN \
670 || ENABLE_FEATURE_FIND_CTIME \
671 || ENABLE_FEATURE_FIND_MMIN \
672 || ENABLE_FEATURE_FIND_MTIME
625static int time_cmp(time_t ftime, char time_char, time_t secs, time_t delta) 673static int time_cmp(time_t ftime, char time_char, time_t secs, time_t delta)
626{ 674{
627 time_t file_age = time(NULL) - ftime; 675 time_t file_age = time(NULL) - ftime;
@@ -637,14 +685,32 @@ static int time_cmp(time_t ftime, char time_char, time_t secs, time_t delta)
637#if ENABLE_FEATURE_FIND_MTIME 685#if ENABLE_FEATURE_FIND_MTIME
638ACTF(mtime) 686ACTF(mtime)
639{ 687{
640 return time_cmp(statbuf->st_mtime, ap->mtime_char, 688 time_t t = statbuf->st_mtime;
689# if ENABLE_FEATURE_FIND_ATIME
690 if (ap->time_type == 'a')
691 t = statbuf->st_atime;
692# endif
693# if ENABLE_FEATURE_FIND_CTIME
694 if (ap->time_type == 'c')
695 t = statbuf->st_ctime;
696# endif
697 return time_cmp(t, ap->mtime_char,
641 ap->mtime_days * 24*60*60, 24*60*60); 698 ap->mtime_days * 24*60*60, 24*60*60);
642} 699}
643#endif 700#endif
644#if ENABLE_FEATURE_FIND_MMIN 701#if ENABLE_FEATURE_FIND_MMIN
645ACTF(mmin) 702ACTF(mmin)
646{ 703{
647 return time_cmp(statbuf->st_mtime, ap->mmin_char, 704 time_t t = statbuf->st_mtime;
705# if ENABLE_FEATURE_FIND_AMIN
706 if (ap->time_type == 'a')
707 t = statbuf->st_atime;
708# endif
709# if ENABLE_FEATURE_FIND_CMIN
710 if (ap->time_type == 'c')
711 t = statbuf->st_ctime;
712# endif
713 return time_cmp(t, ap->mmin_char,
648 ap->mmin_mins * 60, 60); 714 ap->mmin_mins * 60, 60);
649} 715}
650#endif 716#endif
@@ -1047,7 +1113,11 @@ static action*** parse_params(char **argv)
1047 IF_FEATURE_FIND_TYPE( PARM_type ,) 1113 IF_FEATURE_FIND_TYPE( PARM_type ,)
1048 IF_FEATURE_FIND_PERM( PARM_perm ,) 1114 IF_FEATURE_FIND_PERM( PARM_perm ,)
1049 IF_FEATURE_FIND_MTIME( PARM_mtime ,) 1115 IF_FEATURE_FIND_MTIME( PARM_mtime ,)
1116 IF_FEATURE_FIND_ATIME( PARM_atime ,)
1117 IF_FEATURE_FIND_CTIME( PARM_ctime ,)
1050 IF_FEATURE_FIND_MMIN( PARM_mmin ,) 1118 IF_FEATURE_FIND_MMIN( PARM_mmin ,)
1119 IF_FEATURE_FIND_AMIN( PARM_amin ,)
1120 IF_FEATURE_FIND_CMIN( PARM_cmin ,)
1051 IF_FEATURE_FIND_NEWER( PARM_newer ,) 1121 IF_FEATURE_FIND_NEWER( PARM_newer ,)
1052 IF_FEATURE_FIND_INUM( PARM_inum ,) 1122 IF_FEATURE_FIND_INUM( PARM_inum ,)
1053 IF_FEATURE_FIND_USER( PARM_user ,) 1123 IF_FEATURE_FIND_USER( PARM_user ,)
@@ -1091,7 +1161,11 @@ static action*** parse_params(char **argv)
1091 IF_FEATURE_FIND_TYPE( "-type\0" ) 1161 IF_FEATURE_FIND_TYPE( "-type\0" )
1092 IF_FEATURE_FIND_PERM( "-perm\0" ) 1162 IF_FEATURE_FIND_PERM( "-perm\0" )
1093 IF_FEATURE_FIND_MTIME( "-mtime\0" ) 1163 IF_FEATURE_FIND_MTIME( "-mtime\0" )
1164 IF_FEATURE_FIND_ATIME( "-atime\0" )
1165 IF_FEATURE_FIND_CTIME( "-ctime\0" )
1094 IF_FEATURE_FIND_MMIN( "-mmin\0" ) 1166 IF_FEATURE_FIND_MMIN( "-mmin\0" )
1167 IF_FEATURE_FIND_AMIN( "-amin\0" )
1168 IF_FEATURE_FIND_CMIN( "-cmin\0" )
1095 IF_FEATURE_FIND_NEWER( "-newer\0" ) 1169 IF_FEATURE_FIND_NEWER( "-newer\0" )
1096 IF_FEATURE_FIND_INUM( "-inum\0" ) 1170 IF_FEATURE_FIND_INUM( "-inum\0" )
1097 IF_FEATURE_FIND_USER( "-user\0" ) 1171 IF_FEATURE_FIND_USER( "-user\0" )
@@ -1377,19 +1451,39 @@ static action*** parse_params(char **argv)
1377 } 1451 }
1378#endif 1452#endif
1379#if ENABLE_FEATURE_FIND_MTIME 1453#if ENABLE_FEATURE_FIND_MTIME
1380 else if (parm == PARM_mtime) { 1454 else if (parm == PARM_mtime
1455# if ENABLE_FEATURE_FIND_ATIME
1456 || parm == PARM_atime
1457# endif
1458# if ENABLE_FEATURE_FIND_CTIME
1459 || parm == PARM_ctime
1460# endif
1461 ) {
1381 action_mtime *ap; 1462 action_mtime *ap;
1382 dbg("%d", __LINE__); 1463 dbg("%d", __LINE__);
1383 ap = ALLOC_ACTION(mtime); 1464 ap = ALLOC_ACTION(mtime);
1465# if ENABLE_FEATURE_FIND_AMIN || ENABLE_FEATURE_FIND_CMIN
1466 ap->time_type = arg[1];
1467# endif
1384 ap->mtime_char = arg1[0]; 1468 ap->mtime_char = arg1[0];
1385 ap->mtime_days = xatoul(plus_minus_num(arg1)); 1469 ap->mtime_days = xatoul(plus_minus_num(arg1));
1386 } 1470 }
1387#endif 1471#endif
1388#if ENABLE_FEATURE_FIND_MMIN 1472#if ENABLE_FEATURE_FIND_MMIN
1389 else if (parm == PARM_mmin) { 1473 else if (parm == PARM_mmin
1474# if ENABLE_FEATURE_FIND_AMIN
1475 || parm == PARM_amin
1476# endif
1477# if ENABLE_FEATURE_FIND_CMIN
1478 || parm == PARM_cmin
1479# endif
1480 ) {
1390 action_mmin *ap; 1481 action_mmin *ap;
1391 dbg("%d", __LINE__); 1482 dbg("%d", __LINE__);
1392 ap = ALLOC_ACTION(mmin); 1483 ap = ALLOC_ACTION(mmin);
1484# if ENABLE_FEATURE_FIND_AMIN || ENABLE_FEATURE_FIND_CMIN
1485 ap->time_type = arg[1];
1486# endif
1393 ap->mmin_char = arg1[0]; 1487 ap->mmin_char = arg1[0];
1394 ap->mmin_mins = xatoul(plus_minus_num(arg1)); 1488 ap->mmin_mins = xatoul(plus_minus_num(arg1));
1395 } 1489 }