diff options
| author | Colin Cross <ccross@android.com> | 2021-01-21 13:47:59 -0800 |
|---|---|---|
| committer | Colin Cross <ccross@android.com> | 2021-01-21 13:47:59 -0800 |
| commit | a64ca94c0d9f5c56ba8ad4a70fba2d6b0a8df8f1 (patch) | |
| tree | 5f34b06fc6c5acf44b9d735b2a683118a38b6189 /glob.go | |
| parent | 4604a81721007a79e6b4fc5ed4a78ebde95d6cc0 (diff) | |
| download | platform_build_blueprint-a64ca94c0d9f5c56ba8ad4a70fba2d6b0a8df8f1.tar.gz platform_build_blueprint-a64ca94c0d9f5c56ba8ad4a70fba2d6b0a8df8f1.tar.bz2 platform_build_blueprint-a64ca94c0d9f5c56ba8ad4a70fba2d6b0a8df8f1.zip | |
Return a copy of glob lists
Callers to glob methods may do in-place modifications on the returned
list of globs, return a copy instead of the cached value.
Test: m nothing && m nothing
Change-Id: Ic9140d1e1900e8724ba0a484f27786e5c15dea90
Diffstat (limited to 'glob.go')
| -rw-r--r-- | glob.go | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -57,7 +57,8 @@ func (c *Context) glob(pattern string, excludes []string) ([]string, error) { if exists { // Glob has already been done, double check it is identical verifyGlob(fileName, pattern, excludes, g) - return g.Files, nil + // Return a copy so that modifications don't affect the cached value. + return append([]string(nil), g.Files...), nil } // Get a globbed file list @@ -76,10 +77,12 @@ func (c *Context) glob(pattern string, excludes []string) ([]string, error) { // Getting the list raced with another goroutine, throw away the results and use theirs if exists { verifyGlob(fileName, pattern, excludes, g) - return g.Files, nil + // Return a copy so that modifications don't affect the cached value. + return append([]string(nil), g.Files...), nil } - return files, nil + // Return a copy so that modifications don't affect the cached value. + return append([]string(nil), files...), nil } func (c *Context) Globs() []GlobPath { |
