summaryrefslogtreecommitdiff
path: root/ext/node/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node/lib.rs')
-rw-r--r--ext/node/lib.rs24
1 files changed, 22 insertions, 2 deletions
diff --git a/ext/node/lib.rs b/ext/node/lib.rs
index 12d7b0b1e..04fd07cab 100644
--- a/ext/node/lib.rs
+++ b/ext/node/lib.rs
@@ -52,8 +52,11 @@ pub trait NodePermissions {
pub trait NodeFs {
fn current_dir() -> io::Result<PathBuf>;
- fn metadata<P: AsRef<Path>>(path: P) -> io::Result<std::fs::Metadata>;
+ fn is_file<P: AsRef<Path>>(path: P) -> bool;
+ fn is_dir<P: AsRef<Path>>(path: P) -> bool;
+ fn exists<P: AsRef<Path>>(path: P) -> bool;
fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String>;
+ fn canonicalize<P: AsRef<Path>>(path: P) -> io::Result<PathBuf>;
}
pub struct RealFs;
@@ -63,15 +66,32 @@ impl NodeFs for RealFs {
std::env::current_dir()
}
- fn metadata<P: AsRef<Path>>(path: P) -> io::Result<std::fs::Metadata> {
+ fn exists<P: AsRef<Path>>(path: P) -> bool {
+ #[allow(clippy::disallowed_methods)]
+ std::fs::metadata(path).is_ok()
+ }
+
+ fn is_file<P: AsRef<Path>>(path: P) -> bool {
#[allow(clippy::disallowed_methods)]
std::fs::metadata(path)
+ .map(|m| m.is_file())
+ .unwrap_or(false)
+ }
+
+ fn is_dir<P: AsRef<Path>>(path: P) -> bool {
+ #[allow(clippy::disallowed_methods)]
+ std::fs::metadata(path).map(|m| m.is_dir()).unwrap_or(false)
}
fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
#[allow(clippy::disallowed_methods)]
std::fs::read_to_string(path)
}
+
+ fn canonicalize<P: AsRef<Path>>(path: P) -> io::Result<PathBuf> {
+ #[allow(clippy::disallowed_methods)]
+ std::path::Path::canonicalize(path.as_ref())
+ }
}
pub trait RequireNpmResolver {