summaryrefslogtreecommitdiffstats
path: root/openat/src/filetype.rs
diff options
context:
space:
mode:
Diffstat (limited to 'openat/src/filetype.rs')
-rw-r--r--openat/src/filetype.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/openat/src/filetype.rs b/openat/src/filetype.rs
new file mode 100644
index 0000000..efaedbe
--- /dev/null
+++ b/openat/src/filetype.rs
@@ -0,0 +1,33 @@
+use std::fs::Metadata;
+
+/// This is a simplified file type enum that is easy to match
+///
+/// It doesn't represent all the options, because that enum needs to extensible
+/// but most application do not actually need that power, so we provide
+/// this simplified enum that works for many appalications.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum SimpleType {
+ /// Entry is a symlink
+ Symlink,
+ /// Entry is a directory
+ Dir,
+ /// Entry is a regular file
+ File,
+ /// Entry is neither a symlink, directory nor a regular file
+ Other,
+}
+
+impl SimpleType {
+ /// Find out a simple type from a file Metadata (stat)
+ pub fn extract(stat: &Metadata) -> SimpleType {
+ if stat.file_type().is_symlink() {
+ SimpleType::Symlink
+ } else if stat.is_dir() {
+ SimpleType::Dir
+ } else if stat.is_file() {
+ SimpleType::File
+ } else {
+ SimpleType::Other
+ }
+ }
+}