summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cache/cache.go16
-rw-r--r--cache/cache_test.go14
-rw-r--r--main.go6
3 files changed, 35 insertions, 1 deletions
diff --git a/cache/cache.go b/cache/cache.go
index ae2d081..98bdbe8 100644
--- a/cache/cache.go
+++ b/cache/cache.go
@@ -111,3 +111,19 @@ func LoadState(f fs.FS, cache Cache, indexers []model.Indexer, runners []model.R
}
return model.NewState(f, locs, indexers, runners)
}
+
+func (c Cache) Strip(needle Cache) Cache {
+ var result []Entry
+outer:
+ for _, e := range c.Entries {
+ for _, t := range needle.Entries {
+ if t.Path == e.Path {
+ continue outer
+ }
+ }
+ result = append(result, e)
+ }
+ return Cache{
+ Entries: result,
+ }
+}
diff --git a/cache/cache_test.go b/cache/cache_test.go
index fa81974..c140154 100644
--- a/cache/cache_test.go
+++ b/cache/cache_test.go
@@ -77,3 +77,17 @@ func TestFromReader_Comments(t *testing.T) {
Label: "da source",
})
}
+
+func TestStrip(t *testing.T) {
+ c := Cache{Entries: []Entry{{"/asdf/123", ""}, {"xxxxx", "lab"}}}
+ remove := Cache{Entries: []Entry{{"xxxxx", "wronglabel"}}}
+ result := c.Strip(remove)
+ assert.Equal(t, Cache{Entries: []Entry{{"/asdf/123", ""}}}, result)
+}
+
+func TestStrip_Nothing(t *testing.T) {
+ c := Cache{Entries: []Entry{{"/asdf/123", ""}, {"/asdf/123", ""}}}
+ old := Cache{}
+ result := c.Strip(old)
+ assert.Equal(t, c, result)
+}
diff --git a/main.go b/main.go
index d44272d..d12f203 100644
--- a/main.go
+++ b/main.go
@@ -40,6 +40,7 @@ var hydrators = []model.Hydrator{
}
var ForceConfirm = false
+var SourcesWithoutResults cache.Cache
//go:embed version.txt
var version string
@@ -79,10 +80,12 @@ func main() {
var st *model.State
var stateErrors []error
+ var c cache.Cache
if !*flags.All {
st, stateErrors = model.NewState(fs, locs, indexers, runners)
} else {
- c, err := cache.Load()
+ c, err = cache.Load()
+ c.Strip(SourcesWithoutResults)
if err != nil {
_, _ = spool.Warn("%v\n", err)
os.Exit(1)
@@ -136,6 +139,7 @@ func main() {
_, _ = spool.Warn("%v\n", err)
os.Exit(1)
}
+ SourcesWithoutResults = c
main()
return
}