mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-05-12 04:41:32 +02:00
refactor: prevent raise condition in ci
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user