From 89fad8b62bb47b95efa6ebc25980ddefe9a54397 Mon Sep 17 00:00:00 2001 From: Kevin Ruffin Date: Fri, 18 Feb 2022 12:47:13 -0500 Subject: [PATCH] No longer needs to download the checksum to get the file name. Does a HEAD request on the installer and uses the file name on the url path after redirects to name it. Also adds downloading the xml checksum. --- main.go | 72 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/main.go b/main.go index ee8bc7a..55ad1d9 100644 --- a/main.go +++ b/main.go @@ -35,7 +35,7 @@ func saveToken(tok *oauth2.Token, filename string) { if err != nil { log.Fatalf("Failed to marshal token: %v", err) } - err = ioutil.WriteFile(filename, j, 0664) + err = ioutil.WriteFile(filename, j, 0600) if err != nil { log.Fatalf("Failed to save token: %v", err) } @@ -215,36 +215,39 @@ func getDownloadLinks(p *Product) []*DownloadLinks { } func sanitizeName(name string) string { - s := strings.Replace(name, " ", "_", -1) - s = strings.Replace(s, "'", "", -1) - s = strings.Replace(s, "™", "", -1) + // s := strings.Replace(name, " ", "_", -1) + // s = strings.Replace(s, "'", "", -1) + // s = strings.Replace(s, "™", "", -1) + re := regexp.MustCompile("[^0-1a-zA-Z.-_]+") + s := name + s = re.ReplaceAllString(s, "_") return s } -func writeChecksumIfNeeded(dl *DownloadLinks, folder string) { - // TODO: reuse an existing checksum file somehow - res, err := client.Get(dl.Checksum) - if err != nil { - log.Fatalf("Failed to get file checksum info: %v", err) - } - defer res.Body.Close() - body, err := ioutil.ReadAll(res.Body) - if err != nil { - log.Fatalf("Failed to parse file checksum body: %v", err) - } +// func writeChecksumIfNeeded(dl *DownloadLinks, folder string) { +// // TODO: reuse an existing checksum file somehow +// res, err := client.Get(dl.Checksum) +// if err != nil { +// log.Fatalf("Failed to get file checksum info (%s): %v", dl.Checksum, err) +// } +// defer res.Body.Close() +// body, err := ioutil.ReadAll(res.Body) +// if err != nil { +// log.Fatalf("Failed to parse file checksum body (%s): %v", dl.Checksum, err) +// } - re := regexp.MustCompile(`