Don't delete pinned file if it removed by owner

This commit is contained in:
shortcutme 2018-10-15 13:09:43 +02:00
parent 0f49d412b5
commit c12454a8e9
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE
2 changed files with 21 additions and 3 deletions

View file

@ -53,6 +53,10 @@ if "access_log" not in locals().keys(): # To keep between module reloads
@PluginManager.registerTo("ContentManager") @PluginManager.registerTo("ContentManager")
class ContentManagerPlugin(object): class ContentManagerPlugin(object):
def __init__(self, *args, **kwargs):
self.cache_is_pinned = {}
super(ContentManagerPlugin, self).__init__(*args, **kwargs)
def optionalDownloaded(self, inner_path, hash_id, size=None, own=False): def optionalDownloaded(self, inner_path, hash_id, size=None, own=False):
if "|" in inner_path: # Big file piece if "|" in inner_path: # Big file piece
file_inner_path, file_range = inner_path.split("|") file_inner_path, file_range = inner_path.split("|")
@ -100,6 +104,14 @@ class ContentManagerPlugin(object):
return False return False
def optionalDelete(self, inner_path):
if self.isPinned(inner_path):
self.site.log.debug("Skip deleting pinned optional file: %s" % inner_path)
return False
else:
return super(ContentManagerPlugin, self).optionalDelete(inner_path)
@PluginManager.registerTo("WorkerManager") @PluginManager.registerTo("WorkerManager")
class WorkerManagerPlugin(object): class WorkerManagerPlugin(object):
def doneTask(self, task): def doneTask(self, task):

View file

@ -113,10 +113,10 @@ class ContentManager(object):
try: try:
old_hash_id = self.hashfield.getHashId(old_hash) old_hash_id = self.hashfield.getHashId(old_hash)
self.optionalRemoved(file_inner_path, old_hash_id, old_content["files_optional"][relative_path]["size"]) self.optionalRemoved(file_inner_path, old_hash_id, old_content["files_optional"][relative_path]["size"])
self.site.storage.delete(file_inner_path) self.optionalDelete(file_inner_path)
self.log.debug("Deleted changed optional file: %s" % file_inner_path) self.log.debug("Deleted changed optional file: %s" % file_inner_path)
except Exception, err: except Exception, err:
self.log.debug("Error deleting file %s: %s" % (file_inner_path, err)) self.log.debug("Error deleting file %s: %s" % (file_inner_path, Debug.formatException(err)))
else: # The file is not in the old content else: # The file is not in the old content
if self.site.isDownloadable(file_inner_path): if self.site.isDownloadable(file_inner_path):
changed.append(file_inner_path) # Download new file changed.append(file_inner_path) # Download new file
@ -143,14 +143,17 @@ class ContentManager(object):
# Check if the deleted file is optional # Check if the deleted file is optional
if old_content.get("files_optional") and old_content["files_optional"].get(file_relative_path): if old_content.get("files_optional") and old_content["files_optional"].get(file_relative_path):
self.optionalDelete(file_inner_path)
old_hash = old_content["files_optional"][file_relative_path].get("sha512") old_hash = old_content["files_optional"][file_relative_path].get("sha512")
if self.hashfield.hasHash(old_hash): if self.hashfield.hasHash(old_hash):
old_hash_id = self.hashField.getHashid(old_hash) old_hash_id = self.hashField.getHashid(old_hash)
self.optionalRemoved(file_inner_path, old_hash_id, old_content["files_optional"][file_relative_path]["size"]) self.optionalRemoved(file_inner_path, old_hash_id, old_content["files_optional"][file_relative_path]["size"])
else:
self.site.storage.delete(file_inner_path)
self.log.debug("Deleted file: %s" % file_inner_path) self.log.debug("Deleted file: %s" % file_inner_path)
except Exception, err: except Exception, err:
self.log.debug("Error deleting file %s: %s" % (file_inner_path, err)) self.log.debug("Error deleting file %s: %s" % (file_inner_path, Debug.formatException(err)))
# Cleanup empty dirs # Cleanup empty dirs
tree = {root: [dirs, files] for root, dirs, files in os.walk(self.site.storage.getPath(content_inner_dir))} tree = {root: [dirs, files] for root, dirs, files in os.walk(self.site.storage.getPath(content_inner_dir))}
@ -950,6 +953,9 @@ class ContentManager(object):
else: # File not in content.json else: # File not in content.json
raise VerifyError("File not in content.json") raise VerifyError("File not in content.json")
def optionalDelete(self, inner_path):
self.site.storage.delete(inner_path)
def optionalDownloaded(self, inner_path, hash_id, size=None, own=False): def optionalDownloaded(self, inner_path, hash_id, size=None, own=False):
if size is None: if size is None:
size = self.site.storage.getSize(inner_path) size = self.site.storage.getSize(inner_path)