Skip to content

Commit ea70a88

Browse files
Use fs::symlink_metadata in doc for is_symlink
fs::metadata() follows symlinks so is_symlink() will always return false. Use symlink_metadata instead in the example in the documentation. See issue rust-lang#39088.
1 parent 74c42ac commit ea70a88

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/libstd/fs.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -975,13 +975,18 @@ impl FileType {
975975

976976
/// Test whether this file type represents a symbolic link.
977977
///
978+
/// The Metadata struct needs to be retreived with
979+
/// fs::symlink_metadata() not fs::metadata(). metadata()
980+
/// always follows symbolic links, so is_symlink will
981+
/// always return false for the underlying file.
982+
///
978983
/// # Examples
979984
///
980985
/// ```
981986
/// # fn foo() -> std::io::Result<()> {
982987
/// use std::fs;
983988
///
984-
/// let metadata = try!(fs::metadata("foo.txt"));
989+
/// let metadata = try!(fs::symlink_metadata("foo.txt"));
985990
/// let file_type = metadata.file_type();
986991
///
987992
/// assert_eq!(file_type.is_symlink(), false);

0 commit comments

Comments
 (0)