##// END OF EJS Templates
rust-dirstate-v2: clean up previous data file after the docket is written...
Raphaël Gomès -
r50038:802e2c25 stable
parent child Browse files
Show More
@@ -434,7 +434,7 impl Repo {
434 // TODO: Maintain a `DirstateMap::dirty` flag, and return early here if
434 // TODO: Maintain a `DirstateMap::dirty` flag, and return early here if
435 // it’s unset
435 // it’s unset
436 let parents = self.dirstate_parents()?;
436 let parents = self.dirstate_parents()?;
437 let packed_dirstate = if self.has_dirstate_v2() {
437 let (packed_dirstate, old_uuid_to_remove) = if self.has_dirstate_v2() {
438 let uuid = self.dirstate_data_file_uuid.get_or_init(self)?;
438 let uuid = self.dirstate_data_file_uuid.get_or_init(self)?;
439 let mut uuid = uuid.as_ref();
439 let mut uuid = uuid.as_ref();
440 let can_append = uuid.is_some();
440 let can_append = uuid.is_some();
@@ -443,14 +443,16 impl Repo {
443 if !append {
443 if !append {
444 uuid = None
444 uuid = None
445 }
445 }
446 let uuid = if let Some(uuid) = uuid {
446 let (uuid, old_uuid) = if let Some(uuid) = uuid {
447 std::str::from_utf8(uuid)
447 let as_str = std::str::from_utf8(uuid)
448 .map_err(|_| {
448 .map_err(|_| {
449 HgError::corrupted("non-UTF-8 dirstate data file ID")
449 HgError::corrupted("non-UTF-8 dirstate data file ID")
450 })?
450 })?
451 .to_owned()
451 .to_owned();
452 let old_uuid_to_remove = Some(as_str.to_owned());
453 (as_str, old_uuid_to_remove)
452 } else {
454 } else {
453 DirstateDocket::new_uid()
455 (DirstateDocket::new_uid(), None)
454 };
456 };
455 let data_filename = format!("dirstate.{}", uuid);
457 let data_filename = format!("dirstate.{}", uuid);
456 let data_filename = self.hg_vfs().join(data_filename);
458 let data_filename = self.hg_vfs().join(data_filename);
@@ -480,7 +482,8 impl Repo {
480 }
482 }
481 })()
483 })()
482 .when_writing_file(&data_filename)?;
484 .when_writing_file(&data_filename)?;
483 DirstateDocket::serialize(
485
486 let packed_dirstate = DirstateDocket::serialize(
484 parents,
487 parents,
485 tree_metadata,
488 tree_metadata,
486 data_size,
489 data_size,
@@ -488,11 +491,20 impl Repo {
488 )
491 )
489 .map_err(|_: std::num::TryFromIntError| {
492 .map_err(|_: std::num::TryFromIntError| {
490 HgError::corrupted("overflow in dirstate docket serialization")
493 HgError::corrupted("overflow in dirstate docket serialization")
491 })?
494 })?;
495
496 (packed_dirstate, old_uuid)
492 } else {
497 } else {
493 map.pack_v1(parents)?
498 (map.pack_v1(parents)?, None)
494 };
499 };
495 self.hg_vfs().atomic_write("dirstate", &packed_dirstate)?;
500
501 let vfs = self.hg_vfs();
502 vfs.atomic_write("dirstate", &packed_dirstate)?;
503 if let Some(uuid) = old_uuid_to_remove {
504 // Remove the old data file after the new docket pointing to the
505 // new data file was written.
506 vfs.remove_file(format!("dirstate.{}", uuid))?;
507 }
496 Ok(())
508 Ok(())
497 }
509 }
498 }
510 }
General Comments 0
You need to be logged in to leave comments. Login now