Attach context to instances produced by middleware (#273)

This commit is contained in:
Lucien Greathouse
2019-12-04 11:38:28 -08:00
committed by GitHub
parent f0a602b48b
commit 4b89bb087a
7 changed files with 29 additions and 16 deletions

View File

@@ -64,7 +64,8 @@ impl SnapshotMiddleware for SnapshotDir {
.metadata(
InstanceMetadata::new()
.instigating_source(entry.path())
.relevant_paths(relevant_paths),
.relevant_paths(relevant_paths)
.context(context),
);
if let Some(meta_entry) = vfs.get(meta_path).with_not_found()? {

View File

@@ -18,7 +18,7 @@ pub struct SnapshotJsonModel;
impl SnapshotMiddleware for SnapshotJsonModel {
fn from_vfs<F: VfsFetcher>(
_context: &InstanceContext,
context: &InstanceContext,
vfs: &Vfs<F>,
entry: &VfsEntry,
) -> SnapshotInstanceResult {
@@ -54,8 +54,11 @@ impl SnapshotMiddleware for SnapshotJsonModel {
let mut snapshot = instance.core.into_snapshot(instance_name.to_owned());
snapshot.metadata.instigating_source = Some(entry.path().to_path_buf().into());
snapshot.metadata.relevant_paths = vec![entry.path().to_path_buf()];
snapshot.metadata = snapshot
.metadata
.instigating_source(entry.path())
.relevant_paths(vec![entry.path().to_path_buf()])
.context(context);
Ok(Some(snapshot))
}

View File

@@ -33,7 +33,7 @@ impl SnapshotMiddleware for SnapshotLua {
}
if entry.is_file() {
snapshot_lua_file(vfs, entry)
snapshot_lua_file(context, vfs, entry)
} else {
// At this point, our entry is definitely a directory!
@@ -54,7 +54,11 @@ impl SnapshotMiddleware for SnapshotLua {
}
/// Core routine for turning Lua files into snapshots.
fn snapshot_lua_file<F: VfsFetcher>(vfs: &Vfs<F>, entry: &VfsEntry) -> SnapshotInstanceResult {
fn snapshot_lua_file<F: VfsFetcher>(
context: &InstanceContext,
vfs: &Vfs<F>,
entry: &VfsEntry,
) -> SnapshotInstanceResult {
let file_name = entry.path().file_name().unwrap().to_string_lossy();
let (class_name, instance_name) = if let Some(name) = match_trailing(&file_name, ".server.lua")
@@ -89,7 +93,8 @@ fn snapshot_lua_file<F: VfsFetcher>(vfs: &Vfs<F>, entry: &VfsEntry) -> SnapshotI
.metadata(
InstanceMetadata::new()
.instigating_source(entry.path())
.relevant_paths(vec![entry.path().to_path_buf(), meta_path.clone()]),
.relevant_paths(vec![entry.path().to_path_buf(), meta_path.clone()])
.context(context),
);
if let Some(meta_entry) = vfs.get(meta_path).with_not_found()? {
@@ -116,7 +121,7 @@ fn snapshot_init<F: VfsFetcher>(
if let Some(init_entry) = vfs.get(init_path).with_not_found()? {
if let Some(dir_snapshot) = SnapshotDir::from_vfs(context, vfs, folder_entry)? {
if let Some(mut init_snapshot) = snapshot_lua_file(vfs, &init_entry)? {
if let Some(mut init_snapshot) = snapshot_lua_file(context, vfs, &init_entry)? {
if dir_snapshot.class_name != "Folder" {
panic!(
"init.lua, init.server.lua, and init.client.lua can \

View File

@@ -12,7 +12,7 @@ pub struct SnapshotRbxlx;
impl SnapshotMiddleware for SnapshotRbxlx {
fn from_vfs<F: VfsFetcher>(
_context: &InstanceContext,
context: &InstanceContext,
vfs: &Vfs<F>,
entry: &VfsEntry,
) -> SnapshotInstanceResult {
@@ -38,7 +38,8 @@ impl SnapshotMiddleware for SnapshotRbxlx {
.metadata(
InstanceMetadata::new()
.instigating_source(entry.path())
.relevant_paths(vec![entry.path().to_path_buf()]),
.relevant_paths(vec![entry.path().to_path_buf()])
.context(context),
);
Ok(Some(snapshot))

View File

@@ -16,7 +16,7 @@ pub struct SnapshotRbxm;
impl SnapshotMiddleware for SnapshotRbxm {
fn from_vfs<F: VfsFetcher>(
_context: &InstanceContext,
context: &InstanceContext,
vfs: &Vfs<F>,
entry: &VfsEntry,
) -> SnapshotInstanceResult {
@@ -48,7 +48,8 @@ impl SnapshotMiddleware for SnapshotRbxm {
.metadata(
InstanceMetadata::new()
.instigating_source(entry.path())
.relevant_paths(vec![entry.path().to_path_buf()]),
.relevant_paths(vec![entry.path().to_path_buf()])
.context(context),
);
Ok(Some(snapshot))

View File

@@ -12,7 +12,7 @@ pub struct SnapshotRbxmx;
impl SnapshotMiddleware for SnapshotRbxmx {
fn from_vfs<F: VfsFetcher>(
_context: &InstanceContext,
context: &InstanceContext,
vfs: &Vfs<F>,
entry: &VfsEntry,
) -> SnapshotInstanceResult {
@@ -40,7 +40,8 @@ impl SnapshotMiddleware for SnapshotRbxmx {
.metadata(
InstanceMetadata::new()
.instigating_source(entry.path())
.relevant_paths(vec![entry.path().to_path_buf()]),
.relevant_paths(vec![entry.path().to_path_buf()])
.context(context),
);
Ok(Some(snapshot))

View File

@@ -19,7 +19,7 @@ pub struct SnapshotTxt;
impl SnapshotMiddleware for SnapshotTxt {
fn from_vfs<F: VfsFetcher>(
_context: &InstanceContext,
context: &InstanceContext,
vfs: &Vfs<F>,
entry: &VfsEntry,
) -> SnapshotInstanceResult {
@@ -54,7 +54,8 @@ impl SnapshotMiddleware for SnapshotTxt {
.metadata(
InstanceMetadata::new()
.instigating_source(entry.path())
.relevant_paths(vec![entry.path().to_path_buf(), meta_path.clone()]),
.relevant_paths(vec![entry.path().to_path_buf(), meta_path.clone()])
.context(context),
);
if let Some(meta_entry) = vfs.get(meta_path).with_not_found()? {