From 080dea252ea7966e4eed885dc737a667a85605c1 Mon Sep 17 00:00:00 2001 From: Fritz Duchardt Date: Fri, 10 Nov 2023 08:41:16 +0100 Subject: [PATCH 1/3] fix: lazy sync clears vendor directory on second sync Signed-off-by: Fritz Duchardt --- pkg/vendir/directory/directory.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/vendir/directory/directory.go b/pkg/vendir/directory/directory.go index d0ba0bb1..71163f4f 100644 --- a/pkg/vendir/directory/directory.go +++ b/pkg/vendir/directory/directory.go @@ -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("Copying existing content to staging '%s': %s", d.opts.Path, err) + } continue } From 81e84fc0d803fd2e6ec04ce37272e74ef43376c2 Mon Sep 17 00:00:00 2001 From: Fritz Duchardt Date: Fri, 10 Nov 2023 09:00:09 +0100 Subject: [PATCH 2/3] fix: e2e test Signed-off-by: Fritz Duchardt --- pkg/vendir/directory/directory.go | 2 +- test/e2e/example_lazy_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/vendir/directory/directory.go b/pkg/vendir/directory/directory.go index 71163f4f..8e1024a2 100644 --- a/pkg/vendir/directory/directory.go +++ b/pkg/vendir/directory/directory.go @@ -92,7 +92,7 @@ func (d *Directory) Sync(syncOpts SyncOpts) (ctlconf.LockDirectory, error) { // 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("Copying existing content to staging '%s': %s", d.opts.Path, err) + return lockConfig, fmt.Errorf("Lazy content missing. Run sync with --lazy=false to fix. '%s': %s", d.opts.Path, err) } continue } diff --git a/test/e2e/example_lazy_test.go b/test/e2e/example_lazy_test.go index e460a74f..90b73688 100644 --- a/test/e2e/example_lazy_test.go +++ b/test/e2e/example_lazy_test.go @@ -28,19 +28,19 @@ func TestExampleLazy(t *testing.T) { 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") From 39d52af91b9a1948e6a5306d06bb94e018cf22a5 Mon Sep 17 00:00:00 2001 From: Fritz Duchardt Date: Sun, 12 Nov 2023 11:38:19 +0100 Subject: [PATCH 3/3] fix: hardened lazy test Signed-off-by: Fritz Duchardt --- test/e2e/example_lazy_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/e2e/example_lazy_test.go b/test/e2e/example_lazy_test.go index 90b73688..4b478f53 100644 --- a/test/e2e/example_lazy_test.go +++ b/test/e2e/example_lazy_test.go @@ -22,6 +22,12 @@ 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")