Skip to content

Commit 8993486

Browse files
committed
to-squash: address comments confidential-containers#1
1 parent 7cbb9ce commit 8993486

2 files changed

Lines changed: 3 additions & 15 deletions

File tree

  • confidential-data-hub/hub/src/storage

confidential-data-hub/hub/src/storage/drivers/luks2.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
use std::path::Path;
1414

15-
use anyhow::{bail, Context};
15+
use anyhow::Context;
1616
use libcryptsetup_rs::consts::flags::{CryptActivate, CryptDeactivate, CryptVolumeKey};
1717
use libcryptsetup_rs::consts::vals::EncryptionFormat;
1818
use libcryptsetup_rs::{CryptInit, CryptParamsLuks2, CryptParamsLuks2Ref};
@@ -135,12 +135,7 @@ fn init_device(
135135
header_path: Option<&Path>,
136136
) -> anyhow::Result<libcryptsetup_rs::CryptDevice> {
137137
let device_paths = match header_path {
138-
Some(header_path) => {
139-
if !header_path.exists() {
140-
bail!("LUKS header file not found: {}", header_path.display());
141-
}
142-
libcryptsetup_rs::Either::Right((header_path, device_path))
143-
}
138+
Some(header_path) => libcryptsetup_rs::Either::Right((header_path, device_path)),
144139
None => libcryptsetup_rs::Either::Left(device_path),
145140
};
146141

confidential-data-hub/hub/src/storage/volume_type/blockdevice/mod.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,19 +143,12 @@ pub(crate) fn prepare_luks_header_file(
143143
device_path: &Path,
144144
) -> Result<std::path::PathBuf> {
145145
let header_path = luks_header_path(device_id, device_path);
146-
if header_path.exists() {
147-
return Err(std::io::Error::new(
148-
std::io::ErrorKind::AlreadyExists,
149-
format!("LUKS header file already exists: {}", header_path.display()),
150-
)
151-
.into());
152-
}
153146
if let Some(parent) = header_path.parent() {
154147
std::fs::create_dir_all(parent)?;
155148
}
156149
// error "LUKS header file not found: <path/to/header>" from libcryptsetup if header file doesn't exist.
157150
let file = std::fs::OpenOptions::new()
158-
.create(true)
151+
.create_new(true)
159152
.write(true)
160153
.open(&header_path)?;
161154
// error "Device ... is too small" / OS error 5" from libcryptsetup if header isn't sized.

0 commit comments

Comments
 (0)