From 44f4dcc6f7dd3c68f7cb593b46ae73d1b442d8ad Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Wed, 18 Jan 2023 22:01:00 +0000 Subject: [PATCH 1/2] 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() { From 63d0c937f05361b81d3b6d5934c1f50eedf86bbe Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Wed, 18 Jan 2023 22:31:33 +0000 Subject: [PATCH 2/2] Removed existing LFS check --- common/build.rs | 40 +--------------------------------------- flake.nix | 3 --- 2 files changed, 1 insertion(+), 42 deletions(-) diff --git a/common/build.rs b/common/build.rs index 71e4750974..1916c4b808 100644 --- a/common/build.rs +++ b/common/build.rs @@ -1,10 +1,4 @@ -use std::{ - env, - fs::File, - io::{Read, Write}, - path::{Path, PathBuf}, - process::Command, -}; +use std::{env, fs::File, io::Write, path::Path, process::Command}; fn main() { // If these env variables exist then we are building on nix, use them as hash @@ -52,38 +46,6 @@ fn main() { Err(e) => panic!("failed to retrieve current git commit hash: {}", e), } } - - // Check if git-lfs is working - if env::var("DISABLE_GIT_LFS_CHECK").is_err() && cfg!(not(feature = "no-assets")) { - let asset_path: PathBuf = ["..", "assets", "voxygen", "background", "bg_main.jpg"] - .iter() - .collect(); - let asset_file = match File::open(&asset_path) { - Ok(file) => file, - Err(e) => panic!( - "failed to open asset file {}: {}", - asset_path.to_str().unwrap(), - e - ), - }; - const LFS_MARKER: &[u8] = b"version https://git-lfs.github.com/spec/"; - let mut buffer = Vec::new(); - let bytes_read = asset_file - .take(LFS_MARKER.len() as u64) - .read_to_end(&mut buffer) - .expect("failed to read asset file"); - - if bytes_read == LFS_MARKER.len() && buffer == LFS_MARKER { - panic!( - "\n\nGit Large File Storage (git-lfs) has not been set up correctly.\n\ - Most common reasons:\n\ - \t- git-lfs was not installed before cloning this repository\n\ - \t- this repository was not cloned from the primary gitlab mirror.\n\ - \t The github mirror does not support lfs.\n\ - See the book at https://book.veloren.net/ for details.\n\n" - ); - } - } } fn create_hash_file(hash: &str) { diff --git a/flake.nix b/flake.nix index 691249a142..9a69eac388 100644 --- a/flake.nix +++ b/flake.nix @@ -86,9 +86,6 @@ pkgConfig = common: let inherit (common) pkgs; veloren-common-ov = { - # Disable `git-lfs` check here since we check it ourselves - # We have to include the command output here, otherwise Nix won't run it - DISABLE_GIT_LFS_CHECK = true; # We don't add in any information here because otherwise anything # that depends on common will be recompiled. We will set these in # our wrapper instead.