Explorar o código

Remove the price sheet temp file on close

Signed-off-by: Christian Muirhead <christian.muirhead@microsoft.com>
Christian Muirhead %!s(int64=3) %!d(string=hai) anos
pai
achega
e1e77a56ae
Modificáronse 1 ficheiros con 13 adicións e 1 borrados
  1. 13 1
      pkg/cloud/azurepricesheet/downloader.go

+ 13 - 1
pkg/cloud/azurepricesheet/downloader.go

@@ -98,7 +98,19 @@ func (d Downloader[T]) saveData(ctx context.Context, url, tempName string) (io.R
 		return nil, fmt.Errorf("seeking to start of file: %w", err)
 	}
 
-	return out, nil
+	return &removeOnClose{File: out}, nil
+}
+
+type removeOnClose struct {
+	*os.File
+}
+
+func (r *removeOnClose) Close() error {
+	err := r.File.Close()
+	if err != nil {
+		return err
+	}
+	return os.Remove(r.Name())
 }
 
 func (d *Downloader[T]) readPricesheet(ctx context.Context, data io.Reader) (map[string]*T, error) {