refactor(ext/node): enforce interior mutable for NodePermissions to remove clones (#18831)

We can make `NodePermissions` rely on interior mutability (which the
`PermissionsContainer` is already doing) in order to not have to clone
everything all the time. This also reduces the chance of an accidental
`borrow` while `borrrow_mut`.
This commit is contained in:
David Sherret 2023-04-24 21:07:48 -04:00 committed by GitHub
parent 667acb075c
commit 5b4a9b48ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 59 additions and 65 deletions

View file

@ -44,13 +44,13 @@ pub trait NodeEnv {
}
pub trait NodePermissions {
fn check_read(&mut self, path: &Path) -> Result<(), AnyError>;
fn check_read(&self, path: &Path) -> Result<(), AnyError>;
}
pub(crate) struct AllowAllNodePermissions;
impl NodePermissions for AllowAllNodePermissions {
fn check_read(&mut self, _path: &Path) -> Result<(), AnyError> {
fn check_read(&self, _path: &Path) -> Result<(), AnyError> {
Ok(())
}
}
@ -164,7 +164,7 @@ pub trait NpmResolver: std::fmt::Debug + Send + Sync {
fn ensure_read_permission(
&self,
permissions: &mut dyn NodePermissions,
permissions: &dyn NodePermissions,
path: &Path,
) -> Result<(), AnyError>;
}