fix(files): preserve nested folder structure when archiving workspace files - #5985
Conversation
… files The file_compress tool flattened every entry to its leaf name, so asking Sim to package a folder produced a zip with all files at the root and collision suffixes instead of the folder layout. Archive entry paths now mirror the workspace folder structure, with the ancestor chain the whole selection shares dropped so a single folder is not nested under its parents. The bulk download route reuses the same builder instead of its own copy of the path sanitizing and dedup logic.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryLow Risk Overview A shared Unit tests cover layout mirroring, cross-folder same names, collision suffixing, rebasing (including segment-wise common ancestors), and sanitization. The file compress tool description notes that folder structure is preserved. Reviewed by Cursor Bugbot for commit a4de062. Configure here. |
Greptile SummaryThis PR centralizes safe ZIP-entry path construction and preserves workspace folder structure in generated archives.
Confidence Score: 5/5The PR appears safe to merge, with no concrete changed-code defects identified. The shared helper preserves source ordering, sanitizes every generated path segment, prevents duplicate ZIP entries, and applies common-folder rebasing only on the compression path where it is intended.
|
| Filename | Overview |
|---|---|
| apps/sim/lib/uploads/zip-entry-path.ts | Introduces ordered, traversal-safe ZIP path construction with optional common-folder rebasing and collision handling. |
| apps/sim/app/api/tools/file/manage/route.ts | Associates resolved workspace files with their folder paths and uses rebased paths when constructing compression archives. |
| apps/sim/app/api/workspaces/[id]/files/download/route.ts | Replaces duplicated ZIP sanitization and deduplication logic with the shared path builder. |
| apps/sim/lib/uploads/zip-entry-path.test.ts | Covers hierarchy preservation, rebasing, collisions, traversal sanitization, and fallback behavior. |
| apps/sim/tools/file/compress.ts | Updates the tool description to document preservation of workspace folder structure. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
S[Selected workspace files] --> M[Associate names with folder paths]
M --> R{Compress tool?}
R -->|Yes| C[Remove shared folder prefix]
R -->|No| K[Keep workspace-root-relative paths]
C --> Z[Sanitize path segments]
K --> Z
Z --> D[Suffix duplicate entry paths]
D --> A[Generate ZIP archive]
Reviews (1): Last reviewed commit: "fix(files): preserve nested folder struc..." | Re-trigger Greptile
Summary
file_compressflattened every zip entry to its leaf name, so asking Sim to package a folder produced an archive with all files at the root and(1)/(2)collision suffixes instead of the folder layoutlib/uploads/zip-entry-path.tsas the one place that builds unique, traversal-safe entry paths; the bulk download route reuses it instead of its own copy of the sanitizing and dedup logic./..Type of Change
Testing
Unit tests cover folder mirroring, same-name files across sibling folders, collision suffixing, common-ancestor rebasing (including segment-wise comparison so
ReportsandReports-2026are not treated as nested), and traversal/illegal-character stripping.bun run check:api-validation, typecheck, and thelib/uploads+tools/filesuites pass.Checklist