summaryrefslogtreecommitdiff
path: root/pkg/machine/fedora.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/machine/fedora.go')
-rw-r--r--pkg/machine/fedora.go18
1 files changed, 15 insertions, 3 deletions
diff --git a/pkg/machine/fedora.go b/pkg/machine/fedora.go
index 2c6d3d810..7c80fc5d3 100644
--- a/pkg/machine/fedora.go
+++ b/pkg/machine/fedora.go
@@ -11,6 +11,7 @@ import (
"net/http"
"net/url"
"path/filepath"
+ "time"
)
const (
@@ -27,7 +28,7 @@ func NewFedoraDownloader(vmType, vmName, releaseStream string) (DistributionDown
return nil, err
}
- dataDir, err := GetDataDir(vmType)
+ cacheDir, err := GetCacheDir(vmType)
if err != nil {
return nil, err
}
@@ -38,15 +39,20 @@ func NewFedoraDownloader(vmType, vmName, releaseStream string) (DistributionDown
Download: Download{
Arch: getFcosArch(),
Artifact: artifact,
+ CacheDir: cacheDir,
Format: Format,
ImageName: imageName,
- LocalPath: filepath.Join(dataDir, imageName),
+ LocalPath: filepath.Join(cacheDir, imageName),
URL: downloadURL,
VMName: vmName,
Size: size,
},
}
- f.Download.LocalUncompressedFile = f.getLocalUncompressedName()
+ dataDir, err := GetDataDir(vmType)
+ if err != nil {
+ return nil, err
+ }
+ f.Download.LocalUncompressedFile = f.getLocalUncompressedFile(dataDir)
return f, nil
}
@@ -65,6 +71,12 @@ func (f FedoraDownload) HasUsableCache() (bool, error) {
return info.Size() == f.Size, nil
}
+func (f FedoraDownload) CleanCache() error {
+ // Set cached image to expire after 2 weeks
+ expire := 14 * 24 * time.Hour
+ return removeImageAfterExpire(f.CacheDir, expire)
+}
+
func getFedoraDownload(releaseURL string) (*url.URL, int64, error) {
downloadURL, err := url.Parse(releaseURL)
if err != nil {