Don't delete pinned file if it removed by owner
This commit is contained in:
parent
0f49d412b5
commit
c12454a8e9
2 changed files with 21 additions and 3 deletions
|
@ -53,6 +53,10 @@ if "access_log" not in locals().keys(): # To keep between module reloads
|
|||
|
||||
@PluginManager.registerTo("ContentManager")
|
||||
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):
|
||||
if "|" in inner_path: # Big file piece
|
||||
file_inner_path, file_range = inner_path.split("|")
|
||||
|
@ -100,6 +104,14 @@ class ContentManagerPlugin(object):
|
|||
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")
|
||||
class WorkerManagerPlugin(object):
|
||||
def doneTask(self, task):
|
||||
|
|
|
@ -113,10 +113,10 @@ class ContentManager(object):
|
|||
try:
|
||||
old_hash_id = self.hashfield.getHashId(old_hash)
|
||||
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)
|
||||
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
|
||||
if self.site.isDownloadable(file_inner_path):
|
||||
changed.append(file_inner_path) # Download new file
|
||||
|
@ -143,14 +143,17 @@ class ContentManager(object):
|
|||
|
||||
# Check if the deleted file is optional
|
||||
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")
|
||||
if self.hashfield.hasHash(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"])
|
||||
else:
|
||||
self.site.storage.delete(file_inner_path)
|
||||
|
||||
self.log.debug("Deleted file: %s" % file_inner_path)
|
||||
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
|
||||
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
|
||||
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):
|
||||
if size is None:
|
||||
size = self.site.storage.getSize(inner_path)
|
||||
|
|
Loading…
Reference in a new issue