-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes and tests for ingredientcall end-to-end #3575
Merged
+4,437
−194
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
4eb18a8
Add doublestar support for globbing and fix inconsistencies in hash c…
Naatan b1af420
Add CommonParentPath function
Naatan 8472bd9
Add GetwdUnsafe
Naatan bb3304b
`artifacts dl` should fail if artifact status is not successful
Naatan 40b99ef
Add structured output for `artifacts dl`
Naatan 9086810
model.BuildPlannerVersionConstraintsToString > model.VersionRequireme…
Naatan ad3aa7b
Added sliceutils.Cast
Naatan ba97d3c
Automatically set Path according to name/namespace
Naatan a0f86f5
Fix hashglobs variable notation
Naatan 1cb3d36
Fix org namespace values
Naatan da63e3d
Missing import
Naatan 312771b
Added archiver package
Naatan 908b685
Buildscript external values support ints and slices
Naatan 209ced7
Fix successful request throwing error
Naatan 57c7997
Various fixes to ingredientcall during end to end testing
Naatan 18545b2
Test ingredientcall
Naatan b810194
Add comments
Naatan 1273d0b
Merge remote-tracking branch 'origin/version/0-47-0-RC1' into DX-3105
Naatan 104a522
Compatibility fixes
Naatan 32bda03
Disable test for now
Naatan 69236e0
Drop old test
Naatan 71d8071
Remove unused mutex
Naatan dae0380
Enable ingredientcall integration test
Naatan 4546624
More test cases and support windows paths
Naatan 7e2ba42
Clean up parent node logic
Naatan f4b3170
Fix unit test failures
Naatan fa24657
Update hashes in test
Naatan d0d975c
Add log info
Naatan 96baec2
Also handle requirements in solve_legacy
Naatan 332823c
Add debug info
Naatan ba3e9a5
Ensure function call hash is consistently calculated
Naatan 774120b
Increase solving timeout
Naatan 864af32
Add debug info
Naatan 445dbe4
Give windows more time
Naatan 67c2110
Ensure filepaths are using forward slash
Naatan 6c38c9e
Drop redundant calls
Naatan f380d3d
Use relative paths for archives
Naatan c1fc008
Add comment around absolute paths
Naatan c20a2fb
Ensure we use the correct atTime when ingredient was cached at a newe…
Naatan 543089c
Fix time comparison issues with buildscripts due to inconsistent time…
Naatan bceec93
Fix test
Naatan 5d70309
Fix unit test
Naatan 41062d2
Fix TestRealWorld
Naatan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import ( | |
"time" | ||
|
||
"github.com/ActiveState/cli/internal/errs" | ||
"github.com/ActiveState/cli/internal/rtutils" | ||
"github.com/bmatcuk/doublestar/v4" | ||
"github.com/cespare/xxhash" | ||
"github.com/patrickmn/go-cache" | ||
) | ||
|
@@ -36,64 +36,75 @@ func NewFileHasher() *FileHasher { | |
} | ||
|
||
func (fh *FileHasher) HashFiles(wd string, globs []string) (_ string, _ []hashedFile, rerr error) { | ||
sort.Strings(globs) // ensure consistent ordering | ||
fs := os.DirFS(wd) | ||
hashedFiles := []hashedFile{} | ||
hasher := xxhash.New() | ||
hashes := []string{} | ||
for _, glob := range globs { | ||
files, err := filepath.Glob(glob) | ||
files, err := doublestar.Glob(fs, glob) | ||
if err != nil { | ||
return "", nil, errs.Wrap(err, "Could not match glob: %s", glob) | ||
} | ||
sort.Strings(files) // ensure consistent ordering | ||
for _, f := range files { | ||
if !filepath.IsAbs(f) { | ||
af, err := filepath.Abs(filepath.Join(wd, f)) | ||
if err != nil { | ||
return "", nil, errs.Wrap(err, "Could not get absolute path for file: %s", f) | ||
} | ||
f = af | ||
for _, relativePath := range files { | ||
absolutePath, err := filepath.Abs(filepath.Join(wd, relativePath)) | ||
if err != nil { | ||
return "", nil, errs.Wrap(err, "Could not get absolute path for file: %s", relativePath) | ||
} | ||
file, err := os.Open(f) | ||
fileInfo, err := os.Stat(absolutePath) | ||
if err != nil { | ||
return "", nil, errs.Wrap(err, "Could not open file: %s", file.Name()) | ||
return "", nil, errs.Wrap(err, "Could not stat file: %s", absolutePath) | ||
} | ||
defer rtutils.Closer(file.Close, &rerr) | ||
|
||
fileInfo, err := file.Stat() | ||
if err != nil { | ||
return "", nil, errs.Wrap(err, "Could not stat file: %s", file.Name()) | ||
if fileInfo.IsDir() { | ||
continue | ||
} | ||
|
||
var hash string | ||
cachedHash, ok := fh.cache.Get(cacheKey(file.Name(), fileInfo.ModTime())) | ||
cachedHash, ok := fh.cache.Get(cacheKey(fileInfo.Name(), fileInfo.ModTime())) | ||
if ok { | ||
hash, ok = cachedHash.(string) | ||
if !ok { | ||
return "", nil, errs.New("Could not convert cache value to string") | ||
} | ||
} else { | ||
fileHasher := xxhash.New() | ||
// include filepath in hash, because moving files should affect the hash | ||
fmt.Fprintf(fileHasher, "%016x", relativePath) | ||
file, err := os.Open(absolutePath) | ||
if err != nil { | ||
return "", nil, errs.Wrap(err, "Could not open file: %s", absolutePath) | ||
} | ||
defer file.Close() | ||
if _, err := io.Copy(fileHasher, file); err != nil { | ||
return "", nil, errs.Wrap(err, "Could not hash file: %s", file.Name()) | ||
return "", nil, errs.Wrap(err, "Could not hash file: %s", fileInfo.Name()) | ||
} | ||
|
||
hash = fmt.Sprintf("%016x", fileHasher.Sum64()) | ||
} | ||
|
||
fh.cache.Set(cacheKey(file.Name(), fileInfo.ModTime()), hash, cache.NoExpiration) | ||
fh.cache.Set(cacheKey(fileInfo.Name(), fileInfo.ModTime()), hash, cache.NoExpiration) | ||
|
||
hashes = append(hashes, hash) | ||
hashedFiles = append(hashedFiles, hashedFile{ | ||
Pattern: glob, | ||
Path: file.Name(), | ||
Path: relativePath, | ||
Hash: hash, | ||
}) | ||
|
||
// Incorporate the individual file hash into the overall hash in hex format | ||
fmt.Fprintf(hasher, "%016x", hash) | ||
} | ||
} | ||
|
||
return fmt.Sprintf("%016x", hasher.Sum64()), hashedFiles, nil | ||
if hashedFiles == nil { | ||
return "", nil, nil | ||
} | ||
|
||
// Ensure the overall hash is consistently calculated | ||
sort.Slice(hashedFiles, func(i, j int) bool { return hashedFiles[i].Path < hashedFiles[j].Path }) | ||
h := xxhash.New() | ||
for _, f := range hashedFiles { | ||
fmt.Fprintf(h, "%016x", f.Hash) | ||
} | ||
Comment on lines
+100
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed it to calculate the overall hash based on a sorted slice of all the individual hashes for all files. This way we get the same hash even if the files are sorted differently, or more importantly (what I ran into); if the patterns are different but produce the same result. |
||
|
||
return fmt.Sprintf("%016x", h.Sum64()), hashedFiles, nil | ||
} | ||
|
||
func cacheKey(file string, modTime time.Time) string { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filepath.Glob()
does not support double star globs (ie.*/**
) nor specifying the working directory. This library addresses both limitations.