mirror of https://github.com/databricks/cli.git
replace findMetadataAndRecord with more general findFiles
This commit is contained in:
parent
b9eeecd5a1
commit
d7daebfba0
|
@ -23,22 +23,24 @@ const (
|
||||||
nameKey = "Name:"
|
nameKey = "Name:"
|
||||||
)
|
)
|
||||||
|
|
||||||
func findMetadataAndRecord(r *zip.ReadCloser, oldDistInfoPrefix string) (metadataFile, recordFile *zip.File) {
|
func findFiles(r *zip.ReadCloser, files ...string) []*zip.File {
|
||||||
|
found := 0
|
||||||
|
result := make([]*zip.File, len(files))
|
||||||
for _, f := range r.File {
|
for _, f := range r.File {
|
||||||
if metadataFile == nil && f.Name == oldDistInfoPrefix+"METADATA" {
|
for ind, prev := range result {
|
||||||
metadataFile = f
|
if prev != nil {
|
||||||
}
|
continue
|
||||||
|
}
|
||||||
if recordFile == nil && f.Name == oldDistInfoPrefix+"RECORD" {
|
if f.Name == files[ind] {
|
||||||
recordFile = f
|
result[ind] = f
|
||||||
|
found += 1
|
||||||
if metadataFile != nil {
|
if found >= len(files) {
|
||||||
break
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return result
|
||||||
return metadataFile, recordFile
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// patchMetadata returns new METADATA content with an updated "Version:" field and validates that previous version matches oldVersion
|
// patchMetadata returns new METADATA content with an updated "Version:" field and validates that previous version matches oldVersion
|
||||||
|
@ -141,13 +143,15 @@ func PatchWheel(ctx context.Context, path, outputDir string) (string, error) {
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
|
|
||||||
oldDistInfoPrefix := wheelInfo.Distribution + "-" + wheelInfo.Version + ".dist-info/"
|
oldDistInfoPrefix := wheelInfo.Distribution + "-" + wheelInfo.Version + ".dist-info/"
|
||||||
metadataFile, recordFile := findMetadataAndRecord(r, oldDistInfoPrefix)
|
files := findFiles(r, oldDistInfoPrefix+"METADATA", oldDistInfoPrefix+"RECORD")
|
||||||
|
metadataFile, recordFile := files[0], files[1]
|
||||||
|
|
||||||
if metadataFile == nil {
|
if metadataFile == nil {
|
||||||
return "", fmt.Errorf("wheel %s missing METADATA file", path)
|
return "", fmt.Errorf("wheel %s missing %sMETADATA", path, oldDistInfoPrefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
if recordFile == nil {
|
if recordFile == nil {
|
||||||
return "", fmt.Errorf("wheel %s missing RECORD file", path)
|
return "", fmt.Errorf("wheel %s missing %sRECORD file", path, oldDistInfoPrefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
metadataReader, err := metadataFile.Open()
|
metadataReader, err := metadataFile.Open()
|
||||||
|
|
Loading…
Reference in New Issue