diff --git a/pkg/vendir/directory/directory.go b/pkg/vendir/directory/directory.go index 4477337f..bf274272 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("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..fe969310 100644 --- a/test/e2e/example_lazy_test.go +++ b/test/e2e/example_lazy_test.go @@ -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")