Rename optionalRemove to optionalRemoved and accept hash only by id
This commit is contained in:
parent
17be72e55e
commit
f162987a4f
2 changed files with 13 additions and 15 deletions
|
@ -14,6 +14,7 @@ if "_" not in locals():
|
||||||
|
|
||||||
bigfile_sha512_cache = {}
|
bigfile_sha512_cache = {}
|
||||||
|
|
||||||
|
|
||||||
@PluginManager.registerTo("UiWebsocket")
|
@PluginManager.registerTo("UiWebsocket")
|
||||||
class UiWebsocketPlugin(object):
|
class UiWebsocketPlugin(object):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -228,7 +229,7 @@ class UiWebsocketPlugin(object):
|
||||||
if not row:
|
if not row:
|
||||||
return self.response(to, {"error": "Not found in content.db"})
|
return self.response(to, {"error": "Not found in content.db"})
|
||||||
|
|
||||||
removed = site.content_manager.optionalRemove(inner_path, row["hash_id"], row["size"])
|
removed = site.content_manager.optionalRemoved(inner_path, row["hash_id"], row["size"])
|
||||||
# if not removed:
|
# if not removed:
|
||||||
# return self.response(to, {"error": "Not found in hash_id: %s" % row["hash_id"]})
|
# return self.response(to, {"error": "Not found in hash_id: %s" % row["hash_id"]})
|
||||||
|
|
||||||
|
@ -242,7 +243,6 @@ class UiWebsocketPlugin(object):
|
||||||
|
|
||||||
self.response(to, "ok")
|
self.response(to, "ok")
|
||||||
|
|
||||||
|
|
||||||
# Limit functions
|
# Limit functions
|
||||||
|
|
||||||
def actionOptionalLimitStats(self, to):
|
def actionOptionalLimitStats(self, to):
|
||||||
|
|
|
@ -111,7 +111,8 @@ class ContentManager(object):
|
||||||
changed.append(file_inner_path) # Download new file
|
changed.append(file_inner_path) # Download new file
|
||||||
elif old_hash != new_hash and self.hashfield.hasHash(old_hash) and not self.site.settings.get("own"):
|
elif old_hash != new_hash and self.hashfield.hasHash(old_hash) and not self.site.settings.get("own"):
|
||||||
try:
|
try:
|
||||||
self.optionalRemove(file_inner_path, old_hash, old_content["files_optional"][relative_path]["size"])
|
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.site.storage.delete(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:
|
||||||
|
@ -144,7 +145,8 @@ class ContentManager(object):
|
||||||
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):
|
||||||
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):
|
||||||
self.optionalRemove(file_inner_path, old_hash, old_content["files_optional"][file_relative_path]["size"])
|
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.log.debug("Deleted file: %s" % file_inner_path)
|
self.log.debug("Deleted file: %s" % file_inner_path)
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
|
@ -490,7 +492,7 @@ class ContentManager(object):
|
||||||
file_size = os.path.getsize(file_path)
|
file_size = os.path.getsize(file_path)
|
||||||
sha512sum = CryptHash.sha512sum(file_path) # Calculate sha512 sum of file
|
sha512sum = CryptHash.sha512sum(file_path) # Calculate sha512 sum of file
|
||||||
if optional and not self.hashfield.hasHash(sha512sum):
|
if optional and not self.hashfield.hasHash(sha512sum):
|
||||||
self.optionalDownloaded(file_inner_path, sha512sum, file_size, own=True)
|
self.optionalDownloaded(file_inner_path, self.hashfield.getHashId(sha512sum), file_size, own=True)
|
||||||
|
|
||||||
back[file_relative_path] = {"sha512": sha512sum, "size": os.path.getsize(file_path)}
|
back[file_relative_path] = {"sha512": sha512sum, "size": os.path.getsize(file_path)}
|
||||||
return back
|
return back
|
||||||
|
@ -907,22 +909,18 @@ 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 optionalDownloaded(self, inner_path, hash, 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)
|
||||||
if type(hash) is int:
|
|
||||||
done = self.hashfield.appendHashId(hash)
|
done = self.hashfield.appendHashId(hash_id)
|
||||||
else:
|
|
||||||
done = self.hashfield.appendHash(hash)
|
|
||||||
self.site.settings["optional_downloaded"] += size
|
self.site.settings["optional_downloaded"] += size
|
||||||
return done
|
return done
|
||||||
|
|
||||||
def optionalRemove(self, inner_path, hash, size=None):
|
def optionalRemoved(self, inner_path, hash_id, size=None):
|
||||||
if size is None:
|
if size is None:
|
||||||
size = self.site.storage.getSize(inner_path)
|
size = self.site.storage.getSize(inner_path)
|
||||||
if type(hash) is int:
|
done = self.hashfield.removeHashId(hash_id)
|
||||||
done = self.hashfield.removeHashId(hash)
|
|
||||||
else:
|
|
||||||
done = self.hashfield.removeHash(hash)
|
|
||||||
self.site.settings["optional_downloaded"] -= size
|
self.site.settings["optional_downloaded"] -= size
|
||||||
return done
|
return done
|
||||||
|
|
Loading…
Reference in a new issue