VFS Improvements (#259)

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
This commit is contained in:
Lucien Greathouse
2019-10-16 15:45:23 -07:00
committed by GitHub
parent 5123d21290
commit 82678235ab
21 changed files with 292 additions and 258 deletions

View File

@@ -21,7 +21,7 @@ pub struct SnapshotLua;
impl SnapshotMiddleware for SnapshotLua {
fn from_vfs<F: VfsFetcher>(
context: &mut InstanceSnapshotContext,
vfs: &mut Vfs<F>,
vfs: &Vfs<F>,
entry: &VfsEntry,
) -> SnapshotInstanceResult<'static> {
let file_name = entry.path().file_name().unwrap().to_string_lossy();
@@ -54,7 +54,7 @@ impl SnapshotMiddleware for SnapshotLua {
/// Core routine for turning Lua files into snapshots.
fn snapshot_lua_file<F: VfsFetcher>(
vfs: &mut Vfs<F>,
vfs: &Vfs<F>,
entry: &VfsEntry,
) -> SnapshotInstanceResult<'static> {
let file_name = entry.path().file_name().unwrap().to_string_lossy();
@@ -117,7 +117,7 @@ fn snapshot_lua_file<F: VfsFetcher>(
/// their parents, which acts similarly to `__init__.py` from the Python world.
fn snapshot_init<F: VfsFetcher>(
context: &mut InstanceSnapshotContext,
vfs: &mut Vfs<F>,
vfs: &Vfs<F>,
folder_entry: &VfsEntry,
init_name: &str,
) -> SnapshotInstanceResult<'static> {