mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-25 07:06:12 +00:00
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:
committed by
GitHub
parent
5123d21290
commit
82678235ab
@@ -21,7 +21,7 @@ pub struct SnapshotCsv;
|
||||
impl SnapshotMiddleware for SnapshotCsv {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
_context: &mut InstanceSnapshotContext,
|
||||
vfs: &mut Vfs<F>,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult<'static> {
|
||||
if entry.is_directory() {
|
||||
|
||||
@@ -20,7 +20,7 @@ pub struct SnapshotDir;
|
||||
impl SnapshotMiddleware for SnapshotDir {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
context: &mut InstanceSnapshotContext,
|
||||
vfs: &mut Vfs<F>,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult<'static> {
|
||||
if entry.is_file() {
|
||||
|
||||
@@ -20,7 +20,7 @@ pub struct SnapshotJsonModel;
|
||||
impl SnapshotMiddleware for SnapshotJsonModel {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
_context: &mut InstanceSnapshotContext,
|
||||
vfs: &mut Vfs<F>,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult<'static> {
|
||||
if entry.is_directory() {
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -15,7 +15,7 @@ pub type SnapshotFileResult = Option<(String, VfsSnapshot)>;
|
||||
pub trait SnapshotMiddleware {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
context: &mut InstanceSnapshotContext,
|
||||
vfs: &mut Vfs<F>,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult<'static>;
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ macro_rules! middlewares {
|
||||
/// Generates a snapshot of instances from the given VfsEntry.
|
||||
pub fn snapshot_from_vfs<F: VfsFetcher>(
|
||||
context: &mut InstanceSnapshotContext,
|
||||
vfs: &mut Vfs<F>,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult<'static> {
|
||||
$(
|
||||
|
||||
@@ -23,7 +23,7 @@ pub struct SnapshotProject;
|
||||
impl SnapshotMiddleware for SnapshotProject {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
context: &mut InstanceSnapshotContext,
|
||||
vfs: &mut Vfs<F>,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult<'static> {
|
||||
if entry.is_directory() {
|
||||
@@ -80,7 +80,7 @@ fn snapshot_project_node<F: VfsFetcher>(
|
||||
context: &mut InstanceSnapshotContext,
|
||||
instance_name: &str,
|
||||
node: &ProjectNode,
|
||||
vfs: &mut Vfs<F>,
|
||||
vfs: &Vfs<F>,
|
||||
) -> SnapshotInstanceResult<'static> {
|
||||
let name = Cow::Owned(instance_name.to_owned());
|
||||
let mut class_name = node
|
||||
|
||||
@@ -16,7 +16,7 @@ pub struct SnapshotRbxlx;
|
||||
impl SnapshotMiddleware for SnapshotRbxlx {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
_context: &mut InstanceSnapshotContext,
|
||||
vfs: &mut Vfs<F>,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult<'static> {
|
||||
if entry.is_directory() {
|
||||
|
||||
@@ -18,7 +18,7 @@ pub struct SnapshotRbxm;
|
||||
impl SnapshotMiddleware for SnapshotRbxm {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
_context: &mut InstanceSnapshotContext,
|
||||
vfs: &mut Vfs<F>,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult<'static> {
|
||||
if entry.is_directory() {
|
||||
|
||||
@@ -16,7 +16,7 @@ pub struct SnapshotRbxmx;
|
||||
impl SnapshotMiddleware for SnapshotRbxmx {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
_context: &mut InstanceSnapshotContext,
|
||||
vfs: &mut Vfs<F>,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult<'static> {
|
||||
if entry.is_directory() {
|
||||
|
||||
@@ -21,7 +21,7 @@ pub struct SnapshotTxt;
|
||||
impl SnapshotMiddleware for SnapshotTxt {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
_context: &mut InstanceSnapshotContext,
|
||||
vfs: &mut Vfs<F>,
|
||||
vfs: &Vfs<F>,
|
||||
entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult<'static> {
|
||||
if entry.is_directory() {
|
||||
|
||||
@@ -16,7 +16,7 @@ pub struct SnapshotUserPlugins;
|
||||
impl SnapshotMiddleware for SnapshotUserPlugins {
|
||||
fn from_vfs<F: VfsFetcher>(
|
||||
context: &mut InstanceSnapshotContext,
|
||||
_vfs: &mut Vfs<F>,
|
||||
_vfs: &Vfs<F>,
|
||||
_entry: &VfsEntry,
|
||||
) -> SnapshotInstanceResult<'static> {
|
||||
// User plugins are only enabled if present on the snapshot context.
|
||||
|
||||
Reference in New Issue
Block a user