Skip to content

fix(sync): mirrorRemote and preferRemote overwrite newer local files on initial sync - #3370

Draft
pingxin403 wants to merge 1 commit into
devspace-sh:mainfrom
pingxin403:fix/mirror-remote-overwrites-newer-local
Draft

pingxin403 wants to merge 1 commit into
devspace-sh:mainfrom
pingxin403:fix/mirror-remote-overwrites-newer-local

Conversation

@pingxin403

Copy link
Copy Markdown

Problem

With initialSync: mirrorRemote (or preferRemote), the CLI selected the container file for a conflicting path, but the download was skipped when the local copy had a newer mtime:

Downstream - Don't override /conflict.txt because file has newer mTime timestamp

mirrorRemote still deletes local-only files, leaving a partially mirrored local directory.

Documented semantics

From docs/pages/configuration/dev/connections/file-sync.mdx (Initial Sync Strategy):

strategy both sides exist and differ
mirrorLocal keep the local file, upload it
preferLocal keep the local file, upload it
mirrorRemote replace the local file with the container file regardless of mtime, delete local-only files
preferRemote replace the local file with the container file regardless of mtime, keep local-only files
preferNewest newer mtime wins
keepAll leave both files untouched

Root cause

downstream.applyChanges(changes, force) threads force into deletes only. The Unarchiver is constructed once with forceOverride=false (downstream.go:75), so the mtime guard in tar.go skips extraction even when the strategy already chose downloadAction. The initial sync's force argument never reached the extraction step.

Fix

  • initial.go: pass force=true for the initial download when the strategy is mirrorRemote or preferRemote (remote preference means the container file wins, independent of mtime).
  • downstream.go: thread that force into initDownload and set unarchiver.forceOverride for the download. Later (non-initial) downloads still run with force=false, so newer local edits remain protected.
  • Delete behavior of the other modes is unchanged.

Tests

New table test TestInitialSyncConflict runs the real downstream/upstream helper servers over pipes (same harness as TestInitialSync, whose server setup was extracted into startTestSync). It covers all six strategies times both mtime orderings, and also asserts the local-only / remote-only delete semantics of mirrorRemote and mirrorLocal.

Validation:

  • go test ./pkg/devspace/sync/ -count=1 — 17 passed
  • go build ./... — passes
  • gofmt -l pkg/devspace/sync/ — clean

Negative check: with the source change reverted and the new test kept, TestInitialSyncConflict/mirrorRemote/local_newer and TestInitialSyncConflict/preferRemote/local_newer fail on the conflict content while all other cases pass. The fix was restored afterwards.

Fixes #3351

…tial sync

During the initial sync, the remote preference strategies (mirrorRemote,
preferRemote) selected the container file in the conflict calculation, but
the downstream unarchiver still skipped extraction when the local file had
a newer mtime because its forceOverride flag was always false. mirrorRemote
also deletes local-only files, so this left a partially mirrored directory.

Thread the initial sync's force flag into the unarchiver and pass force=true
for the initial download of both remote preference strategies. mirrorLocal,
preferLocal, preferNewest and keepAll keep protecting local files as before,
and later (non-initial) downloads still respect newer local edits.

Fixes devspace-sh#3351

Signed-off-by: pingxin403 <26605276+pingxin403@users.noreply.github.com>
@netlify

netlify Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for devspace-docs canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit aea5cd3
🔍 Latest deploy log https://app.netlify.com/projects/devspace-docs/deploys/6b142d0308c3df372da47c95

This branch has not been deployed

No deployments
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.

bug(sync): mirrorRemote and preferRemote skip newer local files during initial sync

1 participant