Remove pinned status of a file on file deletion

This commit is contained in:
shortcutme 2018-10-15 13:12:46 +02:00
parent 96d40d9816
commit 9b4b9334a3
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -1,6 +1,9 @@
import time import time
import re
import collections import collections
import gevent
from util import helper from util import helper
from Plugin import PluginManager from Plugin import PluginManager
import ContentDbPlugin import ContentDbPlugin
@ -72,16 +75,16 @@ class ContentManagerPlugin(object):
def optionalRemoved(self, inner_path, hash_id, size=None): def optionalRemoved(self, inner_path, hash_id, size=None):
self.contents.db.execute( self.contents.db.execute(
"UPDATE file_optional SET is_downloaded = 0, peer = peer - 1 WHERE site_id = :site_id AND inner_path = :inner_path AND is_downloaded = 1", "UPDATE file_optional SET is_downloaded = 0, is_pinned = 0, peer = peer - 1 WHERE site_id = :site_id AND inner_path = :inner_path AND is_downloaded = 1",
{"site_id": self.contents.db.site_ids[self.site.address], "inner_path": inner_path} {"site_id": self.contents.db.site_ids[self.site.address], "inner_path": inner_path}
) )
print "Removed hash_id: %s" % hash_id, self.contents.db.cur.cursor.rowcount
if self.contents.db.cur.cursor.rowcount > 0: if self.contents.db.cur.cursor.rowcount > 0:
back = super(ContentManagerPlugin, self).optionalRemoved(inner_path, hash_id, size) back = super(ContentManagerPlugin, self).optionalRemoved(inner_path, hash_id, size)
# Re-add to hashfield if we have other file with the same hash_id # Re-add to hashfield if we have other file with the same hash_id
if self.isDownloaded(hash_id=hash_id, force_check_db=True): if self.isDownloaded(hash_id=hash_id, force_check_db=True):
self.hashfield.appendHashId(hash_id) self.hashfield.appendHashId(hash_id)
return back
def isDownloaded(self, inner_path=None, hash_id=None, force_check_db=False): def isDownloaded(self, inner_path=None, hash_id=None, force_check_db=False):
if hash_id and not force_check_db and hash_id not in self.hashfield: if hash_id and not force_check_db and hash_id not in self.hashfield: