mirror of https://github.com/databricks/cli.git
remove glob matching in readMetadataAndRecord, rename to findMetadataAndRecord
This commit is contained in:
parent
138ced54eb
commit
ca55524f94
|
@ -11,7 +11,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -22,28 +21,13 @@ const (
|
|||
nameKey = "Name:"
|
||||
)
|
||||
|
||||
// readMetadataAndRecord scans the zip file for files matching the patterns
|
||||
// "*.dist-info/METADATA" and "*.dist-info/RECORD". If multiple are found, it picks
|
||||
// the first one encountered.
|
||||
func readMetadataAndRecord(r *zip.ReadCloser) (metadataFile, recordFile *zip.File, oldDistInfoPrefix string) {
|
||||
func findMetadataAndRecord(r *zip.ReadCloser, oldDistInfoPrefix string) (metadataFile, recordFile *zip.File) {
|
||||
for _, f := range r.File {
|
||||
if metadataFile == nil {
|
||||
matched, _ := path.Match("*.dist-info/METADATA", f.Name)
|
||||
if matched {
|
||||
if metadataFile == nil && f.Name == oldDistInfoPrefix+"METADATA" {
|
||||
metadataFile = f
|
||||
oldDistInfoPrefix = path.Dir(f.Name) + "/"
|
||||
|
||||
if recordFile != nil {
|
||||
break
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if recordFile == nil {
|
||||
matched, _ := path.Match("*.dist-info/RECORD", f.Name)
|
||||
if matched {
|
||||
if recordFile == nil && f.Name == oldDistInfoPrefix+"RECORD" {
|
||||
recordFile = f
|
||||
|
||||
if metadataFile != nil {
|
||||
|
@ -51,9 +35,8 @@ func readMetadataAndRecord(r *zip.ReadCloser) (metadataFile, recordFile *zip.Fil
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return metadataFile, recordFile, oldDistInfoPrefix
|
||||
return metadataFile, recordFile
|
||||
}
|
||||
|
||||
// patchMetadata returns new METADATA content with an updated "Version:" field and validates that previous version matches oldVersion
|
||||
|
@ -155,7 +138,8 @@ func PatchWheel(ctx context.Context, path, outputDir string) (string, error) {
|
|||
}
|
||||
defer r.Close()
|
||||
|
||||
metadataFile, recordFile, oldDistInfoPrefix := readMetadataAndRecord(r)
|
||||
oldDistInfoPrefix := wheelInfo.Distribution + "-" + wheelInfo.Version + ".dist-info/"
|
||||
metadataFile, recordFile := findMetadataAndRecord(r, oldDistInfoPrefix)
|
||||
if metadataFile == nil {
|
||||
return "", fmt.Errorf("wheel %s missing METADATA file", path)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue