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>
pull/10091/head
Andrew Lytvynov 1 year ago committed by GitHub
parent aa5af06165
commit 6c0ac8bef3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -284,6 +284,7 @@ func (up *Updater) updateSynology() error {
return nil return nil
} }
up.cleanupOldDownloads(filepath.Join(os.TempDir(), "tailscale-update*"))
// Download the SPK into a temporary directory. // Download the SPK into a temporary directory.
spkDir, err := os.MkdirTemp("", "tailscale-update") spkDir, err := os.MkdirTemp("", "tailscale-update")
if err != nil { if err != nil {
@ -743,6 +744,7 @@ you can run the command prompt as Administrator one of these ways:
if err := os.MkdirAll(msiDir, 0700); err != nil { if err := os.MkdirAll(msiDir, 0700); err != nil {
return err return err
} }
up.cleanupOldDownloads(filepath.Join(msiDir, "*.msi"))
pkgsPath := fmt.Sprintf("%s/tailscale-setup-%s-%s.msi", up.track, ver, arch) pkgsPath := fmt.Sprintf("%s/tailscale-setup-%s-%s.msi", up.track, ver, arch)
msiTarget := filepath.Join(msiDir, path.Base(pkgsPath)) msiTarget := filepath.Join(msiDir, path.Base(pkgsPath))
if err := up.downloadURLToFile(pkgsPath, msiTarget); err != nil { if err := up.downloadURLToFile(pkgsPath, msiTarget); err != nil {
@ -831,6 +833,19 @@ func (up *Updater) installMSI(msi string) error {
return err 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 { func msiUUIDForVersion(ver string) string {
arch := runtime.GOARCH arch := runtime.GOARCH
if arch == "386" { if arch == "386" {

Loading…
Cancel
Save