@@ -758,45 +758,20 @@ def safe_remove(self, path_info, force=False):
758758 self .remove (path_info )
759759
760760 def _checkout_file (
761- self ,
762- path_info ,
763- checksum ,
764- force ,
765- progress_callback = None ,
766- save_link = True ,
761+ self , path_info , checksum , force , progress_callback = None
767762 ):
768- # NOTE: In case if path_info is already cached and path_info's
769- # link type matches cache link type, we would like to avoid
770- # relinking.
771- if self .changed (
772- path_info , {self .PARAM_CHECKSUM : checksum }
773- ) or not self ._link_matches (path_info ):
763+ cache_info = self .checksum_to_path_info (checksum )
764+ if self .exists (path_info ):
765+ msg = "data '{}' exists. Removing before checkout."
766+ logger .warning (msg .format (str (path_info )))
774767 self .safe_remove (path_info , force = force )
775768
776- cache_info = self .checksum_to_path_info (checksum )
777- self .link (cache_info , path_info )
778-
779- if save_link :
780- self .state .save_link (path_info )
781-
782- self .state .save (path_info , checksum )
783- else :
784- # NOTE: performing (un)protection costs us +/- the same as checking
785- # if path_info is protected. Instead of implementing logic,
786- # just (un)protect according to self.protected.
787- if self .protected :
788- self .protect (path_info )
789- else :
790- # NOTE dont allow copy, because we checked before that link
791- # type matches cache, and we don't want data duplication
792- self .unprotect (path_info , allow_copy = False )
793-
769+ self .link (cache_info , path_info )
770+ self .state .save_link (path_info )
771+ self .state .save (path_info , checksum )
794772 if progress_callback :
795773 progress_callback (str (path_info ))
796774
797- def _link_matches (self , path_info ):
798- return True
799-
800775 def makedirs (self , path_info ):
801776 """Optional: Implement only if the remote needs to create
802777 directories before copying/linking/moving data
@@ -818,14 +793,17 @@ def _checkout_dir(
818793 for entry in dir_info :
819794 relative_path = entry [self .PARAM_RELPATH ]
820795 entry_checksum = entry [self .PARAM_CHECKSUM ]
796+ entry_cache_info = self .checksum_to_path_info (entry_checksum )
821797 entry_info = path_info / relative_path
822- self ._checkout_file (
823- entry_info ,
824- entry_checksum ,
825- force ,
826- progress_callback ,
827- save_link = False ,
828- )
798+
799+ entry_checksum_info = {self .PARAM_CHECKSUM : entry_checksum }
800+ if self .changed (entry_info , entry_checksum_info ):
801+ if self .exists (entry_info ):
802+ self .safe_remove (entry_info , force = force )
803+ self .link (entry_cache_info , entry_info )
804+ self .state .save (entry_info , entry_checksum )
805+ if progress_callback :
806+ progress_callback (str (entry_info ))
829807
830808 self ._remove_redundant_files (path_info , dir_info , force )
831809
@@ -904,7 +882,7 @@ def get_files_number(self, checksum):
904882 return 1
905883
906884 @staticmethod
907- def unprotect (path_info , allow_copy = True ):
885+ def unprotect (path_info ):
908886 pass
909887
910888 def _get_unpacked_dir_names (self , checksums ):
0 commit comments