From 741b63479e87642706e217ea90422c8fd757cc12 Mon Sep 17 00:00:00 2001 From: Andrew Lytvynov Date: Thu, 2 Nov 2023 12:21:42 -0600 Subject: [PATCH] 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 (cherry picked from commit 6c0ac8bef3a4f90e311a1cd8346f6e63cb57ac9e) --- clientupdate/clientupdate.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/clientupdate/clientupdate.go b/clientupdate/clientupdate.go index 2c49d9350..36a475884 100644 --- a/clientupdate/clientupdate.go +++ b/clientupdate/clientupdate.go @@ -279,6 +279,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 { @@ -733,6 +734,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 { @@ -821,6 +823,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" {