-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
82 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,49 @@ | ||
import time | ||
|
||
enum ByTime { | ||
before_modified | ||
before_accessed | ||
before_changed | ||
after_modified | ||
after_accessed | ||
after_changed | ||
} | ||
|
||
fn filter(entries []Entry, options Options) []Entry { | ||
return match true { | ||
// vfmt off | ||
options.only_dirs { entries.clone().filter(it.dir) } | ||
options.only_files { entries.clone().filter(it.file) } | ||
else { entries } | ||
// vfmt on | ||
mut filtered := entries.clone() | ||
|
||
if options.only_dirs { | ||
filtered = filtered.filter(it.dir) | ||
} | ||
|
||
if options.only_files { | ||
filtered = filtered.filter(it.file) | ||
} | ||
|
||
filtered = filter_time(filtered, options.time_before_modified, .before_modified) | ||
filtered = filter_time(filtered, options.time_before_modified, .before_accessed) | ||
filtered = filter_time(filtered, options.time_before_modified, .before_changed) | ||
|
||
filtered = filter_time(filtered, options.time_after_modified, .after_modified) | ||
filtered = filter_time(filtered, options.time_after_accessed, .after_accessed) | ||
filtered = filter_time(filtered, options.time_after_changed, .after_changed) | ||
|
||
return filtered | ||
} | ||
|
||
fn filter_time(entries []Entry, time_str string, by ByTime) []Entry { | ||
if time_str.len == 0 { | ||
return entries | ||
} | ||
|
||
target_time := time.parse_iso8601(time_str) or { exit_error(err.msg()) } | ||
|
||
return match by { | ||
.before_modified { entries.filter(time.unix(it.stat.mtime) < target_time) } | ||
.before_accessed { entries.filter(time.unix(it.stat.atime) < target_time) } | ||
.before_changed { entries.filter(time.unix(it.stat.ctime) < target_time) } | ||
.after_modified { entries.filter(time.unix(it.stat.mtime) > target_time) } | ||
.after_accessed { entries.filter(time.unix(it.stat.atime) > target_time) } | ||
.after_changed { entries.filter(time.unix(it.stat.ctime) > target_time) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters