Skip to content
Permalink
Browse files
fix(host-cleanup): "permission denied" errors, do not wipe git-patche…
…s on every run

* Fix bug related to wiping of old git-patches by cache-version: fixed typo.
* Do not remove git data entries which has been used recently (wait for 3 hours).
  • Loading branch information
distorhead committed Oct 11, 2021
1 parent 776bbcc commit 2840427158340ec1d2db8a90597c47facf489120
Showing with 19 additions and 1 deletion.
  1. +3 −1 pkg/git_repo/gitdata/gc.go
  2. +16 −0 pkg/git_repo/gitdata/git_data_entry.go
@@ -110,7 +110,7 @@ func RunGC(ctx context.Context, allowedVolumeUsagePercentage, allowedVolumeUsage

{
cacheRoot := filepath.Join(werf.GetLocalCacheDir(), "git_patches")
if err := wipeCacheDirs(ctx, cacheRoot, []string{GitArchivesCacheVersion}); err != nil {
if err := wipeCacheDirs(ctx, cacheRoot, []string{GitPatchesCacheVersion}); err != nil {
return fmt.Errorf("unable to wipe old git patches cache dirs in %q: %s", cacheRoot, err)
}
}
@@ -201,6 +201,8 @@ func RunGC(ctx context.Context, allowedVolumeUsagePercentage, allowedVolumeUsage

sort.Sort(GitDataLruSort(gitDataEntries))

gitDataEntries = PreserveGitDataByLru(gitDataEntries)

var freedBytes uint64
for _, entry := range gitDataEntries {
for _, path := range entry.GetPaths() {
@@ -15,3 +15,19 @@ func (a GitDataLruSort) Less(i, j int) bool {
return a[i].GetLastAccessAt().Before(a[j].GetLastAccessAt())
}
func (a GitDataLruSort) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

func PreserveGitDataByLru(entries []GitDataEntry) []GitDataEntry {
var res []GitDataEntry

for _, entry := range entries {
if !ShouldPreserveGitDataEntryByLru(entry) {
res = append(res, entry)
}
}

return res
}

func ShouldPreserveGitDataEntryByLru(entry GitDataEntry) bool {
return time.Since(entry.GetLastAccessAt()) < 3*time.Hour
}

0 comments on commit 2840427

Please sign in to comment.