Skip to content

Commit

Permalink
Fix corner case where WithDirectory included wrong contents. (dagger#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sipsma committed Jul 14, 2023
1 parent 7369279 commit 4842448
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ func mergeStates(input mergeStateInput) llb.State {
copyInfo.ChownOpt == nil &&
len(copyInfo.ExcludePatterns) == 0 &&
len(copyInfo.IncludePatterns) == 0 &&
input.DestDir == input.SrcDir &&
input.DestDir == "/" &&
input.SrcDir == "/" &&
// TODO:(sipsma) we could support direct merge-op with individual files if we can verify
// there are no other files in the dir, but doing so by just calling ReadDir would result
// in unlazying the inputs, which defeats some of the performance benefits of merge-op.
Expand Down
22 changes: 22 additions & 0 deletions core/integration/directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,28 @@ func TestDirectoryDirectMerge(t *testing.T) {
}
}

func TestDirectoryFallbackMerge(t *testing.T) {
t.Parallel()
ctx := context.Background()
c, err := dagger.Connect(ctx)
require.NoError(t, err)
defer c.Close()

t.Run("dest path same as src selector", func(t *testing.T) {
// corner case where we need to use the fallback rather than direct merge
srcDir := c.Directory().
WithNewFile("/toplevel", "").
WithNewFile("/dir/lowerlevel", "")
srcSubdir := srcDir.Directory("/dir")

mergedDir := c.Directory().WithDirectory("/dir", srcSubdir)
_, err = mergedDir.File("/dir/lowerlevel").Contents(ctx)
require.NoError(t, err)
_, err = mergedDir.File("/toplevel").Contents(ctx)
require.Error(t, err)
})
}

func TestDirectorySync(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 4842448

Please sign in to comment.