Skip to content

Commit 1b06375

Browse files
committed
Auto merge of #39176 - CartesianDaemon:master, r=frewsxcv
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 #39088.
2 parents 9761b17 + f55bbaa commit 1b06375

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/libstd/fs.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -978,13 +978,24 @@ impl FileType {
978978

979979
/// Test whether this file type represents a symbolic link.
980980
///
981+
/// The underlying [`Metadata`] struct needs to be retrieved
982+
/// with the [`fs::symlink_metadata`] function and not the
983+
/// [`fs::metadata`] function. The [`fs::metadata`] function
984+
/// follows symbolic links, so [`is_symlink`] would always
985+
/// return false for the target file.
986+
///
987+
/// [`Metadata`]: struct.Metadata.html
988+
/// [`fs::metadata`]: fn.metadata.html
989+
/// [`fs::symlink_metadata`]: fn.symlink_metadata.html
990+
/// [`is_symlink`]: struct.FileType.html#method.is_symlink
991+
///
981992
/// # Examples
982993
///
983994
/// ```
984995
/// # fn foo() -> std::io::Result<()> {
985996
/// use std::fs;
986997
///
987-
/// let metadata = try!(fs::metadata("foo.txt"));
998+
/// let metadata = try!(fs::symlink_metadata("foo.txt"));
988999
/// let file_type = metadata.file_type();
9891000
///
9901001
/// assert_eq!(file_type.is_symlink(), false);

0 commit comments

Comments
 (0)