Skip to content

Commit

Permalink
fix(host-cleanup): "permission denied" errors, do not wipe git-patche…
Browse files Browse the repository at this point in the history
…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 2840427
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/git_repo/gitdata/gc.go
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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() {
Expand Down
16 changes: 16 additions & 0 deletions pkg/git_repo/gitdata/git_data_entry.go
Expand Up @@ -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.