Skip to content

Commit

Permalink
Add an unstable FileTypeExt extension trait for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
retep998 committed Feb 11, 2018
1 parent c42d76d commit 9269e83
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/libstd/sys/windows/ext/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,24 @@ impl MetadataExt for Metadata {
fn file_size(&self) -> u64 { self.as_inner().size() }
}

/// Add support for the Windows specific fact that a symbolic link knows whether it is a file
/// or directory.
#[unstable(feature = "windows_file_type_ext", issue = "0")]
pub trait FileTypeExt {
/// Returns whether this file type is a symbolic link that is also a directory.
#[unstable(feature = "windows_file_type_ext", issue = "0")]
fn is_symlink_dir(&self) -> bool;
/// Returns whether this file type is a symbolic link that is also a file.
#[unstable(feature = "windows_file_type_ext", issue = "0")]
fn is_symlink_file(&self) -> bool;
}

#[unstable(feature = "windows_file_type_ext", issue = "0")]
impl FileTypeExt for fs::FileType {
fn is_symlink_dir(&self) -> bool { self.as_inner().is_symlink_dir() }
fn is_symlink_file(&self) -> bool { self.as_inner().is_symlink_file() }
}

/// Creates a new file symbolic link on the filesystem.
///
/// The `dst` path will be a file symbolic link pointing to the `src`
Expand Down
3 changes: 3 additions & 0 deletions src/libstd/sys/windows/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,9 @@ impl FileType {
pub fn is_symlink_dir(&self) -> bool {
self.is_symlink() && self.is_directory()
}
pub fn is_symlink_file(&self) -> bool {
self.is_symlink() && !self.is_directory()
}
fn is_directory(&self) -> bool {
self.attributes & c::FILE_ATTRIBUTE_DIRECTORY != 0
}
Expand Down

0 comments on commit 9269e83

Please sign in to comment.