@@ -336,6 +336,7 @@ where
336336 mode,
337337 entry : dir_entry,
338338 search_id,
339+ dirty : false ,
339340 } ,
340341 Mode :: ReadWriteAppend => {
341342 let mut file = File {
@@ -346,6 +347,7 @@ where
346347 mode,
347348 entry : dir_entry,
348349 search_id,
350+ dirty : false ,
349351 } ;
350352 // seek_from_end with 0 can't fail
351353 file. seek_from_end ( 0 ) . ok ( ) ;
@@ -360,6 +362,7 @@ where
360362 mode,
361363 entry : dir_entry,
362364 search_id,
365+ dirty : false ,
363366 } ;
364367 match & mut volume. volume_type {
365368 VolumeType :: Fat ( fat) => {
@@ -452,6 +455,7 @@ where
452455 mode,
453456 entry,
454457 search_id,
458+ dirty : false ,
455459 } ;
456460
457461 // Remember this open file
@@ -567,6 +571,9 @@ where
567571 if file. mode == Mode :: ReadOnly {
568572 return Err ( Error :: ReadOnly ) ;
569573 }
574+
575+ file. dirty = true ;
576+
570577 if file. starting_cluster . 0 < RESERVED_ENTRIES {
571578 // file doesn't have a valid allocated cluster (possible zero-length file), allocate one
572579 file. starting_cluster = match & mut volume. volume_type {
@@ -665,15 +672,17 @@ where
665672
666673 /// Close a file with the given full path.
667674 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+ }
677686
678687 // Unwrap, because we should never be in a situation where we're attempting to close a file
679688 // with an ID which doesn't exist in our open files list.
0 commit comments