fix: detectConflicts uses basename for bundles, missing nested directory structure
Opened by swampadmin · 1/1/2025
Problem
Commit c637ddd (#509) fixed extension push to preserve nested directory structure for bundles (e.g., aws/ec2/instance.ts → bundles/aws/ec2/instance.js). The pull side's copyDir already handled nested paths correctly. However, detectConflicts in extension_pull.ts (line 369) was not updated — it still uses basename(file), which strips all directory info and checks for conflicts at flat paths.
Root cause
In detectConflicts, the bundles section uses:
const destPath = join(bundlesDir, basename(file));But copyDir (which actually installs the bundles) preserves directory structure. For a bundle archived at bundles/k8s/netpol.js:
detectConflictschecks:.swamp/bundles/netpol.js(wrong — flattened bybasename)copyDirinstalls to:.swamp/bundles/k8s/netpol.js(correct — preserves structure)
This is a leftover from before #509 when bundles were flat.
User impact
Real conflicts are missed. If a file already exists at
.swamp/bundles/k8s/netpol.js, the conflict check won't find it because it looks at.swamp/bundles/netpol.jsinstead. The user doesn't get warned before files are overwritten.False conflict warnings from stale files. If a user has old flat-path files from a pre-#509 install (e.g.,
.swamp/bundles/netpol.js),detectConflictsfinds them and warns about them — even thoughcopyDirwon't touch those paths.Confusing path mismatch between
extension rmandextension pull. Afterextension rmdeletes files at the correct nested paths (e.g.,.swamp/bundles/k8s/netpol.js), a subsequentextension pullshows conflict warnings at different flat paths (e.g.,.swamp/bundles/netpol.js). This makes it appear files weren't actually deleted.
Fix
Replace basename(file) with relative(bundlesSrc, file) on line 369, matching how models (line 350) and additional files (line 378) already work in the same function:
const relPath = relative(bundlesSrc, file);
const destPath = join(bundlesDir, relPath);This is a one-line fix (plus adding the relPath variable) that makes conflict detection consistent with installation.
Closed
No activity in this phase yet.
Sign in to post a ripple.