This is what FileType on Windows should ideally be.

This commit is contained in:
Peter Atashian 2018-02-01 20:18:33 -05:00
parent 56733bc9f8
commit b1b9edf5ae
No known key found for this signature in database
GPG key ID: DE04D9E27559BC8A

View file

@ -38,8 +38,9 @@ pub struct FileAttr {
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub enum FileType {
Dir, File, SymlinkFile, SymlinkDir, ReparsePoint, MountPoint,
pub struct FileType {
attributes: c::DWORD,
reparse_tag: c::DWORD,
}
pub struct ReadDir {
@ -516,30 +517,28 @@ impl FilePermissions {
impl FileType {
fn new(attrs: c::DWORD, reparse_tag: c::DWORD) -> FileType {
match (attrs & c::FILE_ATTRIBUTE_DIRECTORY != 0,
attrs & c::FILE_ATTRIBUTE_REPARSE_POINT != 0,
reparse_tag) {
(false, false, _) => FileType::File,
(true, false, _) => FileType::Dir,
(false, true, c::IO_REPARSE_TAG_SYMLINK) => FileType::SymlinkFile,
(true, true, c::IO_REPARSE_TAG_SYMLINK) => FileType::SymlinkDir,
(true, true, c::IO_REPARSE_TAG_MOUNT_POINT) => FileType::MountPoint,
(_, true, _) => FileType::ReparsePoint,
// Note: if a _file_ has a reparse tag of the type IO_REPARSE_TAG_MOUNT_POINT it is
// invalid, as junctions always have to be dirs. We set the filetype to ReparsePoint
// to indicate it is something symlink-like, but not something you can follow.
FileType {
attributes: attrs,
reparse_tag: reparse_tag,
}
}
pub fn is_dir(&self) -> bool { *self == FileType::Dir }
pub fn is_file(&self) -> bool { *self == FileType::File }
pub fn is_dir(&self) -> bool {
self.attributes & c::FILE_ATTRIBUTE_DIRECTORY != 0
}
pub fn is_file(&self) -> bool {
self.attributes & c::FILE_ATTRIBUTE_DIRECTORY == 0
}
pub fn is_symlink(&self) -> bool {
*self == FileType::SymlinkFile ||
*self == FileType::SymlinkDir ||
*self == FileType::MountPoint
self.is_reparse_point() && (
self.reparse_tag == c::IO_REPARSE_TAG_SYMLINK ||
self.reparse_tag == c::IO_REPARSE_TAG_MOUNT_POINT)
}
pub fn is_symlink_dir(&self) -> bool {
*self == FileType::SymlinkDir || *self == FileType::MountPoint
self.is_symlink() && self.is_dir()
}
pub fn is_reparse_point(&self) -> bool {
self.attributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0
}
}