Skip to content

Commit

Permalink
No exception on incomplete content.json signing
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroNet committed Aug 10, 2016
1 parent ec75944 commit 7291ac8
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/Content/ContentManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,10 @@ def getUserContentRules(self, parent_content, inner_path, content):
try:
if not content:
content = self.site.storage.loadJson(inner_path) # Read the file if no content specified
user_urn = "%s/%s" % (content["cert_auth_type"], content["cert_user_id"]) # web/[email protected]
except Exception: # Content.json not exist
return {"signers": [user_address], "user_address": user_address} # Return information that we know for sure

"""if not "cert_user_name" in content: # New file, unknown user
content["cert_auth_type"] = "unknown"
content["cert_user_name"] = "unknown@unknown"
"""
user_urn = "%s/%s" % (content["cert_auth_type"], content["cert_user_id"]) # web/[email protected]

rules = copy.copy(user_contents["permissions"].get(content["cert_user_id"], {})) # Default rules by username
if rules is False:
banned = True
Expand Down Expand Up @@ -436,7 +431,7 @@ def hashFiles(self, dir_inner_path, ignore_pattern=None, optional_pattern=None):
def sign(self, inner_path="content.json", privatekey=None, filewrite=True, update_changed_files=False, extend=None):
if inner_path in self.contents:
content = self.contents[inner_path]
if self.contents[inner_path].get("cert_sign", False) is None:
if self.contents[inner_path].get("cert_sign", False) is None and self.site.storage.isFile(inner_path):
# Recover cert_sign from file
content["cert_sign"] = self.site.storage.loadJson(inner_path).get("cert_sign")
else:
Expand Down Expand Up @@ -465,7 +460,7 @@ def sign(self, inner_path="content.json", privatekey=None, filewrite=True, updat
files_merged = files_node.copy()
files_merged.update(files_optional_node)
for file_relative_path, file_details in files_merged.iteritems():
old_hash = content["files"].get(file_relative_path, {}).get("sha512")
old_hash = content.get("files", {}).get(file_relative_path, {}).get("sha512")
new_hash = files_merged[file_relative_path]["sha512"]
if old_hash != new_hash:
changed_files.append(inner_directory + file_relative_path)
Expand Down Expand Up @@ -590,7 +585,7 @@ def verifyContent(self, inner_path, content):
# Calculate old content size
old_content = self.contents.get(inner_path)
if old_content:
old_content_size = len(json.dumps(old_content)) + sum([file["size"] for file in old_content["files"].values()])
old_content_size = len(json.dumps(old_content)) + sum([file["size"] for file in old_content.get("files", {}).values()])
else:
old_content_size = 0

Expand Down

0 comments on commit 7291ac8

Please sign in to comment.