diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-06-26 17:24:10 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-26 21:24:10 +0000 |
commit | 0da01c0ca6b537f74be32126e567bdfc2c73ed16 (patch) | |
tree | ef29d32cffb03a975a58c16827b0691dda50a5b3 /ext/fs/interface.rs | |
parent | 86e0292733d6d08bf338b68fd50863aef17b1e44 (diff) |
refactor: move PackageJson to deno_config (#24348)
Diffstat (limited to 'ext/fs/interface.rs')
-rw-r--r-- | ext/fs/interface.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/ext/fs/interface.rs b/ext/fs/interface.rs index 833f362bf..6e3c359bb 100644 --- a/ext/fs/interface.rs +++ b/ext/fs/interface.rs @@ -304,6 +304,35 @@ pub trait FileSystem: std::fmt::Debug + MaybeSend + MaybeSync { } } +pub struct DenoConfigFsAdapter<'a>(&'a dyn FileSystem); + +impl<'a> DenoConfigFsAdapter<'a> { + pub fn new(fs: &'a dyn FileSystem) -> Self { + Self(fs) + } +} + +impl<'a> deno_config::fs::DenoConfigFs for DenoConfigFsAdapter<'a> { + fn read_to_string(&self, path: &Path) -> Result<String, std::io::Error> { + use deno_io::fs::FsError; + use std::io::ErrorKind; + self + .0 + .read_text_file_lossy_sync(path, None) + .map_err(|err| match err { + FsError::Io(io) => io, + FsError::FileBusy => std::io::Error::new(ErrorKind::Other, "file busy"), + FsError::NotSupported => { + std::io::Error::new(ErrorKind::Other, "not supported") + } + FsError::PermissionDenied(name) => std::io::Error::new( + ErrorKind::PermissionDenied, + format!("requires {}", name), + ), + }) + } +} + // Like String::from_utf8_lossy but operates on owned values #[inline(always)] fn string_from_utf8_lossy(buf: Vec<u8>) -> String { |