Skip to content

Commit 6c0ac8b

Browse files
authored
clientupdate: cleanup SPK and MSI downloads (tailscale#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 tailscale#10082 Signed-off-by: Andrew Lytvynov <awly@tailscale.com>
1 parent aa5af06 commit 6c0ac8b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

clientupdate/clientupdate.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ func (up *Updater) updateSynology() error {
284284
return nil
285285
}
286286

287+
up.cleanupOldDownloads(filepath.Join(os.TempDir(), "tailscale-update*"))
287288
// Download the SPK into a temporary directory.
288289
spkDir, err := os.MkdirTemp("", "tailscale-update")
289290
if err != nil {
@@ -743,6 +744,7 @@ you can run the command prompt as Administrator one of these ways:
743744
if err := os.MkdirAll(msiDir, 0700); err != nil {
744745
return err
745746
}
747+
up.cleanupOldDownloads(filepath.Join(msiDir, "*.msi"))
746748
pkgsPath := fmt.Sprintf("%s/tailscale-setup-%s-%s.msi", up.track, ver, arch)
747749
msiTarget := filepath.Join(msiDir, path.Base(pkgsPath))
748750
if err := up.downloadURLToFile(pkgsPath, msiTarget); err != nil {
@@ -831,6 +833,19 @@ func (up *Updater) installMSI(msi string) error {
831833
return err
832834
}
833835

836+
func (up *Updater) cleanupOldDownloads(glob string) {
837+
matches, err := filepath.Glob(glob)
838+
if err != nil {
839+
up.Logf("cleaning up old downloads: %v", err)
840+
return
841+
}
842+
for _, m := range matches {
843+
if err := os.RemoveAll(m); err != nil {
844+
up.Logf("cleaning up old downloads: %v", err)
845+
}
846+
}
847+
}
848+
834849
func msiUUIDForVersion(ver string) string {
835850
arch := runtime.GOARCH
836851
if arch == "386" {

0 commit comments

Comments
 (0)