diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-09-24 18:15:38 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2025-09-24 18:15:38 +0800 |
| commit | 6f1660f70809145dd01d2b43a5567b6f219b4da0 (patch) | |
| tree | bf64e2cb63a7beb801eb158656832cf95cf19afd /crates/env/src/workspace/vault.rs | |
| parent | e11507a430aa70d82dc43594cab1e8ed75dcdf4a (diff) | |
Add empty dir check before create vault
Diffstat (limited to 'crates/env/src/workspace/vault.rs')
| -rw-r--r-- | crates/env/src/workspace/vault.rs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/crates/env/src/workspace/vault.rs b/crates/env/src/workspace/vault.rs index b7c5011..caac662 100644 --- a/crates/env/src/workspace/vault.rs +++ b/crates/env/src/workspace/vault.rs @@ -17,7 +17,7 @@ use crate::{ pub mod config; pub mod member; -pub mod vitrual_file; +pub mod virtual_file; pub type MemberId = String; @@ -52,6 +52,14 @@ impl Vault { pub async fn setup_vault(vault_path: impl Into<PathBuf>) -> Result<(), std::io::Error> { let vault_path: PathBuf = vault_path.into(); + // Ensure directory is empty + if vault_path.exists() && vault_path.read_dir()?.next().is_some() { + return Err(std::io::Error::new( + std::io::ErrorKind::DirectoryNotEmpty, + "DirectoryNotEmpty", + )); + } + // 1. Setup main config let config = VaultConfig::default(); VaultConfig::write_to(&config, vault_path.join(SERVER_FILE_VAULT)).await?; @@ -81,23 +89,23 @@ Each public key file should be named `{{member_id}}.pem` (e.g., `juliet.pem`), a **ECDSA:** ```bash -openssl genpkey -algorithm ed25519 -out private.pem -openssl pkey -in private.pem -pubout -out public.pem +openssl genpkey -algorithm ed25519 -out your_name_private.pem +openssl pkey -in your_name_private.pem -pubout -out your_name.pem ``` **RSA:** ```bash -openssl genpkey -algorithm RSA -out private.pem -pkeyopt rsa_keygen_bits:2048 -openssl pkey -in private.pem -pubout -out public.pem +openssl genpkey -algorithm RSA -out your_name_private.pem -pkeyopt rsa_keygen_bits:2048 +openssl pkey -in your_name_private.pem -pubout -out your_name.pem ``` **DSA:** ```bash -openssl genpkey -algorithm DSA -out private.pem -pkeyopt dsa_paramgen_bits:2048 -openssl pkey -in private.pem -pubout -out public.pem +openssl genpkey -algorithm DSA -out your_name_private.pem -pkeyopt dsa_paramgen_bits:2048 +openssl pkey -in your_name_private.pem -pubout -out your_name.pem ``` -Place only the `public.pem` file in the server's `./key/` directory, renamed to match the user's member ID. +Place only the `your_name.pem` file in the server's `./key/` directory, renamed to match the user's member ID. ## File Storage All version-controlled files (Virtual File) are stored in the `{}` directory. |
