mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-23 14:15:24 +00:00
@@ -46,8 +46,8 @@ impl SnapshotMiddleware for SnapshotCsv {
|
|||||||
.relevant_paths(vec![path.to_path_buf(), meta_path.clone()]),
|
.relevant_paths(vec![path.to_path_buf(), meta_path.clone()]),
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(meta_contents) = vfs.read(meta_path).with_not_found()? {
|
if let Some(meta_contents) = vfs.read(&meta_path).with_not_found()? {
|
||||||
let mut metadata = AdjacentMetadata::from_slice(&meta_contents);
|
let mut metadata = AdjacentMetadata::from_slice(&meta_contents, &meta_path)?;
|
||||||
metadata.apply_all(&mut snapshot);
|
metadata.apply_all(&mut snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,8 +73,8 @@ impl SnapshotMiddleware for SnapshotDir {
|
|||||||
.context(context),
|
.context(context),
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(meta_contents) = vfs.read(meta_path).with_not_found()? {
|
if let Some(meta_contents) = vfs.read(&meta_path).with_not_found()? {
|
||||||
let mut metadata = DirectoryMetadata::from_slice(&meta_contents);
|
let mut metadata = DirectoryMetadata::from_slice(&meta_contents, &meta_path)?;
|
||||||
metadata.apply_all(&mut snapshot);
|
metadata.apply_all(&mut snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,13 @@ impl SnapshotError {
|
|||||||
path: Some(path.into()),
|
path: Some(path.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn malformed_meta_json(source: serde_json::Error, path: impl Into<PathBuf>) -> Self {
|
||||||
|
Self {
|
||||||
|
detail: SnapshotErrorDetail::MalformedMetaJson { source },
|
||||||
|
path: Some(path.into()),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error for SnapshotError {
|
impl Error for SnapshotError {
|
||||||
@@ -114,6 +121,9 @@ pub enum SnapshotErrorDetail {
|
|||||||
|
|
||||||
#[snafu(display("malformed .model.json file"))]
|
#[snafu(display("malformed .model.json file"))]
|
||||||
MalformedModelJson { source: serde_json::Error },
|
MalformedModelJson { source: serde_json::Error },
|
||||||
|
|
||||||
|
#[snafu(display("malformed .meta.json file"))]
|
||||||
|
MalformedMetaJson { source: serde_json::Error },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<io::Error> for SnapshotErrorDetail {
|
impl From<io::Error> for SnapshotErrorDetail {
|
||||||
|
|||||||
@@ -87,8 +87,8 @@ fn snapshot_lua_file(context: &InstanceContext, vfs: &Vfs, path: &Path) -> Snaps
|
|||||||
.context(context),
|
.context(context),
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(meta_contents) = vfs.read(meta_path).with_not_found()? {
|
if let Some(meta_contents) = vfs.read(&meta_path).with_not_found()? {
|
||||||
let mut metadata = AdjacentMetadata::from_slice(&meta_contents);
|
let mut metadata = AdjacentMetadata::from_slice(&meta_contents, &meta_path)?;
|
||||||
metadata.apply_all(&mut snapshot);
|
metadata.apply_all(&mut snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::{borrow::Cow, collections::HashMap};
|
use std::{borrow::Cow, collections::HashMap, path::Path};
|
||||||
|
|
||||||
use rbx_dom_weak::UnresolvedRbxValue;
|
use rbx_dom_weak::UnresolvedRbxValue;
|
||||||
use rbx_reflection::try_resolve_value;
|
use rbx_reflection::try_resolve_value;
|
||||||
@@ -6,6 +6,8 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use crate::snapshot::InstanceSnapshot;
|
use crate::snapshot::InstanceSnapshot;
|
||||||
|
|
||||||
|
use super::error::SnapshotError;
|
||||||
|
|
||||||
/// Represents metadata in a sibling file with the same basename.
|
/// Represents metadata in a sibling file with the same basename.
|
||||||
///
|
///
|
||||||
/// As an example, hello.meta.json next to hello.lua would allow assigning
|
/// As an example, hello.meta.json next to hello.lua would allow assigning
|
||||||
@@ -21,10 +23,9 @@ pub struct AdjacentMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AdjacentMetadata {
|
impl AdjacentMetadata {
|
||||||
pub fn from_slice(slice: &[u8]) -> Self {
|
pub fn from_slice(slice: &[u8], path: &Path) -> Result<Self, SnapshotError> {
|
||||||
serde_json::from_slice(slice)
|
serde_json::from_slice(slice)
|
||||||
// TODO: Turn into error type
|
.map_err(|source| SnapshotError::malformed_meta_json(source, path))
|
||||||
.expect(".meta.json file was malformed")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_ignore_unknown_instances(&mut self, snapshot: &mut InstanceSnapshot) {
|
pub fn apply_ignore_unknown_instances(&mut self, snapshot: &mut InstanceSnapshot) {
|
||||||
@@ -74,10 +75,9 @@ pub struct DirectoryMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DirectoryMetadata {
|
impl DirectoryMetadata {
|
||||||
pub fn from_slice(slice: &[u8]) -> Self {
|
pub fn from_slice(slice: &[u8], path: &Path) -> Result<Self, SnapshotError> {
|
||||||
serde_json::from_slice(slice)
|
serde_json::from_slice(slice)
|
||||||
// TODO: Turn into error type
|
.map_err(|source| SnapshotError::malformed_meta_json(source, path))
|
||||||
.expect("init.meta.json file was malformed")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_all(&mut self, snapshot: &mut InstanceSnapshot) {
|
pub fn apply_all(&mut self, snapshot: &mut InstanceSnapshot) {
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ impl SnapshotMiddleware for SnapshotTxt {
|
|||||||
.context(context),
|
.context(context),
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(meta_contents) = vfs.read(meta_path).with_not_found()? {
|
if let Some(meta_contents) = vfs.read(&meta_path).with_not_found()? {
|
||||||
let mut metadata = AdjacentMetadata::from_slice(&meta_contents);
|
let mut metadata = AdjacentMetadata::from_slice(&meta_contents, &meta_path)?;
|
||||||
metadata.apply_all(&mut snapshot);
|
metadata.apply_all(&mut snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user