You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the path passed to WalkDir::new() is a symlink to a file, calling .metadata() on the produced DirEntry returns the metadata of the symlink, rather than its target. This happens irrespective of whether follow_links is set to true or not.
The documentation of WalkDir::new() states that
If root is a file, then it is the first and only item yielded by the iterator. If root is a symlink, then it is always followed.
Given that documentation, I would have assumed that symlinks would always be followed for the metadata. But even if that documentation was not meant to be applied to root files, I would have still assumed that a root symlink would be followed if follow_links is true.
To illustrate the problem use the following demo script:
externcrate walkdir;use walkdir::WalkDir;use std::env;fnmain(){for e inWalkDir::new(env::args_os().skip(1).next().unwrap()).follow_links(true){let e = e.unwrap();println!("is_symlink: {} ({})",
e.metadata().unwrap().file_type().is_symlink(),
e.path().display())}}
If you pass a symlink to a file as an argument to the script, it will print is_symlink: true.
If you pass a directory containing a symlink to a file as an argument, it will print is_symlink: false for the symlink.
The text was updated successfully, but these errors were encountered:
Thanks for the great bug report! This was a bit of a nasty one, I think it was introduced as a regression in 6f72fce. I've committed a fix to master. Once that passes CI, I'll put out a new release.
If the path passed to
WalkDir::new()
is a symlink to a file, calling.metadata()
on the producedDirEntry
returns the metadata of the symlink, rather than its target. This happens irrespective of whetherfollow_links
is set totrue
or not.The documentation of
WalkDir::new()
states thatGiven that documentation, I would have assumed that symlinks would always be followed for the metadata. But even if that documentation was not meant to be applied to root files, I would have still assumed that a root symlink would be followed if
follow_links
istrue
.To illustrate the problem use the following demo script:
If you pass a symlink to a file as an argument to the script, it will print
is_symlink: true
.If you pass a directory containing a symlink to a file as an argument, it will print
is_symlink: false
for the symlink.The text was updated successfully, but these errors were encountered: