~chrisppy/beagles-devel

Check for duplicate feed before adding v1 APPLIED

Will Tiffany: 1
 Check for duplicate feed before adding

 1 files changed, 10 insertions(+), 7 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~chrisppy/beagles-devel/patches/11754/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] Check for duplicate feed before adding Export this patch

---
 db/db.go | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/db/db.go b/db/db.go
index eed6ac5..3872e03 100644
--- a/db/db.go
+++ b/db/db.go
@@ -130,6 +130,11 @@ func ReadDB(path string) (*Storage, error) {
// CreateFeed will collect the rss feed and process through the elements
// and add the relevant data elements to the database
func (s *Storage) CreateFeed(url string) error {
	_, ok := s.Feeds[url]
	if ok {
		return fmt.Errorf("already subscribed to feed: %s", url)
	}

	f, err := parseFeed(url)
	if err != nil {
		return fmt.Errorf("unable to fetch url: %s", err.Error())
@@ -245,18 +250,16 @@ func (s *Storage) DeleteFeed(url string) error {
		return fmt.Errorf("url was empty, unable to delete")
	}

	feed, ok := s.Feeds[url]
	if !ok {
		return fmt.Errorf("feed does not exist")
	}

	db, err := openDB(s.Path)
	if err != nil {
		return fmt.Errorf("unable to open db: %s", err.Error())
	}

	feed, ok := s.Feeds[url]
	if !ok {
		if err := db.Close(); err != nil {
			return err
		}
		return fmt.Errorf("feed does not exist")
	}
	items := feed.Items
	for _, key := range items {
		// Delete from item database
-- 
2.27.0
Thanks Will!