Skip to content

fix(unzip): preserve subfolder structure when extracting archives#443

Open
dschmidt wants to merge 1 commit into
mainfrom
fix/unzip-preserve-subfolders
Open

fix(unzip): preserve subfolder structure when extracting archives#443
dschmidt wants to merge 1 commit into
mainfrom
fix/unzip-preserve-subfolders

Conversation

@dschmidt
Copy link
Copy Markdown
Contributor

@dschmidt dschmidt commented May 16, 2026

Description

Extracted files lost their subfolder paths and ended up flat inside the extraction folder. For example, extracting maps-1.0.2.zip (which contains js/maps-uKkx1qsf.js) put maps-uKkx1qsf.js directly into the extraction folder instead of inside js/.

Root cause

The handler set webkitRelativePath on file.meta, but uppyService.onBeforeFileAdded unconditionally recomputes meta.relativePath from file.data.relativePath || file.data.webkitRelativePath. Neither of those was being set on the blob by the unzip handler. Result: meta.relativePath was always undefined for extracted files, so HandleUpload treated them all as root-level and didn't create the nested directory tree.

This regressed in opencloud-eu/web@e1828e7f70 (refactor: switch back to upstream uppy, 2024-12-20), which dropped the file.meta.relativePath || file.meta.webkitRelativePath fallback in HandleUpload. From that point on, only file.data.* was consulted, but the unzip handler wasn't writing there.

Affected web versions

The fallback was removed in web@e1828e7f70 (2024-12-20) and first shipped in web v1.0.0 (2025-02-25). Module federation (the runtime mechanism that loads this extension) was added in web@f496f9a9f4 (2026-03-24), first shipped in web v6.1.0. This unzip build pins @opencloud-eu/web-pkg: ^7.0.0, so it can only load into web v7.0.0+ at runtime. Every web version that can load this bundle has the regression. There is no host where the old meta.* fallback still works.

Fix

Attach relativePath directly to the data blob. This matches uppy's convention, the same one used by DropTarget.getDroppedFiles for drag-and-drop folder uploads (web, packages/web-pkg/src/services/uppy/DropTarget/getDroppedFiles.ts:17). uppyService now picks it up, populates meta.relativePath, and HandleUpload creates the nested directory tree as expected.

Test

The e2e test (extended to assert the preserved subfolder structure for data.zip) currently has to stay skipped because the OpenCloud rolling image bundles web v7.0.0, which is missing two prerequisite web fixes:

  1. fix: service announcement order web#2506 (service announcement order, merged 2026-05-13): without it, useService<UppyService>('$uppyService') returns undefined when the unzip handler runs, the extract throws, and the catch shows "Failed to extract archive". This is the same reason the test was originally skipped.
  2. fix: skip upload conflict check when uploads target a non-current folder web#2513: suppresses a false-positive "Folder already exists" dialog triggered when the zip's top-level folder name matches anything in the user's current folder. data.zip wraps its content in data/, which is the same name as the freshly-created extraction folder, so the dialog fires.

Once a published OpenCloud image bundles a web that contains both, drop test.skip and the merge-dialog dismissal block. Verified locally against an unbundled web build (override mounting ../web/dist) that includes both PRs.

Related Issue

Types of changes

  • Bugfix
  • Enhancement (a change that doesn't break existing code or deployments)
  • Breaking change (a modification that affects current functionality)
  • Technical debt (addressing code that needs refactoring or improvements)
  • Tests (adding or improving tests)
  • Documentation (updates or additions to documentation)
  • Maintenance (like dependency updates or tooling adjustments)

@dschmidt dschmidt force-pushed the fix/unzip-preserve-subfolders branch from 5e9d798 to 31bc410 Compare May 16, 2026 08:46
@dschmidt dschmidt requested review from JammingBen and Copilot May 16, 2026 08:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a bug where unzipping archives lost their nested folder structure. The root cause was that the unzip handler set webkitRelativePath on file.meta, but uppyService's onBeforeFileAdded overrides meta.relativePath from file.data.relativePath/file.data.webkitRelativePath only. The fix attaches relativePath to the data Blob (matching uppy's convention used by drag-and-drop folder upload).

Changes:

  • Attach relativePath directly to the extracted file's data Blob (typed via local FileWithPath) and drop the now-ineffective webkitRelativePath on meta.
  • Unskip and extend the e2e test to verify nested folder preservation, with a temporary workaround for an unrelated "Folder already exists" dialog (web#2513).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/web-app-unzip/src/composables/useUnzipAction.ts Sets relativePath on the data blob instead of webkitRelativePath on meta so uppyService preserves subfolder structure.
packages/web-app-unzip/tests/e2e/extractZip.spec.ts Enables the previously skipped e2e test and adds assertions for nested directory preservation; dismisses an unrelated false-positive merge dialog.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dschmidt dschmidt force-pushed the fix/unzip-preserve-subfolders branch 2 times, most recently from e1224d7 to 86cb833 Compare May 16, 2026 09:09
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.
@dschmidt dschmidt force-pushed the fix/unzip-preserve-subfolders branch from 86cb833 to c322475 Compare May 16, 2026 09:11
@dschmidt dschmidt requested a review from Copilot May 16, 2026 09:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unzip 1.0.4 - extract wrongly - no subfolder was created

2 participants