def _collect_used_dir_cache(self, remote=None, force=False, jobs=None, filter_info=None) -> Optional["Tree"]: """Fetch dir cache and return used object IDs for this out.""" try: self.get_dir_cache(jobs=jobs, remote=remote) except DvcException: logger.debug(f"failed to pull cache for '{self}'") try: objects.check(self.odb, self.odb.get(self.hash_info)) except FileNotFoundError: msg = ("Missing cache for directory '{}'. " "Cache for files inside will be lost. " "Would you like to continue? Use '-f' to force.") if not force and not prompt.confirm(msg.format(self.path_info)): raise CollectCacheError( "unable to fully collect used cache" " without cache for directory '{}'".format(self)) return None obj = self.get_obj() if filter_info and filter_info != self.path_info: prefix = filter_info.relative_to(self.path_info).parts obj = obj.filter(prefix) return obj
def collect_used_dir_cache( self, remote=None, force=False, jobs=None, filter_info=None ): """Get a list of `info`s related to the given directory. - Pull the directory entry from the remote cache if it was changed. Example: Given the following commands: $ echo "foo" > directory/foo $ echo "bar" > directory/bar $ dvc add directory It will return a NamedCache like: nc = NamedCache() nc.add(self.scheme, 'c157a79031e1', 'directory/foo') nc.add(self.scheme, 'd3b07384d113', 'directory/bar') """ cache = NamedCache() try: self.get_dir_cache(jobs=jobs, remote=remote) except DvcException: logger.debug(f"failed to pull cache for '{self}'") if self.cache.changed_cache_file(self.hash_info): msg = ( "Missing cache for directory '{}'. " "Cache for files inside will be lost. " "Would you like to continue? Use '-f' to force." ) if not force and not prompt.confirm(msg.format(self.path_info)): raise CollectCacheError( "unable to fully collect used cache" " without cache for directory '{}'".format(self) ) else: return cache path = str(self.path_info) filter_path = str(filter_info) if filter_info else None is_win = os.name == "nt" for entry in self.dir_cache: checksum = entry[self.tree.PARAM_CHECKSUM] entry_relpath = entry[self.tree.PARAM_RELPATH] if is_win: entry_relpath = entry_relpath.replace("/", os.sep) entry_path = os.path.join(path, entry_relpath) if ( not filter_path or entry_path == filter_path or entry_path.startswith(filter_path + os.sep) ): cache.add(self.scheme, checksum, entry_path) return cache
def collect_used_dir_cache( self, remote=None, force=False, jobs=None, filter_info=None) -> Dict[Optional["ObjectDB"], Set["HashFile"]]: """Fetch dir cache and return used objects for this out.""" try: self.get_dir_cache(jobs=jobs, remote=remote) except DvcException: logger.debug(f"failed to pull cache for '{self}'") try: objects.check(self.odb, self.odb.get(self.hash_info)) except (FileNotFoundError, ObjectFormatError): msg = ("Missing cache for directory '{}'. " "Cache for files inside will be lost. " "Would you like to continue? Use '-f' to force.") if not force and not prompt.confirm(msg.format(self.path_info)): raise CollectCacheError( "unable to fully collect used cache" " without cache for directory '{}'".format(self)) return {} obj = self.get_obj(filter_info=filter_info, copy=True) self._set_obj_names(obj) return {None: {obj}}
def _collect_used_dir_cache( self, remote=None, force=False, jobs=None, filter_info=None ): """Get a list of `info`s related to the given directory. - Pull the directory entry from the remote cache if it was changed. Example: Given the following commands: $ echo "foo" > directory/foo $ echo "bar" > directory/bar $ dvc add directory It will return a NamedCache like: nc = NamedCache() nc.add(self.scheme, 'c157a79031e1', 'directory/foo') nc.add(self.scheme, 'd3b07384d113', 'directory/bar') """ cache = NamedCache() if self.cache.changed_cache_file(self.checksum): try: self.repo.cloud.pull( NamedCache.make("local", self.checksum, str(self)), jobs=jobs, remote=remote, show_checksums=False, ) except DvcException: logger.debug("failed to pull cache for '{}'".format(self)) if self.cache.changed_cache_file(self.checksum): msg = ( "Missing cache for directory '{}'. " "Cache for files inside will be lost. " "Would you like to continue? Use '-f' to force." ) if not force and not prompt.confirm(msg.format(self.path_info)): raise CollectCacheError( "unable to fully collect used cache" " without cache for directory '{}'".format(self) ) else: return cache for entry in self.dir_cache: checksum = entry[self.remote.PARAM_CHECKSUM] info = self.path_info / entry[self.remote.PARAM_RELPATH] if not filter_info or info.isin_or_eq(filter_info): cache.add(self.scheme, checksum, str(info)) return cache
def collect_used_dir_cache( self, remote=None, force=False, jobs=None, filter_info=None ): """Get a list of `info`s related to the given directory. - Pull the directory entry from the remote cache if it was changed. Example: Given the following commands: $ echo "foo" > directory/foo $ echo "bar" > directory/bar $ dvc add directory It will return a NamedCache like: nc = NamedCache() nc.add(self.scheme, 'c157a79031e1', 'directory/foo') nc.add(self.scheme, 'd3b07384d113', 'directory/bar') """ cache = NamedCache() try: self.get_dir_cache(jobs=jobs, remote=remote) except DvcException: logger.debug(f"failed to pull cache for '{self}'") try: objects.check(self.odb, self.odb.get(self.hash_info)) except (FileNotFoundError, ObjectFormatError): msg = ( "Missing cache for directory '{}'. " "Cache for files inside will be lost. " "Would you like to continue? Use '-f' to force." ) if not force and not prompt.confirm(msg.format(self.path_info)): raise CollectCacheError( "unable to fully collect used cache" " without cache for directory '{}'".format(self) ) return cache path = str(self.path_info) filter_path = str(filter_info) if filter_info else None for entry_key, entry_obj in self.obj: entry_path = os.path.join(path, *entry_key) if ( not filter_path or entry_path == filter_path or entry_path.startswith(filter_path + os.sep) ): cache.add(self.scheme, entry_obj.hash_info.value, entry_path) return cache