From 7a71581e452af3bc6c5f9d646818eeb34e833d53 Mon Sep 17 00:00:00 2001 From: "Diogo Franco (Kovensky)" Date: Fri, 26 Jul 2013 12:20:43 -0300 Subject: [PATCH] anidb: Avoid crash during MyListAdd / MyListEdit Could happen if a file is added without a cached MyListEntry. Make a fake MyListEntry and cache that, with an old enough Cached timestamp to make it always stale. Also change the always stale timestamp in parseMylistReply to a more reliably ancient one. --- mylistcache.go | 2 +- mylistmanip.go | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/mylistcache.go b/mylistcache.go index ed6a8ec..0aa837a 100644 --- a/mylistcache.go +++ b/mylistcache.go @@ -237,7 +237,7 @@ func (adb *AniDB) parseMylistReply(reply udpapi.APIReply) *MyListEntry { if mla.Cached.IsZero() { // as attractive as such an ancient mtime would be, // few filesystems can represent it; just make it old enough - mla.Cached = now.Add(-2 * MyListCacheDuration) + mla.Cached = time.Unix(0, 0), } Cache.Set(mla, key...) diff --git a/mylistmanip.go b/mylistmanip.go index f643c5f..49c0278 100644 --- a/mylistmanip.go +++ b/mylistmanip.go @@ -86,13 +86,29 @@ func (set *MyListSet) update(uid UID, f *File, lid LID) { Cache.Set(mla, "mylist-anime", uid, f.AID) Cache.Chtime(mla.Cached, "mylist-anime", uid, f.AID) + e := lid.MyListEntry() if set == nil || (set.ViewDate == nil && set.Watched == nil && set.State == nil && set.Source == nil && set.Storage == nil && set.Other == nil) { return } + if e == nil { + now := time.Now() + e = &MyListEntry{ + LID: lid, + + AID: f.AID, + EID: f.EID, + FID: f.FID, + GID: f.GID, + + DateAdded: now, + + // make sure it's expired + Cached: time.Unix(0, 0), + } + } - e := lid.MyListEntry() if set.ViewDate != nil { e.DateWatched = *set.ViewDate } else if set.Watched != nil { -- 2.44.0