Skip to content

Commit

Permalink
add forget
Browse files Browse the repository at this point in the history
  • Loading branch information
roarc0 committed Jun 25, 2024
1 parent bc67c9a commit b7ffeb6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/gofetch/gofetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ func (gf *GoFetch) Ignore(dl Downloadable) error {
return nil
}

func (gf *GoFetch) Forget(dl Downloadable) error {
hash := collector.Hash(dl)
return gf.memory.Del(hash)
}

func (gf *GoFetch) Stream(dl Downloadable) error {
return collector.WebTorrentDownloader{}.Download(dl)
}
9 changes: 9 additions & 0 deletions internal/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Memory interface {
Put(key string, value string) error
Get(key string) (*string, error)
Has(key string) bool
Del(key string) error
io.Closer
}

Expand Down Expand Up @@ -84,6 +85,14 @@ func (m *memory) Has(key string) bool {
return exists
}

func (m *memory) Del(key string) error {
return m.db.Update(func(tx *bolt.Tx) error {
b := tx.Bucket(m.bucket)
err := b.Delete([]byte(key))
return err
})
}

func (m *memory) Close() error {
return m.db.Close()
}
14 changes: 14 additions & 0 deletions internal/test/mocks/mock_memory.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b7ffeb6

Please sign in to comment.