Skip to content

Commit 9bfd98f

Browse files
committed
feat: Fixed a crucial bug in lock files in diffrent oses
1 parent 2fbe138 commit 9bfd98f

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ keyring = "4.1.6"
2828
ed25519-dalek = { version = "3.0.0", features = ["rand_core"] }
2929
zstd = "0.13.3"
3030
rmp-serde = "1.3.1"
31+
fs2 = "0.4.3"

src/utils/vault.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use super::token::{TokenKeyMaterial, TokenPayload};
33
use anyhow::{anyhow, Result};
44
use directories::ProjectDirs;
55
use ed25519_dalek::{Signature, Signer, SigningKey, Verifier, VerifyingKey};
6+
use fs2::FileExt;
67
use serde::{Deserialize, Serialize};
78
use std::collections::{BTreeMap, HashSet};
89
use std::env;
@@ -248,6 +249,10 @@ impl Vault {
248249
return Err(anyhow!("Seal already exists at {:?}!", path));
249250
}
250251

252+
if let Some(parent) = path.parent() {
253+
fs::create_dir_all(parent)?;
254+
}
255+
251256
let salt = crypto::generate_salt();
252257

253258
// Derive KEK and Signing Key
@@ -315,7 +320,7 @@ impl Vault {
315320
.write(true)
316321
.create(true)
317322
.open(&lock_path)?;
318-
lock_file.lock()?;
323+
lock_file.lock_exclusive()?;
319324

320325
let parent_dir = path.parent().unwrap_or_else(|| Path::new("."));
321326
let mut temp_file = NamedTempFile::new_in(parent_dir)?;

0 commit comments

Comments
 (0)