@@ -2,6 +2,7 @@ use crate::results::UnwrapOrSgxErrorUnexpected;
2
2
3
3
use core:: mem;
4
4
use core:: ptr:: null;
5
+ use log:: { error, info} ;
5
6
use std:: io:: { Read , Write } ;
6
7
use std:: mem:: * ;
7
8
use std:: path:: Path ;
@@ -98,10 +99,10 @@ pub struct file_md {
98
99
}
99
100
100
101
pub fn unseal_file_from_2_17 (
101
- sPath : & str ,
102
+ s_path : & str ,
102
103
should_check_fname : bool ,
103
104
) -> Result < Vec < u8 > , sgx_status_t > {
104
- let mut file = match File :: open ( sPath ) {
105
+ let mut file = match File :: open ( s_path ) {
105
106
Ok ( f) => f,
106
107
Err ( e) => {
107
108
return Err ( /*e*/ sgx_status_t:: SGX_ERROR_UNEXPECTED ) ;
@@ -178,7 +179,7 @@ pub fn unseal_file_from_2_17(
178
179
bytes. copy_from_slice ( slice:: from_raw_parts ( md_decr. data . as_ptr ( ) , ret_size) ) ;
179
180
180
181
if should_check_fname {
181
- let raw_path = sPath . as_bytes ( ) ;
182
+ let raw_path = s_path . as_bytes ( ) ;
182
183
183
184
let mut fname0: usize = 0 ;
184
185
for i in 0 ..raw_path. len ( ) {
@@ -212,20 +213,35 @@ pub fn unseal_file_from_2_17(
212
213
}
213
214
214
215
pub fn migrate_file_from_2_17_safe (
215
- sPath : & str ,
216
+ s_path : & str ,
216
217
should_check_fname : bool ,
217
218
) -> Result < ( ) , sgx_status_t > {
218
- if Path :: new ( sPath) . exists ( ) {
219
- let data = match unseal_file_from_2_17 ( sPath, should_check_fname) {
219
+ if Path :: new ( s_path) . exists ( ) {
220
+
221
+ let data = match unseal_file_from_2_17 ( s_path, should_check_fname) {
220
222
Ok ( x) => x,
221
223
Err ( e) => {
224
+ error ! ( "Couldn't unseal file {}, {}" , s_path, e) ;
222
225
return Err ( e) ;
223
226
}
224
227
} ;
228
+
229
+ let s_path_bkp = s_path. to_string ( ) + ".bkp" ;
230
+ if let Err ( e) = fs:: copy ( & s_path, & s_path_bkp) {
231
+ error ! ( "Couldn't backup {} into {}, {}" , s_path, s_path_bkp, e) ;
232
+ return Err ( sgx_status_t:: SGX_ERROR_UNEXPECTED ) ;
233
+ }
225
234
226
- if let Err ( e) = seal ( data. as_slice ( ) , sPath) {
235
+ if let Err ( e) = seal ( data. as_slice ( ) , s_path) {
236
+ error ! ( "Couldn't RE-seal file {}, {}" , s_path, e) ;
227
237
return Err ( e) ;
228
238
}
239
+
240
+ info ! ( "File {} successfully RE-sealed" , s_path) ;
241
+ }
242
+ else
243
+ {
244
+ info ! ( "File {} doesn't exist, skipping" , s_path) ;
229
245
}
230
246
231
247
Ok ( ( ) )
0 commit comments