def resize(self, manifest: LocalFileManifest, size: int) -> LocalFileManifest: # No-op if size == manifest.size: return manifest # Resize new_manifest, write_operations, removed_ids = prepare_resize( manifest, size) for chunk, offset in write_operations: self.write_chunk(chunk, b"", offset) for removed_id in removed_ids: self.clear_chunk_data(removed_id) return new_manifest
async def _manifest_resize(self, manifest: LocalFileManifest, length: int) -> None: """This internal helper does not perform any locking.""" # No-op if manifest.size == length: return # Prepare manifest, write_operations, removed_ids = prepare_resize(manifest, length) # Writing for chunk, offset in write_operations: await self._write_chunk(chunk, b"", offset) # Atomic change await self.local_storage.set_manifest(manifest.id, manifest, removed_ids=removed_ids)
async def _manifest_resize(self, manifest: LocalFileManifest, length: int, cache_only: bool = False) -> None: """This internal helper does not perform any locking.""" # No-op if manifest.size == length: return # Prepare updated = self.device.timestamp() manifest, write_operations, removed_ids = prepare_resize( manifest, length, updated) # Writing for chunk, offset in write_operations: await self._write_chunk(chunk, b"", offset) # Atomic change await self.local_storage.set_manifest(manifest.id, manifest, removed_ids=removed_ids, cache_only=cache_only)