mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-21 13:15:50 +00:00
This PR refactors all of the methods on `Vfs` from accepting `&mut self` to accepting `&self` and keeping data wrapped in a mutex. This builds on previous changes to make reference count file contents and cleans up the last places where we're returning borrowed data out of the VFS interface. Once this change lands, there are two possible directions we can go that I see: * Conservative: Refactor all remaining `&mut Vfs` handles to `&Vfs` * Interesting: Embrace ref counting by changing `Vfs` methods to accept `self: Arc<Self>`, which makes the `VfsEntry` API no longer need an explicit `Vfs` argument for its operations. * Change VfsFetcher to be immutable with internal locking * Refactor Vfs::would_be_resident * Refactor Vfs::read_if_not_exists * Refactor Vfs::raise_file_removed * Refactor Vfs::raise_file_changed * Add Vfs::get_internal as bits of Vfs::get * Switch Vfs to use internal locking * Migrate all Vfs methods from &mut self to &self * Make VfsEntry access Vfs immutably * Remove outer VFS locking (#260) * Refactor all snapshot middleware to accept &Vfs instead of &mut Vfs * Remove outer VFS Mutex across the board
38 lines
1.0 KiB
Rust
38 lines
1.0 KiB
Rust
use std::{
|
|
io,
|
|
path::{Path, PathBuf},
|
|
};
|
|
|
|
use crossbeam_channel::Receiver;
|
|
|
|
use super::event::VfsEvent;
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum FileType {
|
|
File,
|
|
Directory,
|
|
}
|
|
|
|
/// The generic interface that `Vfs` uses to lazily read files from the disk.
|
|
/// In tests, it's stubbed out to do different versions of absolutely nothing
|
|
/// depending on the test.
|
|
pub trait VfsFetcher {
|
|
fn file_type(&self, path: &Path) -> io::Result<FileType>;
|
|
fn read_children(&self, path: &Path) -> io::Result<Vec<PathBuf>>;
|
|
fn read_contents(&self, path: &Path) -> io::Result<Vec<u8>>;
|
|
|
|
fn create_directory(&self, path: &Path) -> io::Result<()>;
|
|
fn write_file(&self, path: &Path, contents: &[u8]) -> io::Result<()>;
|
|
fn remove(&self, path: &Path) -> io::Result<()>;
|
|
|
|
fn receiver(&self) -> Receiver<VfsEvent>;
|
|
|
|
fn watch(&self, _path: &Path) {}
|
|
fn unwatch(&self, _path: &Path) {}
|
|
|
|
/// A method intended for debugging what paths the fetcher is watching.
|
|
fn watched_paths(&self) -> Vec<PathBuf> {
|
|
Vec::new()
|
|
}
|
|
}
|