fix(updates): guard portable builds from installer updates (#550)

This commit is contained in:
skyler
2026-05-30 19:15:37 +08:00
committed by GitHub
parent 398e040d5c
commit 528b51fb8d
10 changed files with 92 additions and 4 deletions
+31 -2
View File
@@ -10,7 +10,7 @@ pub fn resolve_data_dir(default_app_data_dir: PathBuf) -> PathBuf {
#[cfg(target_os = "windows")]
if let Some(exe_dir) = current_exe_dir() {
if exe_dir.join(PORTABLE_MARKER).is_file() {
if portable_marker_exists(&exe_dir) {
return exe_dir.join("data");
}
}
@@ -18,11 +18,26 @@ pub fn resolve_data_dir(default_app_data_dir: PathBuf) -> PathBuf {
default_app_data_dir
}
#[cfg(target_os = "windows")]
pub fn is_portable_mode() -> bool {
current_exe_dir().is_some_and(|dir| portable_marker_exists(&dir))
}
#[cfg(not(target_os = "windows"))]
pub fn is_portable_mode() -> bool {
false
}
#[cfg(target_os = "windows")]
fn current_exe_dir() -> Option<PathBuf> {
std::env::current_exe().ok().and_then(|path| path.parent().map(std::path::Path::to_path_buf))
}
#[cfg(target_os = "windows")]
fn portable_marker_exists(exe_dir: &std::path::Path) -> bool {
exe_dir.join(PORTABLE_MARKER).is_file()
}
#[cfg(test)]
fn resolve_data_dir_from_inputs(
default_app_data_dir: PathBuf,
@@ -40,11 +55,16 @@ fn resolve_data_dir_from_inputs(
}
}
#[cfg(test)]
fn is_portable_mode_from_inputs(exe_dir: Option<PathBuf>, portable_marker_exists: bool) -> bool {
exe_dir.is_some() && portable_marker_exists
}
#[cfg(test)]
mod tests {
use std::path::PathBuf;
use super::resolve_data_dir_from_inputs;
use super::{is_portable_mode_from_inputs, resolve_data_dir_from_inputs};
#[test]
fn uses_portable_data_dir_when_marker_exists() {
@@ -55,4 +75,13 @@ mod tests {
assert_eq!(data_dir, exe_dir.join("data"));
}
#[test]
fn detects_portable_mode_only_when_marker_exists_next_to_exe() {
let exe_dir = PathBuf::from(r"D:\Apps\DBX");
assert!(is_portable_mode_from_inputs(Some(exe_dir), true));
assert!(!is_portable_mode_from_inputs(Some(PathBuf::from(r"D:\Apps\DBX")), false));
assert!(!is_portable_mode_from_inputs(None, true));
}
}