clientupdate: cleanup SPK and MSI downloads (#10085)

After we're done installing, clean up the temp files. This prevents temp
volumes from filling up on hosts that don't reboot often.

Fixes https://github.com/tailscale/tailscale/issues/10082

Signed-off-by: Andrew Lytvynov <awly@tailscale.com>
This commit is contained in:
Andrew Lytvynov 2023-11-02 12:21:42 -06:00 committed by GitHub
parent aa5af06165
commit 6c0ac8bef3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -284,6 +284,7 @@ func (up *Updater) updateSynology() error {
return nil
}
up.cleanupOldDownloads(filepath.Join(os.TempDir(), "tailscale-update*"))
// Download the SPK into a temporary directory.
spkDir, err := os.MkdirTemp("", "tailscale-update")
if err != nil {
@ -743,6 +744,7 @@ func (up *Updater) updateWindows() error {
if err := os.MkdirAll(msiDir, 0700); err != nil {
return err
}
up.cleanupOldDownloads(filepath.Join(msiDir, "*.msi"))
pkgsPath := fmt.Sprintf("%s/tailscale-setup-%s-%s.msi", up.track, ver, arch)
msiTarget := filepath.Join(msiDir, path.Base(pkgsPath))
if err := up.downloadURLToFile(pkgsPath, msiTarget); err != nil {
@ -831,6 +833,19 @@ func (up *Updater) installMSI(msi string) error {
return err
}
func (up *Updater) cleanupOldDownloads(glob string) {
matches, err := filepath.Glob(glob)
if err != nil {
up.Logf("cleaning up old downloads: %v", err)
return
}
for _, m := range matches {
if err := os.RemoveAll(m); err != nil {
up.Logf("cleaning up old downloads: %v", err)
}
}
}
func msiUUIDForVersion(ver string) string {
arch := runtime.GOARCH
if arch == "386" {