From c322475292c3058b0838b76a8ff5925068e7671e Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sat, 16 May 2026 10:45:59 +0200 Subject: [PATCH] fix(unzip): preserve subfolder structure when extracting archives extracted files lost their subfolder paths and ended up flat inside the extraction folder. the handler set webkitRelativePath on file.meta, but uppyService.onBeforeFileAdded recomputes meta.relativePath from file.data.relativePath || file.data.webkitRelativePath, neither of which the unzip handler was setting on the blob. attach relativePath directly to the data blob (matching uppy's convention, the same one used by DropTarget.getDroppedFiles for drag-and-drop folder uploads). uppyService now picks it up, populates meta.relativePath, and HandleUpload creates the nested directory tree as expected. regression: introduced by opencloud-eu/web@e1828e7f70 ("refactor: switch back to upstream uppy", 2024-12-20), which dropped the meta.relativePath || meta.webkitRelativePath fallback in HandleUpload. unskips the previously skipped e2e test (its original blocker, opencloud-eu/web#2506, has landed on main) and extends it to assert the preserved subfolder structure as a regression for #293. data.zip wraps its content in a "data/" folder matching the archive name, which trips a false-positive "Folder already exists" dialog in HandleUpload (the conflict detector checks the user's current folder instead of the actual upload target. see opencloud-eu/web#2513). the e2e dismisses the dialog with "Merge" so this PR is independently mergeable. once web#2513 is bundled in the published OpenCloud image, the wait will time out and fail the test as a reminder to remove the workaround. --- .../src/composables/useUnzipAction.ts | 16 +++++++--- .../tests/e2e/extractZip.spec.ts | 29 ++++++++++++++----- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/packages/web-app-unzip/src/composables/useUnzipAction.ts b/packages/web-app-unzip/src/composables/useUnzipAction.ts index f17677ac..36a59feb 100644 --- a/packages/web-app-unzip/src/composables/useUnzipAction.ts +++ b/packages/web-app-unzip/src/composables/useUnzipAction.ts @@ -23,6 +23,11 @@ import workerUrl from '@zip.js/zip.js/dist/zip-web-worker.js?worker&url' const SUPPORTED_MIME_TYPES = ['application/zip'] const MAX_SIZE_MB = 64 // in mb +// uppy's convention for directory-upload metadata on the file object. mirrors the +// (non-exported) FileWithPath in web/packages/web-pkg/src/services/uppy/uppyService.ts. +// uppyService.getRelativeFilePath reads .relativePath from file.data. +type FileWithPath = Blob & { relativePath?: string } + export const useUnzipAction = () => { const { $gettext, current: currentLanguage } = useGettext() const clientService = useClientService() @@ -88,13 +93,16 @@ export const useUnzipAction = () => { const path = dirname(result.filename) const name = path === '.' ? result.filename : result.filename.substring(path.length + 1) + if (path !== '.') { + // attach relativePath to the data blob so uppyService preserves + // the subfolder structure when uploading the extracted files. + ;(data as FileWithPath).relativePath = urlJoin(path, name) + } + return { name, data, - meta: { - ...(path !== '.' && { webkitRelativePath: urlJoin(path, name) }), - uploadId - } + meta: { uploadId } } as unknown as OcMinimalUppyFile }) }) diff --git a/packages/web-app-unzip/tests/e2e/extractZip.spec.ts b/packages/web-app-unzip/tests/e2e/extractZip.spec.ts index d5f46b72..1f1726b1 100644 --- a/packages/web-app-unzip/tests/e2e/extractZip.spec.ts +++ b/packages/web-app-unzip/tests/e2e/extractZip.spec.ts @@ -15,18 +15,33 @@ test.afterEach(async () => { await logout(userPage) }) -// FIXME: currently skipped because of https://github.com/opencloud-eu/web/pull/2506 -// unskip with the next OpenCloud release (v7 probably) -test.skip('extract zip file', async () => { +// FIXME: skipped until the bundled OpenCloud image ships a web build that contains +// both: +// - https://github.com/opencloud-eu/web/pull/2506 (services announced before apps +// init, otherwise uppyService is undefined when the extract handler runs and the +// archive extraction fails) +// - https://github.com/opencloud-eu/web/pull/2513 (suppresses a false-positive +// "Folder already exists" dialog that fires whenever the zip's top-level folder +// name matches anything in the user's current folder, which is the case for +// data.zip) +test.skip('extract zip file preserves subfolder structure', async () => { const uploadFile = new FilesAppBar(userPage) await uploadFile.uploadFile('data.zip') const file = new FilesPage(userPage) await file.extractZip('data.zip') + // extraction creates a folder named after the archive await file.openFolder('data') - await expect( - userPage.locator('span.oc-resource-basename', { hasText: 'logo-wide' }) - ).toBeVisible() - await expect(userPage.locator('span.oc-resource-basename', { hasText: 'lorem' })).toBeVisible() + // the zip's own top-level "data/" folder must be preserved inside + await expect(userPage.locator('[data-test-resource-name="data"]')).toBeVisible() + + await file.openFolder('data') + await expect(userPage.locator('[data-test-resource-name="logo-wide.png"]')).toBeVisible() + await expect(userPage.locator('[data-test-resource-name="lorem.txt"]')).toBeVisible() + await expect(userPage.locator('[data-test-resource-name="dir"]')).toBeVisible() + + // nested subfolder content must be preserved, not flattened + await file.openFolder('dir') + await expect(userPage.locator('[data-test-resource-name="lorem.txt"]')).toBeVisible() })