def test_build_addrs(): backend_addr = BackendAddr.from_url(BackendAddrTestbed.url) assert backend_addr.hostname == "parsec.cloud.com" assert backend_addr.port == 443 assert backend_addr.use_ssl is True organization_id = OrganizationID("MyOrg") root_verify_key = SigningKey.generate().verify_key organization_addr = BackendOrganizationAddr.build( backend_addr=backend_addr, organization_id=organization_id, root_verify_key=root_verify_key ) assert organization_addr.organization_id == organization_id assert organization_addr.root_verify_key == root_verify_key organization_bootstrap_addr = BackendOrganizationBootstrapAddr.build( backend_addr=backend_addr, organization_id=organization_id, token="a0000000000000000000000000000001", ) assert organization_bootstrap_addr.token == "a0000000000000000000000000000001" assert organization_bootstrap_addr.organization_id == organization_id organization_bootstrap_addr2 = BackendOrganizationBootstrapAddr.build( backend_addr=backend_addr, organization_id=organization_id, token=None ) assert organization_bootstrap_addr2.organization_id == organization_id assert organization_bootstrap_addr2.token == "" organization_file_link_addr = BackendOrganizationFileLinkAddr.build( organization_addr=organization_addr, workspace_id=EntryID.from_hex("2d4ded12-7406-4608-833b-7f57f01156e2"), encrypted_path=b"<encrypted_payload>", ) assert organization_file_link_addr.workspace_id == EntryID.from_hex( "2d4ded12-7406-4608-833b-7f57f01156e2" ) assert organization_file_link_addr.encrypted_path == b"<encrypted_payload>" invitation_addr = BackendInvitationAddr.build( backend_addr=backend_addr, organization_id=organization_id, invitation_type=InvitationType.USER, token=InvitationToken.from_hex("a0000000000000000000000000000001"), ) assert invitation_addr.organization_id == organization_id assert invitation_addr.token == InvitationToken.from_hex("a0000000000000000000000000000001") assert invitation_addr.invitation_type == InvitationType.USER
async def _load_changes(self) -> bool: if self._changes_loaded: return True # Initialize due_time so that if we cannot retrieve the changes, we # will wait until an external event (most likely a `sharing.updated`) # make it worth to retry self.due_time = math.inf # 1) Fetch new checkpoint and changes realm_checkpoint = await self._get_local_storage().get_realm_checkpoint() try: rep = await self._get_backend_cmds().vlob_poll_changes( RealmID(self.id.uuid), realm_checkpoint ) except BackendNotAvailable: raise # Another backend error except BackendConnectionError as exc: logger.warning("Unexpected backend response during sync bootstrap", exc_info=exc) return False if rep["status"] == "not_found": # Workspace not yet synchronized with backend new_checkpoint = 0 changes = {} elif rep["status"] in ("in_maintenance", "not_allowed"): return False elif rep["status"] != "ok": return False else: new_checkpoint = rep["current_checkpoint"] changes = rep["changes"] # 2) Store new checkpoint and changes await self._get_local_storage().update_realm_checkpoint( new_checkpoint, {EntryID.from_hex(name.hex): val for name, val in changes.items()} ) # 3) Compute local and remote changes that need to be synced need_sync_local, need_sync_remote = await self._get_local_storage().get_need_sync_entries() now = current_time() # Ignore local changes in read only mode if not self.read_only: self._local_changes = {entry_id: LocalChange(now) for entry_id in need_sync_local} self._remote_changes = need_sync_remote # 4) Finally refresh due time according to the changes self._compute_due_time() self._changes_loaded = True return True
async def make_workspace_dir_inconsistent(workspace: WorkspaceFS, dir: FsPath): """ Create directory and make it inconsistent by adding an entry refering to an unknown EntryID. """ await workspace.mkdir(dir) await workspace.touch(dir / "foo.txt") rep_info = await workspace.transactions.entry_info(dir) rep_manifest = await workspace.local_storage.get_manifest(rep_info["id"]) children = rep_manifest.children children[EntryName("newfail.txt")] = EntryID.from_hex( "b9295787-d9aa-6cbd-be27-1ff83ac72fa6") rep_manifest = rep_manifest.evolve(children=children) async with workspace.local_storage.lock_manifest(rep_info["id"]): await workspace.local_storage.set_manifest(rep_info["id"], rep_manifest) await workspace.sync()
def selected_files(self): files = [] # As it turns out, Qt can return several overlapping ranges # Fix the overlap by using a sorted set rows = { row for r in self.selectedRanges() for row in range(r.topRow(), r.bottomRow() + 1) } for row in sorted(rows): item = self.item(row, Column.NAME) files.append( SelectedFile( row, item.data(TYPE_DATA_INDEX), item.data(NAME_DATA_INDEX), EntryID.from_hex(item.data(ENTRY_ID_DATA_INDEX)), )) return files