From e2460db596ba031f9705511ca2c5b35c4c43fad4 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 26 Jan 2024 23:14:56 +0800 Subject: [PATCH 1/2] fix comparison on previous PR helps to test things...couldn't do that earlier due to system issues. this actually works now. --- services/gam/src/tokens.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/gam/src/tokens.rs b/services/gam/src/tokens.rs index 58de5a560..9ed40ffbb 100644 --- a/services/gam/src/tokens.rs +++ b/services/gam/src/tokens.rs @@ -54,7 +54,7 @@ impl<'a> TokenManager { // throw a bone to the dev who has to debug this error. This typically only triggers after a major // refactor and some UX element was removed and we forgot to update it in this table here. let now = self.tt.elapsed_ms(); - if *self.last_time.borrow() < now - REPEAT_MSG_INTERVAL_MS { + if *self.last_time.borrow() + REPEAT_MSG_INTERVAL_MS < now { log::info!("Occupied token slots: ***"); for t in self.tokens.iter() { log::info!(" {}", t.name); From 1835f4c1398ee0db05301d82079fa03118c88bf4 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 27 Jan 2024 01:13:26 +0800 Subject: [PATCH 2/2] check that app paths exist in hosted mode --- xtask/src/builder.rs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/xtask/src/builder.rs b/xtask/src/builder.rs index ca6c586e1..321a323f3 100644 --- a/xtask/src/builder.rs +++ b/xtask/src/builder.rs @@ -306,6 +306,24 @@ impl Builder { self } + /// Check if a file exists and is executable + pub fn executable_exists(&self, file: &str) -> bool { + if let Ok(_metadata) = std::fs::metadata(file) { + #[cfg(target_os = "windows")] + if file.to_lowercase().ends_with("exe") { + return true; + } + #[cfg(not(target_os = "windows"))] + if _metadata.is_file() { + use std::os::unix::fs::PermissionsExt; + if _metadata.permissions().mode() & 0o100 != 0 { + return true; + } + } + } + false + } + /// Add just one service pub fn add_service<'a>(&'a mut self, service_spec: &str, xip: bool) -> &'a mut Builder { let mut spec: CrateSpec = service_spec.into(); @@ -667,7 +685,25 @@ impl Builder { } // jam in any pre-built local binary files that were specified let binary_files_string = self.enumerate_binary_files()?; - let mut binary_files: Vec<&str> = binary_files_string.iter().map(|s| s.as_ref()).collect(); + let mut canonicalized_paths = Vec::new(); + let mut binary_files_storage = Vec::::new(); + for f in binary_files_string { + if !self.executable_exists(&f) { + panic!("FATAL ERROR: App '{}' does not exist or is not executable.", f); + } + canonicalized_paths + .push(std::fs::canonicalize(f).expect("Couldn't canonicalize executable target")); + } + for f in canonicalized_paths { + let path_as_str = f.to_str().expect("Couldn't canonicalize executable target").to_string(); + let windows_clean_path = if path_as_str.starts_with("\\\\?\\") { + path_as_str[4..].to_owned() + } else { + path_as_str + }; + binary_files_storage.push(windows_clean_path); + } + let mut binary_files: Vec<&str> = binary_files_storage.iter().map(|s| s.as_ref()).collect(); hosted_args.append(&mut binary_files); if !self.dry_run {