Accept equivalent checkout paths in build receipts
This commit is contained in:
@@ -122,15 +122,14 @@ func LoadBuildReceipt(path string) (BuildReceipt, error) {
|
||||
}
|
||||
return BuildReceipt{}, err
|
||||
}
|
||||
if filepath.Clean(receipt.OutputDir) != filepath.Dir(resolvedPath) {
|
||||
if !sameDirectory(receipt.OutputDir, filepath.Dir(resolvedPath)) {
|
||||
return BuildReceipt{}, errors.New("build receipt output directory does not match its location")
|
||||
}
|
||||
return receipt, nil
|
||||
}
|
||||
|
||||
func (receipt BuildReceipt) MatchesBuild(repositoryDir, commit, version string, settings BuildSettings) bool {
|
||||
resolvedRepo, err := filepath.Abs(repositoryDir)
|
||||
if err != nil || filepath.Clean(receipt.RepositoryDir) != filepath.Clean(resolvedRepo) {
|
||||
if !sameDirectory(receipt.RepositoryDir, repositoryDir) {
|
||||
return false
|
||||
}
|
||||
if receipt.CandidateCommit != commit || receipt.Version != version {
|
||||
@@ -149,6 +148,15 @@ func (receipt BuildReceipt) MatchesBuild(repositoryDir, commit, version string,
|
||||
return true
|
||||
}
|
||||
|
||||
func sameDirectory(first, second string) bool {
|
||||
firstInfo, err := os.Stat(first)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
secondInfo, err := os.Stat(second)
|
||||
return err == nil && os.SameFile(firstInfo, secondInfo)
|
||||
}
|
||||
|
||||
func validateBuildReceipt(receipt BuildReceipt) error {
|
||||
if receipt.SchemaVersion != BuildReceiptSchemaVersion {
|
||||
return fmt.Errorf("unsupported or missing build receipt schema version %d", receipt.SchemaVersion)
|
||||
|
||||
Reference in New Issue
Block a user