Merge branch 'pr/opposing-options' of https://github.com/Asha20/fd into pr/opposing-options

This commit is contained in:
Vukašin Stepanović 2021-08-23 15:28:45 +02:00
commit 8da936abd8
10 changed files with 243 additions and 111 deletions

View File

@ -16,7 +16,7 @@ on:
jobs: jobs:
min_version: min_version:
name: Minimum supported rust version name: Minimum supported rust version
runs-on: ubuntu-18.04 runs-on: ubuntu-20.04
steps: steps:
- name: Checkout source code - name: Checkout source code
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -45,13 +45,13 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
job: job:
- { os: ubuntu-18.04, target: arm-unknown-linux-gnueabihf , use-cross: true } - { os: ubuntu-20.04, target: arm-unknown-linux-gnueabihf , use-cross: true }
- { os: ubuntu-18.04, target: arm-unknown-linux-musleabihf, use-cross: true } - { os: ubuntu-20.04, target: arm-unknown-linux-musleabihf, use-cross: true }
- { os: ubuntu-18.04, target: aarch64-unknown-linux-gnu , use-cross: true } - { os: ubuntu-20.04, target: aarch64-unknown-linux-gnu , use-cross: true }
- { os: ubuntu-18.04, target: i686-unknown-linux-gnu , use-cross: true } - { os: ubuntu-20.04, target: i686-unknown-linux-gnu , use-cross: true }
- { os: ubuntu-18.04, target: i686-unknown-linux-musl , use-cross: true } - { os: ubuntu-20.04, target: i686-unknown-linux-musl , use-cross: true }
- { os: ubuntu-18.04, target: x86_64-unknown-linux-gnu } - { os: ubuntu-20.04, target: x86_64-unknown-linux-gnu }
- { os: ubuntu-18.04, target: x86_64-unknown-linux-musl , use-cross: true } - { os: ubuntu-20.04, target: x86_64-unknown-linux-musl , use-cross: true }
- { os: macos-10.15 , target: x86_64-apple-darwin } - { os: macos-10.15 , target: x86_64-apple-darwin }
# - { os: windows-2019, target: i686-pc-windows-gnu } ## disabled; error: linker `i686-w64-mingw32-gcc` not found # - { os: windows-2019, target: i686-pc-windows-gnu } ## disabled; error: linker `i686-w64-mingw32-gcc` not found
- { os: windows-2019, target: i686-pc-windows-msvc } - { os: windows-2019, target: i686-pc-windows-msvc }

View File

@ -10,6 +10,8 @@
- fd cannot search files under a RAM disk, see #752 - fd cannot search files under a RAM disk, see #752
- fd doesn't show substituted drive on Windows, see #365 - fd doesn't show substituted drive on Windows, see #365
- Properly handle write errors to devices that are full, see #737 - Properly handle write errors to devices that are full, see #737
- Use local time zone for time functions (`--change-newer-than`, `--change-older-than`), see #631 (@jacobmischka)
- Support `--list-details` on more platforms (like BusyBox), see #783
## Changes ## Changes

162
Cargo.lock generated
View File

@ -60,24 +60,18 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]] [[package]]
name = "bstr" name = "bstr"
version = "0.2.14" version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "473fc6b38233f9af7baa94fb5852dca389e3d95b8e21c8e3719301462c5d9faf" checksum = "90682c8d613ad3373e66de8c6411e0ae2ab2571e879d2efbf73558cc66f21279"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.0.66" version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48" checksum = "e70cc2f62c6ce1868963827bd677764c62d07c3d9a3e1fb1177ee1a9ab199eb2"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
@ -85,6 +79,19 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"libc",
"num-integer",
"num-traits",
"time",
"winapi",
]
[[package]] [[package]]
name = "clap" name = "clap"
version = "2.33.3" version = "2.33.3"
@ -103,20 +110,19 @@ dependencies = [
[[package]] [[package]]
name = "crossbeam-utils" name = "crossbeam-utils"
version = "0.8.1" version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db"
dependencies = [ dependencies = [
"autocfg", "cfg-if",
"cfg-if 1.0.0",
"lazy_static", "lazy_static",
] ]
[[package]] [[package]]
name = "ctrlc" name = "ctrlc"
version = "3.1.9" version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "232295399409a8b7ae41276757b5a1cc21032848d42bff2352261f958b3ca29a" checksum = "377c9b002a72a0b2c1a18c62e2f3864bdfea4a015e3683a96e24aa45dd6c02d1"
dependencies = [ dependencies = [
"nix", "nix",
"winapi", "winapi",
@ -134,15 +140,15 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"dirs-sys-next", "dirs-sys-next",
] ]
[[package]] [[package]]
name = "dirs-sys-next" name = "dirs-sys-next"
version = "0.1.1" version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99de365f605554ae33f115102a02057d4fc18b01f3284d6870be0938743cfe7d" checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
dependencies = [ dependencies = [
"libc", "libc",
"redox_users", "redox_users",
@ -156,6 +162,7 @@ dependencies = [
"ansi_term 0.12.1", "ansi_term 0.12.1",
"anyhow", "anyhow",
"atty", "atty",
"chrono",
"clap", "clap",
"ctrlc", "ctrlc",
"diff", "diff",
@ -180,13 +187,13 @@ dependencies = [
[[package]] [[package]]
name = "filetime" name = "filetime"
version = "0.2.14" version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d34cfa13a63ae058bfa601fe9e313bbdb3746427c1459185464ce0fcf62e1e8" checksum = "975ccf83d8d9d0d84682850a38c8169027be83368805971cc4f238c2b245bc98"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"libc", "libc",
"redox_syscall 0.2.10", "redox_syscall",
"winapi", "winapi",
] ]
@ -210,11 +217,11 @@ checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.1.15" version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753"
dependencies = [ dependencies = [
"cfg-if 0.1.10", "cfg-if",
"libc", "libc",
"wasi", "wasi",
] ]
@ -234,24 +241,24 @@ dependencies = [
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.1.17" version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [ dependencies = [
"libc", "libc",
] ]
[[package]] [[package]]
name = "humantime" name = "humantime"
version = "2.0.1" version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c1ad908cc71012b7bea4d0c53ba96a8cba9962f048fa68d143376143d863b7a" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]] [[package]]
name = "ignore" name = "ignore"
version = "0.4.17" version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b287fb45c60bb826a0dc68ff08742b9d88a2fea13d6e0c286b3172065aaf878c" checksum = "713f1b139373f96a2e0ce3ac931cd01ee973c3c5dd7c40c0c2efe96ad2b6751d"
dependencies = [ dependencies = [
"crossbeam-utils", "crossbeam-utils",
"globset", "globset",
@ -294,17 +301,17 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.98" version = "0.2.99"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790" checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765"
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.11" version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
dependencies = [ dependencies = [
"cfg-if 0.1.10", "cfg-if",
] ]
[[package]] [[package]]
@ -323,15 +330,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc"
[[package]] [[package]]
name = "nix" name = "memoffset"
version = "0.20.0" version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa9b4819da1bc61c0ea48b63b7bc8604064dd43013e7cc325df098d49cd7c18a" checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9"
dependencies = [
"autocfg",
]
[[package]]
name = "nix"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1e25ee6b412c2a1e3fcb6a4499a5c1bfe7f43e014bdce9a6b6666e5aa2d187"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cc", "cc",
"cfg-if 1.0.0", "cfg-if",
"libc", "libc",
"memoffset",
] ]
[[package]] [[package]]
@ -343,6 +360,25 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "num-integer"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "num_cpus" name = "num_cpus"
version = "1.13.0" version = "1.13.0"
@ -353,6 +389,12 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "once_cell"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.28" version = "1.0.28"
@ -408,12 +450,6 @@ dependencies = [
"rand_core 0.3.1", "rand_core 0.3.1",
] ]
[[package]]
name = "redox_syscall"
version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.2.10" version = "0.2.10"
@ -425,12 +461,12 @@ dependencies = [
[[package]] [[package]]
name = "redox_users" name = "redox_users"
version = "0.3.5" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64"
dependencies = [ dependencies = [
"getrandom", "getrandom",
"redox_syscall 0.1.57", "redox_syscall",
] ]
[[package]] [[package]]
@ -511,7 +547,7 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b114ece25254e97bf48dd4bfc2a12bad0647adacfe4cae1247a9ca6ad302cec" checksum = "3b114ece25254e97bf48dd4bfc2a12bad0647adacfe4cae1247a9ca6ad302cec"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn",
@ -530,11 +566,21 @@ dependencies = [
[[package]] [[package]]
name = "thread_local" name = "thread_local"
version = "1.0.1" version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd"
dependencies = [ dependencies = [
"lazy_static", "once_cell",
]
[[package]]
name = "time"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
dependencies = [
"libc",
"winapi",
] ]
[[package]] [[package]]
@ -573,9 +619,9 @@ checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
[[package]] [[package]]
name = "walkdir" name = "walkdir"
version = "2.3.1" version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56"
dependencies = [ dependencies = [
"same-file", "same-file",
"winapi", "winapi",
@ -584,9 +630,9 @@ dependencies = [
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.9.0+wasi-snapshot-preview1" version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]] [[package]]
name = "winapi" name = "winapi"

View File

@ -48,6 +48,7 @@ globset = "0.4"
anyhow = "1.0" anyhow = "1.0"
dirs-next = "2.0" dirs-next = "2.0"
normpath = "0.3" normpath = "0.3"
chrono = "0.4"
[dependencies.clap] [dependencies.clap]
version = "2.31.2" version = "2.31.2"

View File

@ -115,6 +115,15 @@ src/lscolors/mod.rs
tests/testenv/mod.rs tests/testenv/mod.rs
``` ```
### Searching for a particular file name
To find files with exactly the provided search pattern, use the `-g` (or `--glob`) option:
``` bash
> fd -g libc.so /usr
/usr/lib32/libc.so
/usr/lib/libc.so
```
### Hidden and ignored files ### Hidden and ignored files
By default, *fd* does not search hidden directories and does not show hidden files in the By default, *fd* does not search hidden directories and does not show hidden files in the
search results. To disable this behavior, we can use the `-H` (or `--hidden`) option: search results. To disable this behavior, we can use the `-H` (or `--hidden`) option:
@ -136,6 +145,15 @@ target/debug/deps/libnum_cpus-f5ce7ef99006aa05.rlib
To really search *all* files and directories, simply combine the hidden and ignore features to show To really search *all* files and directories, simply combine the hidden and ignore features to show
everything (`-HI`). everything (`-HI`).
### Matching the full path
By default, *fd* only matches the filename of each file. However, using the `--full-path` or `-p` option,
you can match against the full path.
```bash
> fd -p -g '**/.git/config'
> fd -p '.*/lesson-\d+/[a-z]+.(jpg|png)'
```
### Command execution ### Command execution
Instead of just showing the search results, you often want to *do something* with them. `fd` Instead of just showing the search results, you often want to *do something* with them. `fd`
@ -623,6 +641,8 @@ cargo install fd-find
``` ```
Note that rust version *1.42.0* or later is required. Note that rust version *1.42.0* or later is required.
`make` is also needed for the build.
### From binaries ### From binaries
The [release page](https://github.com/sharkdp/fd/releases) includes precompiled binaries for Linux, macOS and Windows. Statically-linked binaries are also available: look for archives with `musl` in the file name. The [release page](https://github.com/sharkdp/fd/releases) includes precompiled binaries for Linux, macOS and Windows. Statically-linked binaries are also available: look for archives with `musl` in the file name.
@ -647,6 +667,7 @@ cargo install --path .
- [sharkdp](https://github.com/sharkdp) - [sharkdp](https://github.com/sharkdp)
- [tmccombs](https://github.com/tmccombs) - [tmccombs](https://github.com/tmccombs)
- [tavianator](https://github.com/tavianator) - [tavianator](https://github.com/tavianator)
- [pemistahl](https://github.com/pemistahl/)
## License ## License

15
doc/fd.1 vendored
View File

@ -57,6 +57,7 @@ pattern contains an uppercase character (smart case).
.TP .TP
.B \-g, \-\-glob .B \-g, \-\-glob
Perform a glob-based search instead of a regular expression search. Perform a glob-based search instead of a regular expression search.
If combined with the '\-\-full-path' option, '**' can be used to match multiple path components.
.TP .TP
.B \-\-regex .B \-\-regex
Perform a regular-expression based search (default). This can be used to override --glob. Perform a regular-expression based search (default). This can be used to override --glob.
@ -219,8 +220,11 @@ tebibytes
.RE .RE
.TP .TP
.BI "\-\-changed-within " date|duration .BI "\-\-changed-within " date|duration
Filter results based on the file modification time. The argument can be provided as a specific Filter results based on the file modification time.
point in time (\fIYYYY-MM-DD HH:MM:SS\fR) or as a duration (\fI10h, 1d, 35min\fR). Files with modification times greater than or equal to the argument will be returned.
The argument can be provided as a duration (\fI10h, 1d, 35min\fR) or as a specific point
in time in either full RFC3339 format with time zone, or as a date or datetime in the
local time zone (\fIYYYY-MM-DD\fR or \fIYYYY-MM-DD HH:MM:SS\fR).
.B --change-newer-than .B --change-newer-than
can be used as an alias. can be used as an alias.
@ -229,8 +233,11 @@ Examples:
\-\-change-newer-than "2018-10-27 10:00:00" \-\-change-newer-than "2018-10-27 10:00:00"
.TP .TP
.BI "\-\-changed-before " date|duration .BI "\-\-changed-before " date|duration
Filter results based on the file modification time. The argument can be provided as a specific Filter results based on the file modification time.
point in time (\fIYYYY-MM-DD HH:MM:SS\fR) or as a duration (\fI10h, 1d, 35min\fR). Files with modification times less than or equal to the argument will be returned.
The argument can be provided as a duration (\fI10h, 1d, 35min\fR) or as a specific point
in time in either full RFC3339 format with time zone, or as a date or datetime in the
local time zone (\fIYYYY-MM-DD\fR or \fIYYYY-MM-DD HH:MM:SS\fR).
.B --change-older-than .B --change-older-than
can be used as an alias. can be used as an alias.

View File

@ -1,3 +1,6 @@
use crate::filesystem;
use crate::walk;
/// Whether or not to show /// Whether or not to show
pub struct FileTypes { pub struct FileTypes {
pub files: bool, pub files: bool,
@ -22,3 +25,28 @@ impl Default for FileTypes {
} }
} }
} }
impl FileTypes {
pub fn should_ignore(&self, entry: &walk::DirEntry) -> bool {
if let Some(ref entry_type) = entry.file_type() {
(!self.files && entry_type.is_file())
|| (!self.directories && entry_type.is_dir())
|| (!self.symlinks && entry_type.is_symlink())
|| (!self.sockets && filesystem::is_socket(*entry_type))
|| (!self.pipes && filesystem::is_pipe(*entry_type))
|| (self.executables_only
&& !entry
.metadata()
.map(|m| filesystem::is_executable(&m))
.unwrap_or(false))
|| (self.empty_only && !filesystem::is_empty(&entry))
|| !(entry_type.is_file()
|| entry_type.is_dir()
|| entry_type.is_symlink()
|| filesystem::is_socket(*entry_type)
|| filesystem::is_pipe(*entry_type))
} else {
true
}
}
}

View File

@ -1,3 +1,5 @@
use chrono::{offset::TimeZone, DateTime, Local, NaiveDate};
use std::time::SystemTime; use std::time::SystemTime;
/// Filter based on time ranges. /// Filter based on time ranges.
@ -11,9 +13,20 @@ impl TimeFilter {
fn from_str(ref_time: &SystemTime, s: &str) -> Option<SystemTime> { fn from_str(ref_time: &SystemTime, s: &str) -> Option<SystemTime> {
humantime::parse_duration(s) humantime::parse_duration(s)
.map(|duration| *ref_time - duration) .map(|duration| *ref_time - duration)
.or_else(|_| humantime::parse_rfc3339_weak(s))
.or_else(|_| humantime::parse_rfc3339_weak(&(s.to_owned() + " 00:00:00")))
.ok() .ok()
.or_else(|| {
DateTime::parse_from_rfc3339(s)
.map(|dt| dt.into())
.ok()
.or_else(|| {
NaiveDate::parse_from_str(s, "%F")
.map(|nd| nd.and_hms(0, 0, 0))
.ok()
.and_then(|ndt| Local.from_local_datetime(&ndt).single())
})
.or_else(|| Local.datetime_from_str(s, "%F %T").ok())
.map(|dt| dt.into())
})
} }
pub fn before(ref_time: &SystemTime, s: &str) -> Option<TimeFilter> { pub fn before(ref_time: &SystemTime, s: &str) -> Option<TimeFilter> {
@ -39,7 +52,11 @@ mod tests {
#[test] #[test]
fn is_time_filter_applicable() { fn is_time_filter_applicable() {
let ref_time = humantime::parse_rfc3339("2010-10-10T10:10:10Z").unwrap(); let ref_time = Local
.datetime_from_str("2010-10-10 10:10:10", "%F %T")
.unwrap()
.into();
assert!(TimeFilter::after(&ref_time, "1min") assert!(TimeFilter::after(&ref_time, "1min")
.unwrap() .unwrap()
.applies_to(&ref_time)); .applies_to(&ref_time));
@ -76,5 +93,39 @@ mod tests {
assert!(!TimeFilter::after(&ref_time, t10s_before) assert!(!TimeFilter::after(&ref_time, t10s_before)
.unwrap() .unwrap()
.applies_to(&t1m_ago)); .applies_to(&t1m_ago));
let same_day = "2010-10-10";
assert!(!TimeFilter::before(&ref_time, same_day)
.unwrap()
.applies_to(&ref_time));
assert!(!TimeFilter::before(&ref_time, same_day)
.unwrap()
.applies_to(&t1m_ago));
assert!(TimeFilter::after(&ref_time, same_day)
.unwrap()
.applies_to(&ref_time));
assert!(TimeFilter::after(&ref_time, same_day)
.unwrap()
.applies_to(&t1m_ago));
let ref_time = DateTime::parse_from_rfc3339("2010-10-10T10:10:10+00:00")
.unwrap()
.into();
let t1m_ago = ref_time - Duration::from_secs(60);
let t10s_before = "2010-10-10T10:10:00+00:00";
assert!(!TimeFilter::before(&ref_time, t10s_before)
.unwrap()
.applies_to(&ref_time));
assert!(TimeFilter::before(&ref_time, t10s_before)
.unwrap()
.applies_to(&t1m_ago));
assert!(TimeFilter::after(&ref_time, t10s_before)
.unwrap()
.applies_to(&ref_time));
assert!(!TimeFilter::after(&ref_time, t10s_before)
.unwrap()
.applies_to(&t1m_ago));
} }
} }

View File

@ -210,11 +210,13 @@ fn run() -> Result<ExitCode> {
#[allow(unused)] #[allow(unused)]
let gnu_ls = |command_name| { let gnu_ls = |command_name| {
// Note: we use short options here (instead of --long-options) to support more
// platforms (like BusyBox).
vec![ vec![
command_name, command_name,
"-l", // long listing format "-l", // long listing format
"--human-readable", // human readable file sizes "-h", // human readable file sizes
"--directory", // list directories themselves, not their contents "-d", // list directories themselves, not their contents
&color_arg, &color_arg,
] ]
}; };

View File

@ -358,27 +358,21 @@ fn spawn_senders(
DirEntry::BrokenSymlink(path) DirEntry::BrokenSymlink(path)
} }
_ => { _ => {
match tx_thread.send(WorkerResult::Error(ignore::Error::WithPath { return match tx_thread.send(WorkerResult::Error(ignore::Error::WithPath {
path, path,
err: inner_err, err: inner_err,
})) { })) {
Ok(_) => { Ok(_) => ignore::WalkState::Continue,
return ignore::WalkState::Continue; Err(_) => ignore::WalkState::Quit,
}
Err(_) => {
return ignore::WalkState::Quit;
}
} }
} }
}, },
Err(err) => match tx_thread.send(WorkerResult::Error(err)) { Err(err) => {
Ok(_) => { return match tx_thread.send(WorkerResult::Error(err)) {
return ignore::WalkState::Continue; Ok(_) => ignore::WalkState::Continue,
Err(_) => ignore::WalkState::Quit,
} }
Err(_) => { }
return ignore::WalkState::Quit;
}
},
}; };
if let Some(min_depth) = config.min_depth { if let Some(min_depth) = config.min_depth {
@ -422,27 +416,7 @@ fn spawn_senders(
// Filter out unwanted file types. // Filter out unwanted file types.
if let Some(ref file_types) = config.file_types { if let Some(ref file_types) = config.file_types {
if let Some(ref entry_type) = entry.file_type() { if file_types.should_ignore(&entry) {
if (!file_types.files && entry_type.is_file())
|| (!file_types.directories && entry_type.is_dir())
|| (!file_types.symlinks && entry_type.is_symlink())
|| (!file_types.sockets && filesystem::is_socket(*entry_type))
|| (!file_types.pipes && filesystem::is_pipe(*entry_type))
|| (file_types.executables_only
&& !entry
.metadata()
.map(|m| filesystem::is_executable(&m))
.unwrap_or(false))
|| (file_types.empty_only && !filesystem::is_empty(&entry))
|| !(entry_type.is_file()
|| entry_type.is_dir()
|| entry_type.is_symlink()
|| filesystem::is_socket(*entry_type)
|| filesystem::is_pipe(*entry_type))
{
return ignore::WalkState::Continue;
}
} else {
return ignore::WalkState::Continue; return ignore::WalkState::Continue;
} }
} }