From 74c76bb5cea8ff70153a8f9ebe02df6ffb0205f7 Mon Sep 17 00:00:00 2001 From: qvkap Date: Sat, 5 Sep 2026 08:29:46 +0300 Subject: fix: dependency resolution, update file removal and sync TLS validation --- src/parallel.rs | 60 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 26 deletions(-) (limited to 'src/parallel.rs') diff --git a/src/parallel.rs b/src/parallel.rs index ed4671f..a3a722b 100644 --- a/src/parallel.rs +++ b/src/parallel.rs @@ -1,8 +1,3 @@ -// parallel.rs -#![allow(dead_code)] -#![allow(unused_imports)] -#![allow(unused_variables)] - use std::collections::{HashMap, HashSet}; use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicBool, Ordering}; @@ -11,7 +6,6 @@ use std::time::Duration; use std::io::Write; use colored::Colorize; -use futures::StreamExt; use sha2::{Digest, Sha256}; use tokio::sync::oneshot; use tokio::task; @@ -60,12 +54,12 @@ impl InstalledDB { } struct AtomicInstaller { - shadow: tempfile::TempDir, + _shadow: tempfile::TempDir, } impl AtomicInstaller { fn new(shadow: tempfile::TempDir) -> Self { - Self { shadow } + Self { _shadow: shadow } } fn commit( @@ -90,8 +84,21 @@ impl AtomicInstaller { std::fs::create_dir_all(parent) .map_err(|e| format!("Create parent {}: {}", parent.display(), e))?; - let bak_path = dst.with_extension("ror-old"); if dst.exists() && dst.is_file() { + let mut bak_num = 0u32; + let bak_path = loop { + let mut p = dst.as_os_str().to_os_string(); + if bak_num == 0 { + p.push(".ror-old"); + } else { + p.push(format!(".ror-old.{}", bak_num)); + } + let p = PathBuf::from(p); + if !p.exists() { + break p; + } + bak_num += 1; + }; if let Err(e) = std::fs::rename(&dst, &bak_path) { return Err(format!("Cannot backup {}: {}", dst.display(), e)); } @@ -100,19 +107,14 @@ impl AtomicInstaller { let rename_err = std::fs::rename(&src, &dst).err(); if let Some(e) = rename_err { - use std::io::ErrorKind; if e.raw_os_error() == Some(18) { if let Err(ce) = std::fs::copy(&src, &dst) { - if let Some((last_bak, orig)) = backup_paths.pop() { - let _ = std::fs::rename(&last_bak, &orig); - } + Self::rollback(&backup_paths); return Err(format!("Failed to install (copy) {}: {}", dst.display(), ce)); } let _ = std::fs::remove_file(&src); } else { - if let Some((last_bak, orig)) = backup_paths.pop() { - let _ = std::fs::rename(&last_bak, &orig); - } + Self::rollback(&backup_paths); return Err(format!("Failed to install {}: {}", dst.display(), e)); } } @@ -128,9 +130,21 @@ impl AtomicInstaller { Ok(installed) } + + fn rollback(backup_paths: &[(PathBuf, PathBuf)]) { + for (bak, orig) in backup_paths { + if bak.exists() { + let _ = std::fs::rename(bak, orig); + } + } + } } async fn download_one(url: &str, expected_sha: &str, _cfg: &Config) -> Result { + if url.starts_with("http://") { + return Err(format!("Insecure HTTP URL rejected: {}. Only HTTPS allowed.", url)); + } + let result = timeout(Duration::from_secs(60), async { let client = reqwest::Client::builder() .timeout(Duration::from_secs(30)) @@ -147,24 +161,17 @@ async fn download_one(url: &str, expected_sha: &str, _cfg: &Config) -> Result Result