From 15f963418734e0ea6051694a5a63e22b3154af10 Mon Sep 17 00:00:00 2001 From: Tigor Hutasuhut Date: Fri, 3 May 2024 09:31:57 +0700 Subject: [PATCH] api: isImageEntryExists: fix image file existence check --- api/download_subreddit_images.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/api/download_subreddit_images.go b/api/download_subreddit_images.go index d16176e..cff0390 100644 --- a/api/download_subreddit_images.go +++ b/api/download_subreddit_images.go @@ -313,10 +313,17 @@ func (api *API) isImageEntryExists(ctx context.Context, post reddit.Post, device models.SelectWhere.Images.Device.EQ(device.Slug), models.SelectWhere.Images.PostName.EQ(post.GetName()), ).Exists() - - _, errStat := os.Stat(post.GetImageTargetPath(api.config, device)) - - return exist && errQuery == nil && errStat == nil + if errQuery != nil { + return false + } + if !exist { + return false + } + stat, errStat := os.Stat(post.GetImageTargetPath(api.config, device)) + if errStat != nil { + return false + } + return stat.Size() > 0 } // findImageFileForDevice finds if any of the image file exists for given devices.