mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-19 15:46:17 +00:00
fix(windows): persist adaptive mirror history
This commit is contained in:
@@ -460,6 +460,7 @@ try {
|
|||||||
smokeFailure = new Error(`${error.message}${detail ? `\n${detail}` : ''}`);
|
smokeFailure = new Error(`${error.message}${detail ? `\n${detail}` : ''}`);
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
|
if (process.platform === 'win32') fs.rmSync(serverStatPath, { force: true });
|
||||||
await stop(child, rpcPort, secret);
|
await stop(child, rpcPort, secret);
|
||||||
if (smokePassed) {
|
if (smokePassed) {
|
||||||
const stat = fs.readFileSync(serverStatPath, 'utf8');
|
const stat = fs.readFileSync(serverStatPath, 'utf8');
|
||||||
|
|||||||
@@ -3115,6 +3115,10 @@ async fn shutdown_aria2_daemon(app_handle: tauri::AppHandle) {
|
|||||||
if let Some(state) = app_handle.try_state::<AppState>() {
|
if let Some(state) = app_handle.try_state::<AppState>() {
|
||||||
let port = state.aria2_port.load(Ordering::Relaxed);
|
let port = state.aria2_port.load(Ordering::Relaxed);
|
||||||
if port != 0 {
|
if port != 0 {
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
if let Err(error) = state.storage_layout.prepare_aria2_server_stat_for_replace() {
|
||||||
|
log::warn!("adaptive mirror history cannot be replaced on shutdown: {error}");
|
||||||
|
}
|
||||||
let shutdown = tokio::time::timeout(
|
let shutdown = tokio::time::timeout(
|
||||||
std::time::Duration::from_secs(2),
|
std::time::Duration::from_secs(2),
|
||||||
rpc_call(port, &state.aria2_secret, "aria2.shutdown", serde_json::json!([])),
|
rpc_call(port, &state.aria2_secret, "aria2.shutdown", serde_json::json!([])),
|
||||||
|
|||||||
@@ -228,6 +228,26 @@ impl StorageLayout {
|
|||||||
}
|
}
|
||||||
Ok(path)
|
Ok(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The MSVC build of Aria2 uses C `rename`, which cannot replace an
|
||||||
|
/// existing destination on Windows. Remove only the already-validated,
|
||||||
|
/// app-owned regular cache immediately before graceful shutdown so
|
||||||
|
/// Aria2's `__temp` file can be renamed into place.
|
||||||
|
pub fn prepare_aria2_server_stat_for_replace(&self) -> Result<(), String> {
|
||||||
|
let path = self.aria2_server_stat_path();
|
||||||
|
match std::fs::symlink_metadata(&path) {
|
||||||
|
Ok(metadata) if metadata.file_type().is_symlink() || !metadata.is_file() => {
|
||||||
|
Err("Aria2 server-stat cache replacement target is not a regular file".to_string())
|
||||||
|
}
|
||||||
|
Ok(_) => std::fs::remove_file(&path).map_err(|error| {
|
||||||
|
format!("failed to prepare Aria2 server-stat replacement: {error}")
|
||||||
|
}),
|
||||||
|
Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(()),
|
||||||
|
Err(error) => Err(format!(
|
||||||
|
"failed to inspect Aria2 server-stat replacement target: {error}"
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn aria2_server_stat_is_valid(contents: &str) -> bool {
|
fn aria2_server_stat_is_valid(contents: &str) -> bool {
|
||||||
@@ -395,6 +415,23 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn aria2_server_stat_replacement_removes_only_the_managed_regular_cache() {
|
||||||
|
let root = TempDir::new().unwrap();
|
||||||
|
let layout = test_layout(root.path());
|
||||||
|
layout.prepare_aria2_dht_paths().unwrap();
|
||||||
|
let path = layout.prepare_aria2_server_stat_path().unwrap();
|
||||||
|
fs::write(
|
||||||
|
&path,
|
||||||
|
"host=mirror.example, protocol=https, dl_speed=1, last_updated=1, status=OK\n",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
layout.prepare_aria2_server_stat_for_replace().unwrap();
|
||||||
|
assert!(!path.exists());
|
||||||
|
layout.prepare_aria2_server_stat_for_replace().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn aria2_server_stat_cache_rejects_symlink_output() {
|
fn aria2_server_stat_cache_rejects_symlink_output() {
|
||||||
@@ -411,6 +448,7 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert!(layout.prepare_aria2_server_stat_path().is_err());
|
assert!(layout.prepare_aria2_server_stat_path().is_err());
|
||||||
|
assert!(layout.prepare_aria2_server_stat_for_replace().is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
|||||||
Reference in New Issue
Block a user