From 44f4dcc6f7dd3c68f7cb593b46ae73d1b442d8ad Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Wed, 18 Jan 2023 22:01:00 +0000 Subject: [PATCH] Added canary asset --- .gitattributes | 1 + assets/common/canary.canary | 3 +++ common/assets/src/fs.rs | 14 +++++++++++++- common/assets/src/lib.rs | 6 ++++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 assets/common/canary.canary diff --git a/.gitattributes b/.gitattributes index 6aefa43907..9a6ab1cf2f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,6 +9,7 @@ *.tar filter=lfs diff=lfs merge=lfs -text *.obj filter=lfs diff=lfs merge=lfs -text *.blend filter=lfs diff=lfs merge=lfs -text +*.canary filter=lfs diff=lfs merge=lfs -text assets/world/map/*.bin filter=lfs diff=lfs merge=lfs -text *.ron gitlab-language=rust diff --git a/assets/common/canary.canary b/assets/common/canary.canary new file mode 100644 index 0000000000..2db11972f0 --- /dev/null +++ b/assets/common/canary.canary @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:97113cf6c0e999a0eece8c1d10847306bba1cbfbb8618aa92d4fd3f9b5b2813d +size 480 diff --git a/common/assets/src/fs.rs b/common/assets/src/fs.rs index 7a3662d76f..b5cef02cbd 100644 --- a/common/assets/src/fs.rs +++ b/common/assets/src/fs.rs @@ -1,4 +1,4 @@ -use std::{borrow::Cow, io}; +use std::{borrow::Cow, fs, io}; use assets_manager::{ hot_reloading::{DynUpdateSender, EventSender, FsWatcherBuilder}, @@ -23,6 +23,18 @@ impl FileSystem { .ok() }); + let canary = fs::read_to_string(super::ASSETS_PATH.join("common").join("canary.canary")) + .map_err(|e| { + io::Error::new( + io::ErrorKind::Other, + format!("failed to load canary asset: {}", e), + ) + })?; + + if !canary.starts_with("VELOREN_CANARY_MAGIC") { + panic!("Canary asset `canary.canary` was present but did not contain the expected data. This *heavily* implies that you've not correctly set up Git LFS (Large File Storage). Visit `https://book.veloren.net/contributors/development-tools.html#git-lfs` for more information about setting up Git LFS."); + } + Ok(Self { default, override_dir, diff --git a/common/assets/src/lib.rs b/common/assets/src/lib.rs index e25fa101da..ee86ec8c2b 100644 --- a/common/assets/src/lib.rs +++ b/common/assets/src/lib.rs @@ -305,6 +305,12 @@ mod tests { use std::{ffi::OsStr, fs::File}; use walkdir::WalkDir; + #[test] + fn load_canary() { + // Loading the asset cache will automatically cause the canary to load + let _ = *super::ASSETS; + } + /// Fail unless all `.ron` asset files successfully parse to `ron::Value`. #[test] fn parse_all_ron_files_to_value() {