Repository navigation
fix(sync): mirrorRemote and preferRemote overwrite newer local files on initial sync - #3370
Draft
pingxin403 wants to merge 1 commit into
Draft
pingxin403 wants to merge 1 commit into
pingxin403 wants to merge 1 commit into
Conversation
…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>
✅ Deploy Preview for devspace-docs canceled.Built without sensitive environment variables
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With
initialSync: mirrorRemote(orpreferRemote), the CLI selected the container file for a conflicting path, but the download was skipped when the local copy had a newer mtime:mirrorRemotestill deletes local-only files, leaving a partially mirrored local directory.Documented semantics
From
docs/pages/configuration/dev/connections/file-sync.mdx(Initial Sync Strategy):mirrorLocalpreferLocalmirrorRemotepreferRemotepreferNewestkeepAllRoot cause
downstream.applyChanges(changes, force)threadsforceinto deletes only. TheUnarchiveris constructed once withforceOverride=false(downstream.go:75), so the mtime guard intar.goskips extraction even when the strategy already chosedownloadAction. The initial sync'sforceargument never reached the extraction step.Fix
initial.go: passforce=truefor the initial download when the strategy ismirrorRemoteorpreferRemote(remote preference means the container file wins, independent of mtime).downstream.go: thread thatforceintoinitDownloadand setunarchiver.forceOverridefor the download. Later (non-initial) downloads still run withforce=false, so newer local edits remain protected.Tests
New table test
TestInitialSyncConflictruns the real downstream/upstream helper servers over pipes (same harness asTestInitialSync, whose server setup was extracted intostartTestSync). It covers all six strategies times both mtime orderings, and also asserts the local-only / remote-only delete semantics ofmirrorRemoteandmirrorLocal.Validation:
go test ./pkg/devspace/sync/ -count=1— 17 passedgo build ./...— passesgofmt -l pkg/devspace/sync/— cleanNegative check: with the source change reverted and the new test kept,
TestInitialSyncConflict/mirrorRemote/local_newerandTestInitialSyncConflict/preferRemote/local_newerfail on the conflict content while all other cases pass. The fix was restored afterwards.Fixes #3351