From 9de0f812f55c508880cde9a7fa9de6634510be3c Mon Sep 17 00:00:00 2001 From: Mustafa Gezen Date: Fri, 1 Jan 2021 16:55:21 +0100 Subject: [PATCH] prune lookaside files that change in the same stream --- internal/git.go | 11 +++++++---- internal/process.go | 13 ++++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/internal/git.go b/internal/git.go index b54ec33..bd7b46e 100644 --- a/internal/git.go +++ b/internal/git.go @@ -175,7 +175,7 @@ func (g *GitMode) WriteSource(md *modeData) { } md.sourcesToIgnore = append(md.sourcesToIgnore, &ignoredSource{ - name: filepath.Base(path), + name: path, hashFunction: hasher, }) @@ -189,9 +189,12 @@ func (g *GitMode) WriteSource(md *modeData) { func (g *GitMode) PostProcess(md *modeData) { for _, source := range md.sourcesToIgnore { - err := md.worktree.Filesystem.Remove(filepath.Join("SOURCES", source.name)) - if err != nil { - log.Fatalf("could not remove dist-git file: %v", err) + _, err := md.worktree.Filesystem.Stat(source.name) + if err == nil { + err := md.worktree.Filesystem.Remove(source.name) + if err != nil { + log.Fatalf("could not remove dist-git file: %v", err) + } } } diff --git a/internal/process.go b/internal/process.go index 8596b86..1a45aef 100644 --- a/internal/process.go +++ b/internal/process.go @@ -43,6 +43,7 @@ type ProcessData struct { type ignoredSource struct { name string hashFunction hash.Hash + expired bool } type modeData struct { @@ -112,7 +113,9 @@ func ProcessRPM(pd *ProcessData) { md.repo = &sourceRepo md.worktree = &sourceWorktree md.tagBranch = branch - md.sourcesToIgnore = []*ignoredSource{} + for _, source := range md.sourcesToIgnore { + source.expired = true + } rpmFile := md.rpmFile // create new repo for final dist @@ -217,7 +220,11 @@ func ProcessRPM(pd *ProcessData) { log.Fatalf("could not create metadata file: %v", err) } for _, source := range md.sourcesToIgnore { - sourcePath := "SOURCES/" + source.name + if source.expired { + continue + } + + sourcePath := source.name sourceFile, err := w.Filesystem.Open(sourcePath) if err != nil { log.Fatalf("could not open ignored source file %s: %v", sourcePath, err) @@ -239,7 +246,7 @@ func ProcessRPM(pd *ProcessData) { log.Fatalf("could not write to metadata file: %v", err) } - path := fmt.Sprintf("%s/%s", rpmFile.Name(), checksum) + path := fmt.Sprintf("%s", checksum) if strContains(alreadyUploadedBlobs, path) { continue }