From bcbdaac7e6399870b5b6fcdf765013c1682fe80c Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 17 Apr 2023 16:10:59 +0200 Subject: chore(ext/fs): decouple fs trait from deno_core (#18732) This commit removes the dependencies on `deno_core` for the Fs trait. This allows to move the trait into a different crate that does not depend on core in the limit. This adds a new `bounds` field to `deno_core::extension!` that expands to `where` clauses on the generated code. This allows to add bounds to the extension parameters, such as `Fs::File: Resource`. --- ext/fs/interface.rs | 63 +---------------------------------------------------- 1 file changed, 1 insertion(+), 62 deletions(-) (limited to 'ext/fs/interface.rs') diff --git a/ext/fs/interface.rs b/ext/fs/interface.rs index a68260051..184cb8096 100644 --- a/ext/fs/interface.rs +++ b/ext/fs/interface.rs @@ -5,32 +5,8 @@ use std::path::Path; use std::path::PathBuf; use std::rc::Rc; -use deno_core::error::not_supported; -use deno_core::error::resource_unavailable; -use deno_core::error::AnyError; -use deno_core::Resource; use serde::Deserialize; use serde::Serialize; -use tokio::task::JoinError; - -pub trait FsPermissions { - fn check_read(&mut self, p: &Path, api_name: &str) -> Result<(), AnyError>; - fn check_read_all(&mut self, api_name: &str) -> Result<(), AnyError>; - fn check_read_blind( - &mut self, - p: &Path, - display: &str, - api_name: &str, - ) -> Result<(), AnyError>; - fn check_write(&mut self, p: &Path, api_name: &str) -> Result<(), AnyError>; - fn check_write_all(&mut self, api_name: &str) -> Result<(), AnyError>; - fn check_write_blind( - &mut self, - p: &Path, - display: &str, - api_name: &str, - ) -> Result<(), AnyError>; -} #[derive(Deserialize, Default, Debug, Clone, Copy)] #[serde(rename_all = "camelCase")] @@ -74,21 +50,6 @@ impl OpenOptions { mode, } } - - pub(crate) fn check( - &self, - permissions: &mut P, - path: &Path, - api_name: &str, - ) -> Result<(), AnyError> { - if self.read { - permissions.check_read(path, api_name)?; - } - if self.write || self.append { - permissions.check_write(path, api_name)?; - } - Ok(()) - } } pub struct FsStat { @@ -141,28 +102,6 @@ impl From for FsError { } } -impl From for FsError { - fn from(err: JoinError) -> Self { - if err.is_cancelled() { - todo!("async tasks must not be cancelled") - } - if err.is_panic() { - std::panic::resume_unwind(err.into_panic()); // resume the panic on the main thread - } - unreachable!() - } -} - -impl From for AnyError { - fn from(err: FsError) -> Self { - match err { - FsError::Io(err) => AnyError::from(err), - FsError::FileBusy => resource_unavailable(), - FsError::NotSupported => not_supported(), - } - } -} - pub type FsResult = Result; #[async_trait::async_trait(?Send)] @@ -214,7 +153,7 @@ pub trait File { #[async_trait::async_trait(?Send)] pub trait FileSystem: Clone { - type File: File + Resource; + type File: File; fn cwd(&self) -> FsResult; fn tmp_dir(&self) -> FsResult; -- cgit v1.2.3