@@ -336,6 +336,7 @@ where
336
336
mode,
337
337
entry : dir_entry,
338
338
search_id,
339
+ dirty : false ,
339
340
} ,
340
341
Mode :: ReadWriteAppend => {
341
342
let mut file = File {
@@ -346,6 +347,7 @@ where
346
347
mode,
347
348
entry : dir_entry,
348
349
search_id,
350
+ dirty : false ,
349
351
} ;
350
352
// seek_from_end with 0 can't fail
351
353
file. seek_from_end ( 0 ) . ok ( ) ;
@@ -360,6 +362,7 @@ where
360
362
mode,
361
363
entry : dir_entry,
362
364
search_id,
365
+ dirty : false ,
363
366
} ;
364
367
match & mut volume. volume_type {
365
368
VolumeType :: Fat ( fat) => {
@@ -452,6 +455,7 @@ where
452
455
mode,
453
456
entry,
454
457
search_id,
458
+ dirty : false ,
455
459
} ;
456
460
457
461
// Remember this open file
@@ -567,6 +571,9 @@ where
567
571
if file. mode == Mode :: ReadOnly {
568
572
return Err ( Error :: ReadOnly ) ;
569
573
}
574
+
575
+ file. dirty = true ;
576
+
570
577
if file. starting_cluster . 0 < RESERVED_ENTRIES {
571
578
// file doesn't have a valid allocated cluster (possible zero-length file), allocate one
572
579
file. starting_cluster = match & mut volume. volume_type {
@@ -665,15 +672,17 @@ where
665
672
666
673
/// Close a file with the given full path.
667
674
pub fn close_file ( & mut self , volume : & mut Volume , file : File ) -> Result < ( ) , Error < D :: Error > > {
668
- match volume. volume_type {
669
- VolumeType :: Fat ( ref mut fat) => {
670
- debug ! ( "Updating FAT info sector" ) ;
671
- fat. update_info_sector ( self ) ?;
672
- debug ! ( "Updating dir entry {:?}" , file. entry) ;
673
- let fat_type = fat. get_fat_type ( ) ;
674
- self . write_entry_to_disk ( fat_type, & file. entry ) ?;
675
- }
676
- } ;
675
+ if file. dirty {
676
+ match volume. volume_type {
677
+ VolumeType :: Fat ( ref mut fat) => {
678
+ debug ! ( "Updating FAT info sector" ) ;
679
+ fat. update_info_sector ( self ) ?;
680
+ debug ! ( "Updating dir entry {:?}" , file. entry) ;
681
+ let fat_type = fat. get_fat_type ( ) ;
682
+ self . write_entry_to_disk ( fat_type, & file. entry ) ?;
683
+ }
684
+ } ;
685
+ }
677
686
678
687
// Unwrap, because we should never be in a situation where we're attempting to close a file
679
688
// with an ID which doesn't exist in our open files list.
0 commit comments