Skip to content

Commit 1d7f345

Browse files
committed
Restore original meaning of std::fs::read_dir's example changed in #33958.
DirEntry.file_type().is_dir() will not follow symlinks, but the original example (fs::metadata(&path).is_dir()) does. Therefore the change in #33958 introduced a subtle difference that now it won't enter linked folders. To preserve the same behavior, we use Path::is_dir() instead, which does follow symlink.
1 parent 806a553 commit 1d7f345

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/libstd/fs.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1341,8 +1341,9 @@ pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
13411341
/// if dir.is_dir() {
13421342
/// for entry in try!(fs::read_dir(dir)) {
13431343
/// let entry = try!(entry);
1344-
/// if try!(entry.file_type()).is_dir() {
1345-
/// try!(visit_dirs(&entry.path(), cb));
1344+
/// let path = entry.path();
1345+
/// if path.is_dir() {
1346+
/// try!(visit_dirs(&path, cb));
13461347
/// } else {
13471348
/// cb(&entry);
13481349
/// }

0 commit comments

Comments
 (0)