Don't remove pinned files from download queue

This commit is contained in:
shortcutme 2018-10-15 13:10:34 +02:00
parent c12454a8e9
commit 8129d5e6af
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -103,6 +103,32 @@ class ContentManagerPlugin(object):
else: else:
return False return False
def isPinned(self, inner_path):
if inner_path in self.cache_is_pinned:
self.site.log.debug("Cached is pinned: %s" % inner_path)
return self.cache_is_pinned[inner_path]
res = self.contents.db.execute(
"SELECT is_pinned FROM file_optional WHERE site_id = :site_id AND inner_path = :inner_path LIMIT 1",
{"site_id": self.contents.db.site_ids[self.site.address], "inner_path": inner_path}
)
row = res.fetchone()
if row and row[0]:
is_pinned = True
else:
is_pinned = False
self.cache_is_pinned[inner_path] = is_pinned
self.site.log.debug("Cache set is pinned: %s %s" % (inner_path, is_pinned))
return is_pinned
def setPin(self, inner_path, is_pinned):
content_db = self.contents.db
site_id = content_db.site_ids[self.site.address]
content_db.execute("UPDATE file_optional SET is_pinned = %d WHERE ?" % is_pinned, {"site_id": site_id, "inner_path": inner_path})
self.cache_is_pinned = {}
def optionalDelete(self, inner_path): def optionalDelete(self, inner_path):
if self.isPinned(inner_path): if self.isPinned(inner_path):
@ -168,6 +194,13 @@ class SitePlugin(object):
return False return False
def fileForgot(self, inner_path):
if "|" in inner_path and self.content_manager.isPinned(re.sub("\|.*", "", inner_path)):
self.log.debug("File %s is pinned, no fileForgot" % inner_path)
return False
else:
return super(SitePlugin, self).fileForgot(inner_path)
@PluginManager.registerTo("ConfigPlugin") @PluginManager.registerTo("ConfigPlugin")
class ConfigPlugin(object): class ConfigPlugin(object):