summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhorchi <vdr@jwendel.de>2020-02-13 14:33:13 +0100
committerhorchi <vdr@jwendel.de>2020-02-13 14:33:13 +0100
commit15f0fdaa237a7ddd2d29c1e2baee70806807ceb5 (patch)
treeb2c5009fb9b965c96010bd4908fe958c6d68bdc1
parent3938e95d034ce1150c21b3121f308643e888f24a (diff)
downloadvdr-plugin-epg2vdr-15f0fdaa237a7ddd2d29c1e2baee70806807ceb5.tar.gz
vdr-plugin-epg2vdr-15f0fdaa237a7ddd2d29c1e2baee70806807ceb5.tar.bz2
update of picture link cleanup
-rw-r--r--update.c64
1 files changed, 30 insertions, 34 deletions
diff --git a/update.c b/update.c
index e0f6a1f..22792ca 100644
--- a/update.c
+++ b/update.c
@@ -2019,12 +2019,12 @@ int cUpdate::storePicturesToFs()
int cUpdate::cleanupPictures()
{
- const char* ext = ".jpg";
- struct dirent* dirent;
- DIR* dir;
- char* pdir;
- int iCount = 0;
- int lCount = 0;
+ const char* ext {".jpg"};
+ struct dirent* dirent {nullptr};
+ DIR* dir {nullptr};
+ char* pdir {nullptr};
+ int iCount {0};
+ int lCount {0};
imageRefDb->countWhere("", iCount);
@@ -2034,27 +2034,11 @@ int cUpdate::cleanupPictures()
return done;
}
- // -----------------------
- // remove unused images
-
tell(1, "Starting cleanup of images in '%s'", epgimagedir);
// -----------------------
// cleanup 'images' directory
- cDbStatement* stmt = new cDbStatement(imageRefDb);
-
- stmt->build("select ");
- stmt->bind("FILEREF", cDBS::bndOut);
- stmt->build(" from %s where ", imageRefDb->TableName());
- stmt->bind("IMGNAMEFS", cDBS::bndIn | cDBS::bndSet);
-
- if (stmt->prepare() != success)
- {
- delete stmt;
- return fail;
- }
-
iCount = 0;
// open directory
@@ -2065,29 +2049,43 @@ int cUpdate::cleanupPictures()
{
tell(1, "Can't open directory '%s', '%s'", pdir, strerror(errno));
free(pdir);
-
return done;
}
free(pdir);
- int cnt = 0;
+ if (!dbConnected(yes))
+ return fail;
+
+ cDbStatement stmt(imageRefDb);
+
+ stmt.build("select ");
+ stmt.bind("IMGNAMEFS", cDBS::bndOut);
+ stmt.build(" from %s", imageRefDb->TableName());
+
+ if (stmt.prepare() != success)
+ return fail;
+
+ std::unordered_set<std::string> usedRefs;
+
+ imageRefDb->clear();
+
+ for (int res = stmt.find(); res; res = stmt.fetch())
+ usedRefs.insert(imageRefDb->getStrValue("IMGNAMEFS"));
+
+ stmt.freeResult();
- while (dbConnected() && (dirent = readdir(dir)))
+ while ((dirent = readdir(dir)))
{
// check extension
if (strncmp(dirent->d_name + strlen(dirent->d_name) - strlen(ext), ext, strlen(ext)) != 0)
continue;
- imageRefDb->clear();
- imageRefDb->setValue("IMGNAMEFS", dirent->d_name);
-
- if (!stmt->find())
+ if (usedRefs.count(dirent->d_name))
{
asprintf(&pdir, "%s/images/%s", epgimagedir, dirent->d_name);
-
- tell(2, "Remove image '%s'", pdir);
+ tell(2, "Removing image '%s'", pdir);
if (!removeFile(pdir))
iCount++;
@@ -2095,11 +2093,9 @@ int cUpdate::cleanupPictures()
free(pdir);
}
- cnt++;
- stmt->freeResult();
+ stmt.freeResult();
}
- delete stmt;
closedir(dir);
// -----------------------