Skip to content

Commit

Permalink
Merge pull request #326 from carvel-dev/lazy-sync-fix-36.x
Browse files Browse the repository at this point in the history
fix: lazy sync clears vendor directory on second sync in line 0.36.x
  • Loading branch information
kumaritanushree authored Dec 5, 2023
2 parents 6f81673 + 39d52af commit 97d9417
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pkg/vendir/directory/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ func (d *Directory) Sync(syncOpts SyncOpts) (ctlconf.LockDirectory, error) {
if skipFetching {
d.ui.PrintLinef("Skipping fetch: %s + %s (flagged as lazy, config has not changed since last sync)", d.opts.Path, contents.Path)
lockConfig.Contents = append(lockConfig.Contents, oldLockContents)
// copy previously fetched contents to staging dir
err = dircopy.Copy(filepath.Join(d.opts.Path, contents.Path), stagingDstPath)
if err != nil {
return lockConfig, fmt.Errorf("Lazy content missing. Run sync with --lazy=false to fix. '%s': %s", d.opts.Path, err)
}
continue
}

Expand Down
14 changes: 10 additions & 4 deletions test/e2e/example_lazy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,31 @@ func TestExampleLazy(t *testing.T) {
// run lazy sync
_, err := vendir.RunWithOpts([]string{"sync", "-f=vendir-lazy.yml"}, RunOpts{Dir: path, Env: osEnv})
require.NoError(t, err)
require.DirExists(t, path+"/vendor/dir")

// rerun lazy sync for good measure
_, err = vendir.RunWithOpts([]string{"sync", "-f=vendir-lazy.yml"}, RunOpts{Dir: path, Env: osEnv})
require.NoError(t, err)
require.DirExists(t, path+"/vendor/dir")

// check that the lock file has config digest
lockConf, err := ctlconf.NewLockConfigFromFile(path + "/vendir.lock.yml")
require.NoError(t, err)
require.NotEmpty(t, lockConf.Directories[0].Contents[0].ConfigDigest, "Expected Config Digest in Lock File")

// remove some directory
err = os.RemoveAll(path + "/vendor/dir")
// remove file from synced dir
err = os.Remove(path + "/vendor/dir/some-file.txt")
require.NoError(t, err)

// resync lazily, should not sync. Removed dir has not been reinstated
_, err = vendir.RunWithOpts([]string{"sync", "-f=vendir-lazy.yml"}, RunOpts{Dir: path, Env: osEnv})
require.NoError(t, err)
require.NoDirExists(t, path+"/vendor/dir")
require.NoFileExists(t, path+"/vendor/dir/some-file.txt")

// resync with lazy override, should not affect config digest
_, err = vendir.RunWithOpts([]string{"sync", "--lazy=false", "-f=vendir-lazy.yml"}, RunOpts{Dir: path, Env: osEnv})
require.NoError(t, err)
require.DirExists(t, path+"/vendor/dir")
require.FileExists(t, path+"/vendor/dir/some-file.txt")

// content digest is kept during lazy sync override
lockConf, err = ctlconf.NewLockConfigFromFile(path + "/vendir.lock.yml")
Expand Down

0 comments on commit 97d9417

Please sign in to comment.