Partial fix: fix empty software title when metadata doesn't find one (#19047)

#19041 (it falls back on filename)

# Checklist for submitter

- [x] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
This commit is contained in:
Martin Angers 2024-05-15 17:27:04 -04:00 committed by GitHub
parent 01898fd176
commit 62adb46a36
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -321,6 +321,10 @@ func (svc *Service) addMetadataToSoftwarePayload(ctx context.Context, payload *f
}
return "", ctxerr.Wrap(ctx, err, "extracting metadata from installer")
}
if title == "" {
// use the filename if no title from metadata
title = payload.Filename
}
payload.Title = title
payload.Version = vers
payload.StorageID = hex.EncodeToString(hash)
@ -445,11 +449,7 @@ func (svc *Service) BatchSetSoftwareInstallers(ctx context.Context, tmName strin
InstallerFile: bytes.NewReader(bodyBytes),
}
ext, err := svc.addMetadataToSoftwarePayload(ctx, installer)
if err != nil {
return err
}
// set the filename before adding metadata, as it is used as fallback
var filename string
cdh, ok := resp.Header["Content-Disposition"]
if ok && len(cdh) > 0 {
@ -458,7 +458,15 @@ func (svc *Service) BatchSetSoftwareInstallers(ctx context.Context, tmName strin
filename = params["filename"]
}
}
// if it fails, try to extract it from the URL
installer.Filename = filename
ext, err := svc.addMetadataToSoftwarePayload(ctx, installer)
if err != nil {
return err
}
// if filename was empty, try to extract it from the URL with the
// now-known extension
if filename == "" {
filename = file.ExtractFilenameFromURLPath(p.URL, ext)
}
@ -467,6 +475,9 @@ func (svc *Service) BatchSetSoftwareInstallers(ctx context.Context, tmName strin
filename = fmt.Sprintf("package.%s", ext)
}
installer.Filename = filename
if installer.Title == "" {
installer.Title = filename
}
installers[i] = installer