Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lazy sync clears vendor directory on second sync in line 0.37.x #327

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -23,25 +23,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
Loading