153 Commits

Author SHA1 Message Date
Guillaume Gomez
4c4fdb2abd test: check examples in README
PR #119
2019-05-01 10:52:20 -04:00
Andrew Gallant
830fc25acf
ci: stop testing on MSRV, build only 2019-04-30 13:32:15 -04:00
Andrew Gallant
45deac4d7e
code: remove unnecessary mut 2019-04-30 13:30:48 -04:00
Andrew Gallant
705d06c15d
2.2.7 2.2.7 2018-11-11 09:37:20 -05:00
Andrew Gallant
83b7a24302
walkdir: fix root symlink bug
This commit fixes a nasty bug where the root path given to walkdir was
always reported as a symlink, even when 'follow_links' was enabled. This
appears to be a regression introduced by commit 6f72fce as part of
fixing BurntSushi/ripgrep#984.

The central problem was that since root paths should always be followed,
we were creating a DirEntry whose internal file type was always resolved
by following a symlink, but whose 'metadata' method still returned the
metadata of the symlink and not the target. This was problematic and
inconsistent both with and without 'follow_links' enabled.

We also fix the documentation. In particular, we make the docs of 'new'
more unambiguous, where it previously could have been interpreted as
contradictory to the docs on 'DirEntry'. Specifically, 'WalkDir::new'
says:

    If root is a symlink, then it is always followed.

But the docs for 'DirEntry::metadata' say

    This always calls std::fs::symlink_metadata.

    If this entry is a symbolic link and follow_links is enabled, then
    std::fs::metadata is called instead.

Similarly, 'DirEntry::file_type' said

    If this is a symbolic link and follow_links is true, then this
    returns the type of the target.

That is, if 'root' is a symlink and 'follow_links' is NOT enabled,
then the previous incorrect behavior resulted in 'DirEntry::file_type'
behaving as if 'follow_links' was enabled. If 'follow_links'
was enabled, then the previous incorrect behavior resulted in
'DirEntry::metadata' reporting the metadata of the symlink itself.

We fix this by correctly constructing the DirEntry in the first place,
and then adding special case logic to path traversal that will always
attempt to follow the root path if it's a symlink and 'follow_links'
was not enabled. We also tweak the docs on 'WalkDir::new' to be more
precise.

Fixes #115
2018-11-11 09:32:29 -05:00
Andrew Gallant
4879ce266a
ci: pin to lazy_static 1.1 in CI 2018-11-07 07:17:55 -05:00
Andrew Gallant
99315723f5
2.2.6 2.2.6 2018-10-29 06:59:16 -04:00
Igor Gnatenko
809360416b ci: exclude CI files
PR #114
2018-10-29 06:58:59 -04:00
Andrew Gallant
e6fe17ca98
2.2.5 2.2.5 2018-08-25 10:46:35 -04:00
Andrew Gallant
80a08041e6
deps: update to quickcheck 0.7 2018-08-25 10:46:33 -04:00
Andrew Gallant
07a38b2948
2.2.4 2.2.4 2018-08-24 23:38:31 -04:00
Andrew Gallant
8b72d93227 windows: replace winapi ffi with winapi-util
We do still need winapi for a std-library work-around.
2018-08-24 23:38:09 -04:00
Andrew Gallant
64399797d1
2.2.3 2.2.3 2018-08-24 18:55:32 -04:00
Jacob Finkelman
ddf3f29717 deps: update for minimal-versions
PR #112
2018-08-24 18:55:24 -04:00
Andrew Gallant
edea9ea2d4
2.2.2 2.2.2 2018-08-22 20:47:51 -04:00
Aron Griffis
9a29218ca6 walkdir: add option to stay on same file system
This commit includes a new method, `same_file_system`, which when
enabled, will cause walkdir to only descend into directories that are on
the same file system as the root path.

Closes #8, Closes #107
2018-08-22 20:46:56 -04:00
Andrew Gallant
ddbbe48d56
DirEntry: add into_path method
This can avoid an allocation and copy in iterator chains that need to
produce a PathBuf.

PR #100
2018-08-22 18:46:58 -04:00
Andrew Gallant
987642ce46
2.2.1 2.2.1 2018-08-21 21:49:16 -04:00
Andrew Gallant
6f72fce431
path_is_symlink: fix false positive
This commit fixes a bug where the first path always reported itself as
as symlink via `path_is_symlink`.

Partially fixes https://github.com/BurntSushi/ripgrep/issues/984
2018-08-21 21:41:48 -04:00
Andrew Gallant
7033d12ded
deps: update docopt to 1.0 2018-08-21 21:30:51 -04:00
Andrew Gallant
dbe269c9af
2.2.0 2.2.0 2018-08-04 22:44:37 -04:00
Andrew Gallant
19f24b860e
msrv: bump minimum Rust to 1.23
lazy_static increased there's, so we might as we do ours.
2018-08-04 22:44:04 -04:00
Andrew Gallant
4b21b55f21
redox: remove uses of Unix-only things
The code for `cfg(not(any(unix, windows)))` is untested and contained a few
errors that this commit cleans up.
2018-06-13 12:13:02 -04:00
Jeremy Soller
40d2f56b94 Fix compilation on Redox 2018-06-13 09:47:37 -06:00
Jędrzej
e1f7637cf8 doc: use syntax highlighting in README 2018-05-27 08:59:26 -04:00
Ruud van Asseldonk
73eb575162 add DirEntry::into_path
This can avoid an allocation and copy in iterator chains that need to
produce a PathBuf.
2018-04-09 23:38:40 +02:00
Andrew Gallant
26dc0f584b
2.1.4 2.1.4 2018-02-20 19:24:27 -05:00
Andrew Gallant
ddac44a82a performance: fix regression
This commit fixes a performance regression introduced in commit 0f4441,
which aimed to fix OneDrive traversals. In particular, we added an
additional stat call to every directory entry, which can be quite
disastrous for performance. We fix this by being more fastidious about
reusing the Metadata that comes from fs::DirEntry, which is, conveniently,
cheap to acquire specifically on Windows.

The performance regression was reported against ripgrep:
https://github.com/BurntSushi/ripgrep/issues/820
2018-02-20 19:24:05 -05:00
Andrew Gallant
e3223962fe compile: clean up cfgs
In some cases, we were relying on things like "not(unix)" to mean "windows"
or "not(windows)" to mean "unix". Instead, we should split this in three
cases: unix, windows or not(unix or windows).
2018-02-20 19:24:05 -05:00
Michael Lamparski
44a5dfe6f7 doc: improve stdout in contents_first example
A big potential question on the reader's mind when reviewing these
docs is "what will the paths returned by the iterator be relative
to?" This is the one example on the page which shows output that
could potentially answer that question, and to only see filenames is
needlessly discouraging.
2018-02-10 13:35:49 -05:00
Andrew Gallant
aa8b1544f5
2.1.3 2.1.3 2018-02-01 22:50:59 -05:00
Andrew Gallant
2863f281e7
windows: more carefuly is_dir checking
This fixes a bug where a symlink was followed even if the user did not
request it. Namely, on Windows, a symlink can be interpreted as both a
symlink and a directory, given our new is_dir checking.
2018-02-01 22:50:55 -05:00
Andrew Gallant
dc4c1ccea1
windows: use entry file type
Using fs::metadata will always read through a link, and we want to
preserve the type of the original entry.
2018-02-01 22:49:59 -05:00
Andrew Gallant
01ee572ab4
gitignore: add tmp dir 2018-02-01 22:49:07 -05:00
Andrew Gallant
a838cd6c68
2.1.2 2.1.2 2018-02-01 21:08:20 -05:00
Andrew Gallant
0f4441f9bc
windows: fix OneDrive traversals
This commit fixes a bug on Windows where walkdir refused to traverse
directories that resided on OneDrive via its "file on demand" strategy.
The specific bug is that Rust's standard library treats a reparse point
(which is what OneDrive uses) as distinct from a file or directory, which
wreaks havoc on any code that uses FileType::{is_file, is_dir}. We fix
this by checking the directory status of a file by looking only at whether
its directory bit is set.

This bug was originally reported in ripgrep:
https://github.com/BurntSushi/ripgrep/issues/705

It has also been filed upstream:
https://github.com/rust-lang/rust/issues/46484

And has a pending fix:
https://github.com/rust-lang/rust/pull/47956
2018-02-01 21:08:16 -05:00
Andrew Gallant
42a5b959f1
2.1.1 2.1.1 2018-02-01 17:03:47 -05:00
Andrew Gallant
e2b898329f
traversal: more robust error handling
This fixes a bug in walkdir that happened on Windows when following
symlinks. It was triggered when opening a handle to the symlink failed.
In particular, this resulted in the two stacks in the walkdir iterator
getting out of sync. At some point, this tripped a panic when popping
from one stack would be fine but popping from the other failed because
it was empty.

We fix this by only pushing to both stacks if and only if both pushes
would succeed.

This bug was found via ripgrep. See:
https://github.com/BurntSushi/ripgrep/issues/633#issuecomment-339076246
2018-02-01 17:01:08 -05:00
Andrew Gallant
34857644e6
2.1.0 2.1.0 2018-01-30 20:25:20 -05:00
Garrett Berg
b03670ee30 errors: keep context when converting to io::Error
This commit tweaks the `From<walkdir::Error> for io::Error`
implementation to always retain the current context when
constructing the `io::Error`. This differs from the previous
implementation in that the original raw I/O error is no longer
returned.

To compensate, a new method, `into_io_error`, has been
added which returns the original I/O error, if one exists.

We do not consider this a breaking change because the
documentation for the `From` impl always stated that it
existed for ergonomic reasons. Arguably, the implementation
in this commit is a more faithful reflection of that
documentation.

This commit also clears up the public documentation
surrounding the aforementioned methods.
2018-01-30 20:24:28 -05:00
Jason Grlicky
9775f531be docs: fix a couple broken links 2018-01-17 08:58:56 -05:00
Igor Gnatenko
791d6034cc deps: bump quickcheck to 0.6 and rand to 0.4 2017-12-31 19:44:50 -05:00
Andrew Gallant
cf6d422edb
2.0.1 2.0.1 2017-10-21 18:55:02 -04:00
Andrew Gallant
286bb1f3aa
doc: formatting
Doc strings on public items should always start with a short one
sentence description. This is for readability purposes, and also to make
the display reasonable in rustdoc.
2017-10-21 18:54:21 -04:00
Andrew Gallant
a9f41405c0
deps: remove winapi and kernel32
These are extraneous at this point. The Windows specific logic is now
encapsulated in the same-file crate.
2.0.0
2017-10-21 08:19:18 -04:00
Andrew Gallant
99fe05638d doc: bump version number to 2 2017-10-21 08:10:18 -04:00
Andrew Gallant
bfd917fdfd deps: upgrade to same-file 1.0 2017-10-21 08:10:18 -04:00
Andrew Gallant
3d4c9f7eca symlinks: optimize check loop on Windows
Broadly speaking, this commit is an attempt to fix this issue:
https://github.com/BurntSushi/ripgrep/issues/633

It was reported that symlink checking was taking a long amount of time,
and that one possible way to fix this was to reduce number of times a
file descriptor is opened. In this commit, we amortize opening file
descriptors by keeping a file handle open for each ancestor in the
directory tree. We also open a handle for the candidate file path at
most once, instead of once every iteration.

Note that we only perform this optimization on Windows, where opening a
file handle seems inordinately expensive. In particular, this now causes
us to potentially open more file descriptors than the limit set by the
user, which only happens when following symbolic links. We document this
behavior.
2017-10-21 08:10:18 -04:00
Andrew Gallant
5ce6b10716 style: switch from try! to ? 2017-10-21 08:10:18 -04:00
Andrew Gallant
2b4e508c75 doc: touchups 2017-10-21 08:10:18 -04:00