File tree Expand file tree Collapse file tree
confidential-data-hub/hub/src/storage Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212
1313use std:: path:: Path ;
1414
15- use anyhow:: { bail , Context } ;
15+ use anyhow:: Context ;
1616use libcryptsetup_rs:: consts:: flags:: { CryptActivate , CryptDeactivate , CryptVolumeKey } ;
1717use libcryptsetup_rs:: consts:: vals:: EncryptionFormat ;
1818use 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
Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments