summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-07-05 17:53:09 -0400
committerGitHub <noreply@github.com>2024-07-05 17:53:09 -0400
commit80df9aec1db449e6cc0f4513103aa442b8d43de3 (patch)
treee5a36781b8b75253b4896a2cdfd46116fde5af71 /ext
parentd4d3a3c54f5e26dec0cc79e273dc488f8a47f2b3 (diff)
refactor: move `FileCollector` to deno_config (#24433)
Diffstat (limited to 'ext')
-rw-r--r--ext/fs/interface.rs71
1 files changed, 58 insertions, 13 deletions
diff --git a/ext/fs/interface.rs b/ext/fs/interface.rs
index f639a700b..8f791f4c2 100644
--- a/ext/fs/interface.rs
+++ b/ext/fs/interface.rs
@@ -343,26 +343,71 @@ impl<'a> DenoConfigFsAdapter<'a> {
}
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;
+ fn read_to_string_lossy(
+ &self,
+ path: &Path,
+ ) -> Result<String, std::io::Error> {
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),
- ),
+ .map_err(map_deno_fs_to_config_err)
+ }
+
+ fn stat_sync(
+ &self,
+ path: &Path,
+ ) -> Result<deno_config::fs::FsMetadata, std::io::Error> {
+ self
+ .0
+ .stat_sync(path)
+ .map(|stat| deno_config::fs::FsMetadata {
+ is_file: stat.is_file,
+ is_directory: stat.is_directory,
+ is_symlink: stat.is_symlink,
+ })
+ .map_err(map_deno_fs_to_config_err)
+ }
+
+ fn read_dir(
+ &self,
+ path: &Path,
+ ) -> Result<Vec<deno_config::fs::FsDirEntry>, std::io::Error> {
+ self
+ .0
+ .read_dir_sync(path)
+ .map_err(map_deno_fs_to_config_err)
+ .map(|entries| {
+ entries
+ .into_iter()
+ .map(|e| deno_config::fs::FsDirEntry {
+ path: path.join(e.name),
+ metadata: deno_config::fs::FsMetadata {
+ is_file: e.is_file,
+ is_directory: e.is_directory,
+ is_symlink: e.is_symlink,
+ },
+ })
+ .collect()
})
}
}
+fn map_deno_fs_to_config_err(fs_err: deno_io::fs::FsError) -> std::io::Error {
+ use deno_io::fs::FsError;
+ use std::io::ErrorKind;
+ match fs_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 {