diff --git a/files/files_test.go b/files/files_test.go index 21662673..06dceeec 100644 --- a/files/files_test.go +++ b/files/files_test.go @@ -370,3 +370,15 @@ func TestGlobbingFilesWithDifferentSizesWithFileInfo(t *testing.T) { t.Fatal("test FileInfos have the same size, expected different") } } + +func TestDestEndsWithSlash(t *testing.T) { + result, err := files.ExpandContentGlobs(files.Contents{ + { + Source: "./testdata/globtest/a.txt", + Destination: "./foo/", + }, + }, false) + require.NoError(t, err) + require.Len(t, result, 1) + require.Equal(t, "foo/a.txt", result[0].Destination) +} diff --git a/internal/glob/glob.go b/internal/glob/glob.go index e225147a..e6fca628 100644 --- a/internal/glob/glob.go +++ b/internal/glob/glob.go @@ -92,6 +92,11 @@ func Glob(pattern, dst string, ignoreMatchers bool) (map[string]string, error) { continue } + if strings.HasSuffix(dst, "/") { + files[src] = filepath.Join(dst, filepath.Base(src)) + continue + } + relpath, err := filepath.Rel(prefix, src) if err != nil { // since prefix is a prefix of src a relative path should always be found diff --git a/internal/glob/glob_test.go b/internal/glob/glob_test.go index 721b3c88..d21daabc 100644 --- a/internal/glob/glob_test.go +++ b/internal/glob/glob_test.go @@ -47,6 +47,13 @@ func TestGlob(t *testing.T) { require.Equal(t, "/foo/bar/dir_c/test_c.txt", files["testdata/dir_a/dir_c/test_c.txt"]) }) + t.Run("dst is a dir", func(t *testing.T) { + files, err := Glob("./testdata/dir_a/dir_b/test_b.txt", "/foo/bar/", false) + require.NoError(t, err) + require.Len(t, files, 1) + require.Equal(t, "/foo/bar/test_b.txt", files["testdata/dir_a/dir_b/test_b.txt"]) + }) + t.Run("to parent", func(t *testing.T) { pattern := "../../testdata/fake" abs, err := filepath.Abs(pattern)