refactor: prevent raise condition in ci

This commit is contained in:
zhom
2026-02-02 01:40:58 +04:00
parent 288685030a
commit 2f0217e8ed
3 changed files with 36 additions and 4 deletions
+1
View File
@@ -1,4 +1,5 @@
use directories::ProjectDirs;
#[cfg(any(target_os = "macos", target_os = "linux"))]
use std::fs;
use std::io;
use std::path::PathBuf;
+33
View File
@@ -58,6 +58,39 @@ impl VpnStorage {
}
}
/// Create a VPN storage manager with a custom storage directory
pub fn with_dir(dir: &std::path::Path) -> Self {
let storage_path = dir.join("vpn_configs.json");
let key_path = dir.join(".vpn_key");
let encryption_key = if key_path.exists() {
if let Ok(key_data) = fs::read(&key_path) {
if key_data.len() == 32 {
let mut key = [0u8; 32];
key.copy_from_slice(&key_data);
key
} else {
let key: [u8; 32] = rand::rng().random();
let _ = fs::write(&key_path, key);
key
}
} else {
let key: [u8; 32] = rand::rng().random();
let _ = fs::write(&key_path, key);
key
}
} else {
let key: [u8; 32] = rand::rng().random();
let _ = fs::write(&key_path, key);
key
};
Self {
storage_path,
encryption_key,
}
}
/// Get the storage file path
fn get_storage_path() -> PathBuf {
let data_dir = directories::ProjectDirs::from("com", "donut", "donutbrowser")
+2 -4
View File
@@ -286,10 +286,8 @@ fn test_vpn_storage_import() {
// Helper Functions
// ============================================================================
fn create_test_storage(_temp_dir: &tempfile::TempDir) -> VpnStorage {
// VpnStorage::new() uses the default path
// TODO: Pass temp_dir path when VpnStorage supports custom paths
VpnStorage::new()
fn create_test_storage(temp_dir: &tempfile::TempDir) -> VpnStorage {
VpnStorage::with_dir(temp_dir.path())
}
// ============================================================================