@@ -285,10 +285,9 @@ impl ComparableValue {
285
285
}
286
286
287
287
// Used on file output arguments.
288
- // Based on path inode or file_index check if the file already has been specified.
289
288
// If yes, use the same file pointer.
290
289
struct FileMemoizer {
291
- mem : HashMap < u64 , Arc < File > > ,
290
+ mem : HashMap < FileInformation , Arc < File > > ,
292
291
}
293
292
impl FileMemoizer {
294
293
fn new ( ) -> Self {
@@ -297,30 +296,22 @@ impl FileMemoizer {
297
296
}
298
297
}
299
298
fn get_or_create_file ( & mut self , path : & str ) -> Result < Arc < File > , Box < dyn Error > > {
300
- let path = Path :: new ( path) ;
301
- let file_id = self . get_file_id ( path) ;
302
- if file_id. is_err ( ) {
303
- let file = Arc :: new ( File :: create ( path) ?) ;
304
- self . mem . insert ( self . get_file_id ( path) ?, file. clone ( ) ) ;
305
- return Ok ( file) ;
299
+ let mut file_info = FileInformation :: from_path ( path, true ) ;
300
+ match file_info {
301
+ Ok ( info) => {
302
+ let file = self
303
+ . mem
304
+ . entry ( info)
305
+ . or_insert ( Arc :: new ( File :: create ( path) ?) ) ;
306
+ Ok ( file. clone ( ) )
307
+ }
308
+ Err ( _) => {
309
+ let file = Arc :: new ( File :: create ( path) ?) ;
310
+ file_info = FileInformation :: from_path ( path, true ) ;
311
+ self . mem . insert ( file_info?, file. clone ( ) ) ;
312
+ Ok ( file)
313
+ }
306
314
}
307
-
308
- let file = self
309
- . mem
310
- . entry ( file_id. unwrap ( ) )
311
- . or_insert ( Arc :: new ( File :: create ( path) ?) ) ;
312
- Ok ( file. clone ( ) )
313
- }
314
-
315
- fn get_file_id ( & self , path : & Path ) -> Result < u64 , Box < dyn Error > > {
316
- let file_info = FileInformation :: from_path ( path, true ) ?;
317
- #[ cfg( windows) ]
318
- let file_inode = file_info. file_index ( ) ;
319
-
320
- #[ cfg( unix) ]
321
- let file_inode = file_info. inode ( ) ;
322
-
323
- Ok ( file_inode)
324
315
}
325
316
}
326
317
0 commit comments