From 5ed9f308906f88080509e9d8322ef451430ecfbe Mon Sep 17 00:00:00 2001 From: horchi Date: Wed, 12 Feb 2020 13:00:02 +0100 Subject: improved cleanup of pictures --- lib/common.c | 2 +- update.c | 60 ++++++++++++++++++++++++++++++------------------------------ update.h | 1 - 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/lib/common.c b/lib/common.c index a452b23..2793537 100644 --- a/lib/common.c +++ b/lib/common.c @@ -977,7 +977,6 @@ int removeFile(const char* filename) if (unlink(filename) != 0) { tell(0, "Can't remove file '%s', '%s'", filename, strerror(errno)); - return 1; } @@ -1027,6 +1026,7 @@ xsltStylesheetPtr loadXSLT(const char* name, const char* path, int utf8) tell(0, "Info: Stylesheet '%s' loaded", xsltfile); free(xsltfile); + return stylesheet; } #endif diff --git a/update.c b/update.c index 6c1bbe5..681bb25 100644 --- a/update.c +++ b/update.c @@ -2087,8 +2087,10 @@ int cUpdate::cleanupPictures() if (!dbConnected(yes)) return fail; + tell(1, "Remove %s symlinks", fullreload ? "all" : "old"); + // ----------------------- - // remove wasted symlinks + // remove unused symlinks if (!(dir = opendir(epgimagedir))) { @@ -2096,15 +2098,37 @@ int cUpdate::cleanupPictures() return done; } - tell(1, "Remove %s symlinks", fullreload ? "all" : "old"); - while ((dirent = readdir(dir))) { - // check extension + asprintf(&pdir, "%s/%s", epgimagedir, dirent->d_name); - if (strncmp(dirent->d_name + strlen(dirent->d_name) - strlen(ext), ext, strlen(ext)) != 0) - continue; + if (isLink(pdir)) + { + useeventsDb->setValue("USEID", atoi(dirent->d_name)); + + if (fullreload || !selectEventById->find()) + { + if (!removeFile(pdir)) + lCount++; + } + } + + free(pdir); + } + + closedir(dir); + + // ----------------------- + // remove wasted symlinks + if (!(dir = opendir(epgimagedir))) + { + tell(1, "Can't open directory '%s', '%s'", epgimagedir, strerror(errno)); + return done; + } + + while ((dirent = readdir(dir))) + { asprintf(&pdir, "%s/%s", epgimagedir, dirent->d_name); // fileExists use access() which dereference links! @@ -2123,27 +2147,3 @@ int cUpdate::cleanupPictures() return success; } - -//*************************************************************************** -// Link Needed -//*************************************************************************** - -int cUpdate::pictureLinkNeeded(const char* linkName) -{ - int found; - - if (!dbConnected()) - return yes; - - // we don't need to patch the linkname "123456_0.jpg" - // since atoi() stops at the first non numerical character ... - - imageRefDb->clear(); - imageRefDb->setValue("LFN", 0L); - imageRefDb->setBigintValue("EVENTID", atol(linkName)); - - found = imageRefDb->find(); - imageRefDb->reset(); - - return found; -} diff --git a/update.h b/update.h index 2032569..588f3f0 100644 --- a/update.h +++ b/update.h @@ -197,7 +197,6 @@ class cUpdate : public cThread, public cStatus, public cParameters int lookupVdrEventOf(int eId, const char* cId); int storePicturesToFs(); int cleanupPictures(); - int pictureLinkNeeded(const char* linkName); int getOsd2WebPort(); tChannelID toChanID(const char* chanIdStr) -- cgit v1.2.3