From d7f93e9063103ee6eb25c91b8dd43d1a0feedec4 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 4477337f..c2dd8a76 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 a025bd83335bf720f434688e96ddc3dca24b095a 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 c2dd8a76..bf274272 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 b3263f1f..b3e736c8 100644 --- a/test/e2e/example_lazy_test.go +++ b/test/e2e/example_lazy_test.go @@ -29,19 +29,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 51b11581396fba44126d41bcf758737760d9f9ba 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 b3e736c8..fe969310 100644 --- a/test/e2e/example_lazy_test.go +++ b/test/e2e/example_lazy_test.go @@ -23,6 +23,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")