avoid tor deadlock, clenaup annotations on delete
This commit is contained in:
parent
6f8acb90d9
commit
8169d8e720
2 changed files with 15 additions and 3 deletions
|
@ -311,13 +311,20 @@ class Item(db.Model):
|
|||
|
||||
def delete(self, commit=True):
|
||||
Sort.query.filter_by(item_id=self.id).delete()
|
||||
Find.query.filter_by(item_id=self.id).delete()
|
||||
if state.downloads and self.id in state.downloads.transfers:
|
||||
del state.downloads.transfers[self.id]
|
||||
state.db.session.delete(self)
|
||||
icons.clear('cover:%s' % self.id)
|
||||
icons.clear('preview:%s' % self.id)
|
||||
if commit:
|
||||
state.db.session.commit()
|
||||
icons.clear('cover:%s' % self.id)
|
||||
icons.clear('preview:%s' % self.id)
|
||||
|
||||
def remove_annotations(self):
|
||||
from annotation.models import Annotation
|
||||
for a in Annotation.query.filter_by(item_id=self.id, user_id=state.user()):
|
||||
a.add_record('removeannotation')
|
||||
a.delete()
|
||||
|
||||
meta_keys = (
|
||||
'author',
|
||||
|
@ -562,6 +569,7 @@ class Item(db.Model):
|
|||
state.db.session.add(self)
|
||||
|
||||
def remove_file(self):
|
||||
folders = set()
|
||||
for f in self.files.all():
|
||||
path = f.fullpath()
|
||||
if os.path.exists(path):
|
||||
|
@ -569,10 +577,12 @@ class Item(db.Model):
|
|||
try:
|
||||
os.chmod(path, mode)
|
||||
os.unlink(path)
|
||||
remove_empty_folders(os.path.dirname(path))
|
||||
folders.add(os.path.dirname(path))
|
||||
except:
|
||||
pass
|
||||
state.db.session.delete(f)
|
||||
for folder in folders:
|
||||
remove_empty_folders(folder)
|
||||
user = state.user()
|
||||
if user in self.users:
|
||||
self.users.remove(user)
|
||||
|
@ -589,6 +599,7 @@ class Item(db.Model):
|
|||
if self.id in state.downloads.transfers:
|
||||
del state.downloads.transfers[self.id]
|
||||
add_record('removeitem', self.id)
|
||||
self.remove_annotations()
|
||||
|
||||
class Sort(db.Model):
|
||||
__tablename__ = 'sort'
|
||||
|
|
|
@ -103,6 +103,7 @@ DirReqStatistics 0
|
|||
for line in self.p.stdout:
|
||||
self._status.append(line)
|
||||
logger.debug(line)
|
||||
self.p.communicate()
|
||||
time.sleep(0.5)
|
||||
self.p = None
|
||||
|
||||
|
|
Loading…
Reference in a new issue