def get_sync_strategy(self, path: FsPath, recursive: dict) -> Tuple[FsPath, dict]: # Consider root is never a placeholder for curr_path in path.walk_to_path(): _, curr_manifest = self._retrieve_entry_read_only(curr_path) if curr_manifest.is_placeholder: sync_path = curr_path.parent break else: return path, recursive sync_recursive = recursive for curr_path in path.walk_from_path(): if curr_path == sync_path: break sync_recursive = {curr_path.name: sync_recursive} return sync_path, sync_recursive
def _retrieve_entry_read_only( self, path: FsPath, collector=None) -> Tuple[Access, LocalManifest]: curr_access = self.root_access curr_manifest = self._get_manifest_read_only(curr_access) if collector: collector(curr_access, curr_manifest) try: _, *hops, dest = list(path.walk_to_path()) except ValueError: return curr_access, curr_manifest for hop in hops: try: curr_access = curr_manifest.children[hop.name] except KeyError: raise FileNotFoundError(2, "No such file or directory", str(hop)) curr_manifest = self._get_manifest_read_only(curr_access) if not is_folderish_manifest(curr_manifest): raise NotADirectoryError(20, "Not a directory", str(hop)) if collector: collector(curr_access, curr_manifest) try: curr_access = curr_manifest.children[dest.name] except KeyError: raise FileNotFoundError(2, "No such file or directory", str(dest)) curr_manifest = self._get_manifest_read_only(curr_access) if collector: collector(curr_access, curr_manifest) return curr_access, curr_manifest