Skip to main content
← Back to list
01Issue
BugClosedSwamp Club
AssigneesNone

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.tsbundles/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:

  • detectConflicts checks: .swamp/bundles/netpol.js (wrong — flattened by basename)
  • copyDir installs to: .swamp/bundles/k8s/netpol.js (correct — preserves structure)

This is a leftover from before #509 when bundles were flat.

User impact

  1. 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.js instead. The user doesn't get warned before files are overwritten.

  2. 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), detectConflicts finds them and warns about them — even though copyDir won't touch those paths.

  3. Confusing path mismatch between extension rm and extension pull. After extension rm deletes files at the correct nested paths (e.g., .swamp/bundles/k8s/netpol.js), a subsequent extension pull shows 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.

02Bog Flow
OPENTRIAGEDIN PROGRESSCLOSED

Closed

No activity in this phase yet.

03Sludge Pulse

Sign in to post a ripple.