From d96582a6fb7df092c2856f56decd33034fe0ade3 Mon Sep 17 00:00:00 2001 From: Taru Karttunen Date: Thu, 16 Nov 2017 21:00:51 +0200 Subject: Make object repacking more configurable --- storage/filesystem/internal/dotgit/dotgit.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'storage/filesystem/internal/dotgit/dotgit.go') diff --git a/storage/filesystem/internal/dotgit/dotgit.go b/storage/filesystem/internal/dotgit/dotgit.go index 09688c1..cd4f517 100644 --- a/storage/filesystem/internal/dotgit/dotgit.go +++ b/storage/filesystem/internal/dotgit/dotgit.go @@ -9,6 +9,7 @@ import ( stdioutil "io/ioutil" "os" "strings" + "time" "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/utils/ioutil" @@ -193,8 +194,19 @@ func (d *DotGit) ObjectPackIdx(hash plumbing.Hash) (billy.File, error) { return d.objectPackOpen(hash, `idx`) } -func (d *DotGit) DeleteObjectPackAndIndex(hash plumbing.Hash) error { - err := d.fs.Remove(d.objectPackPath(hash, `pack`)) +func (d *DotGit) DeleteOldObjectPackAndIndex(hash plumbing.Hash, t time.Time) error { + path := d.objectPackPath(hash, `pack`) + if !t.IsZero() { + fi, err := d.fs.Stat(path) + if err != nil { + return err + } + // too new, skip deletion. + if !fi.ModTime().Before(t) { + return nil + } + } + err := d.fs.Remove(path) if err != nil { return err } -- cgit