.B -atime 3d
has a margin of error of one day, while
.B -atime 72h
-has a margin of error of one hour.
+has a margin of error of one hour. If both
+.BI "-atime +" older
+and
+.BI "-atime -" newer
+are used, then files with atime within the range
+.IR older - newer
+are matched.
.TP
.BR --attrs
File has ATTRS attribute flags. Supported attributes are (non exhaustive list):
}
run_test 56od "check lfs find -btime with units"
+test_56oe() {
+ local dir=$DIR/$tdir
+ local expected=5
+ local unit=hour
+
+ # just to make sure there is something that won't be found
+ test_mkdir $dir
+ touch $dir/$tfile.now
+
+ for ((val = 1; val <= 10; val++)); do
+ touch $dir/$tfile-a.$val $dir/$tfile-m.$val
+ touch $dir/$tfile-c.$val
+ touch --date="$val $unit ago" -a $dir/$tfile-a.$val
+ touch --date="$val $unit ago" -m $dir/$tfile-m.$val
+ (( val % 5 != 2 )) || sleep 10
+ done
+
+ cmd="$LFS find $dir -ctime -19s -ctime +9s"
+ nums=$($cmd | grep -c c.*)
+
+ (( nums == expected )) ||
+ error "'$cmd' wrong: found $nums, expected $expected"
+
+ local cmd="$LFS find $dir -atime +7h30m -atime -2h30m"
+ local nums=$($cmd | wc -l)
+
+ (( $($cmd | grep -c a.7) == 1 )) ||
+ error "'$cmd' didn't capture file accessed 7 hours ago"
+ (( $($cmd | grep -c a.3) == 1 )) ||
+ error "'$cmd' didn't capture file accessed 3 hours ago"
+ (( nums == expected )) ||
+ error "'$cmd' wrong: found $nums, expected $expected"
+
+ cmd="$LFS find $dir -mtime -7h30m -mtime +2h30m"
+ nums=$($cmd | wc -l)
+
+ (( $($cmd | grep -c m.7) == 1 )) ||
+ error "'$cmd' didn't capture file modified 7 hours ago"
+ (( $($cmd | grep -c m.3) == 1 )) ||
+ error "'$cmd' didn't capture file modified 3 hours ago"
+ (( nums == expected )) ||
+ error "'$cmd' wrong: found $nums, expected $expected"
+}
+run_test 56oe "check lfs find with time range"
+
test_56p() {
[ $RUNAS_ID -eq $UID ] &&
skip_env "RUNAS_ID = UID = $UID -- skipping"
}
#define FP_DEFAULT_TIME_MARGIN (24 * 60 * 60)
-static int set_time(struct find_param *param, time_t *time, time_t *set,
- char *str)
+static int set_time(struct find_param *param, time_t *time, time_t *set_t,
+ int *sign_t, char *str)
{
long long t = 0;
int sign = 0;
char *endptr = "AD";
char *timebuf;
+ time_t prev_set = 0;
+ int prev_sign = 0;
if (str[0] == '+')
sign = 1;
if (sign)
str++;
+ if (*set_t) {
+ prev_set = *set_t;
+ prev_sign = *sign_t;
+ }
+
for (timebuf = str; *endptr && *(endptr + 1); timebuf = endptr + 1) {
long long val = strtoll(timebuf, &endptr, 0);
int unit = 1;
return INT_MAX;
}
- *set = *time - t;
+ *set_t = *time - t;
+ /* if user requested a time range via "-xtime +M -xtime -N" then
+ * use the largest time and increase margin to cover the difference
+ * This will occur as long as the signs differ.
+ */
+ if (sign * prev_sign == -1) {
+ param->fp_time_margin = abs(*set_t - prev_set);
+ if (prev_set > *set_t)
+ *set_t = prev_set;
+ return 0;
+ }
return sign;
}
xsign = ¶m.fp_msign;
param.fp_exclude_mtime = !!neg_opt;
}
- rc = set_time(¶m, &t, xtime, optarg);
+ rc = set_time(¶m, &t, xtime, xsign, optarg);
if (rc == INT_MAX) {
ret = -1;
goto err;
}
- if (rc)
- *xsign = rc;
+ *xsign = rc;
break;
case LFS_ATTRS_OPT:
ret = name2attrs(optarg, ¶m.fp_attrs,