Skip to content

Commit 9269e83

Browse files
committed
Add an unstable FileTypeExt extension trait for Windows
1 parent c42d76d commit 9269e83

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/libstd/sys/windows/ext/fs.rs

+18
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,24 @@ impl MetadataExt for Metadata {
445445
fn file_size(&self) -> u64 { self.as_inner().size() }
446446
}
447447

448+
/// Add support for the Windows specific fact that a symbolic link knows whether it is a file
449+
/// or directory.
450+
#[unstable(feature = "windows_file_type_ext", issue = "0")]
451+
pub trait FileTypeExt {
452+
/// Returns whether this file type is a symbolic link that is also a directory.
453+
#[unstable(feature = "windows_file_type_ext", issue = "0")]
454+
fn is_symlink_dir(&self) -> bool;
455+
/// Returns whether this file type is a symbolic link that is also a file.
456+
#[unstable(feature = "windows_file_type_ext", issue = "0")]
457+
fn is_symlink_file(&self) -> bool;
458+
}
459+
460+
#[unstable(feature = "windows_file_type_ext", issue = "0")]
461+
impl FileTypeExt for fs::FileType {
462+
fn is_symlink_dir(&self) -> bool { self.as_inner().is_symlink_dir() }
463+
fn is_symlink_file(&self) -> bool { self.as_inner().is_symlink_file() }
464+
}
465+
448466
/// Creates a new file symbolic link on the filesystem.
449467
///
450468
/// The `dst` path will be a file symbolic link pointing to the `src`

src/libstd/sys/windows/fs.rs

+3
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,9 @@ impl FileType {
534534
pub fn is_symlink_dir(&self) -> bool {
535535
self.is_symlink() && self.is_directory()
536536
}
537+
pub fn is_symlink_file(&self) -> bool {
538+
self.is_symlink() && !self.is_directory()
539+
}
537540
fn is_directory(&self) -> bool {
538541
self.attributes & c::FILE_ATTRIBUTE_DIRECTORY != 0
539542
}

0 commit comments

Comments
 (0)