Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cache memory exceed check #24

Merged
merged 5 commits into from
Jul 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pkg/cache/lrucache.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"sync"
"syscall"

"github.com/go-git/go-git/v5"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -59,6 +60,19 @@ func NewGitRepoLRUCache(dir string, minFreeGbs uint64) (*GitRepoLRUCache, error)
return nil, fmt.Errorf("error checking provided cache directory: %s", err.Error())
}

stats := &syscall.Statfs_t{}

err = syscall.Statfs(dir, stats)
if err != nil {
return nil, fmt.Errorf("error fetching stats for cache directory: %s", err.Error())
}

freeSpace := stats.Bavail * stats.Bfree
AvineshTripathi marked this conversation as resolved.
Show resolved Hide resolved

if freeSpace <= minFreeGbs {
AvineshTripathi marked this conversation as resolved.
Show resolved Hide resolved
return nil, fmt.Errorf("memory limit exceeded for cache directory")
AvineshTripathi marked this conversation as resolved.
Show resolved Hide resolved
}

return &GitRepoLRUCache{
minFreeDiskGb: minFreeGbs,
dir: path,
Expand Down