Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions client/src/file/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,28 +161,37 @@ impl Keyring {
.as_secs();
self.usage_count += 1;

let blob = self.as_bytes()?;
let result = async {
let blob = self.as_bytes()?;

tmpfile.write_all(&blob).await?;
tmpfile.sync_all().await?;
tmpfile.write_all(&blob).await?;
tmpfile.sync_all().await?;

let target_file = fs::File::open(path.as_ref()).await;
let target_file = fs::File::open(path.as_ref()).await;

let target_mtime = match target_file {
Err(err) if err.kind() == io::ErrorKind::NotFound => None,
Err(err) => return Err(err.into()),
Ok(file) => file.metadata().await?.modified().ok(),
};
let target_mtime = match target_file {
Err(err) if err.kind() == io::ErrorKind::NotFound => None,
Err(err) => return Err(err.into()),
Ok(file) => file.metadata().await?.modified().ok(),
};

if mtime != target_mtime {
return Err(Error::TargetFileChanged(
path.as_ref().display().to_string(),
));
if mtime != target_mtime {
return Err(Error::TargetFileChanged(
path.as_ref().display().to_string(),
));
}

fs::rename(&tmp_path, path.as_ref()).await?;

Ok(())
}
.await;

fs::rename(tmp_path, path.as_ref()).await?;
if result.is_err() {
let _ = fs::remove_file(&tmp_path).await;
}

Ok(())
result
}

pub fn search_items(
Expand Down
9 changes: 9 additions & 0 deletions server/src/pam_listener/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ async fn pam_migrates_v0_keyrings() -> Result<(), Box<dyn std::error::Error>> {
drop(pending);

let collections = setup.server.collections.lock().await;
let non_session: Vec<_> = collections
.values()
.filter(|c| c.name() != "session")
.collect();
assert_eq!(
non_session.len(),
1,
"Should have exactly one non-session collection (placeholder replaced in place, not duplicated)"
);
let mut legacy_collection = None;
for collection in collections.values() {
if collection.label().await == "Legacy" {
Expand Down
2 changes: 1 addition & 1 deletion server/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ impl Service {
name
);

let locked = LockedKeyring::open(name).await?;
let locked = LockedKeyring::open_at(&self.data_dir, name).await?;
self.pending_migrations
.lock()
.await
Expand Down
Loading