Skip to content

Commit

Permalink
Merge pull request ZeroNetX#220 from caryoscelus/fix-error-handling
Browse files Browse the repository at this point in the history
fix error handling (was: unbound local variable)
  • Loading branch information
caryoscelus authored Jul 25, 2023
2 parents 62f1437 + d924e9b commit db78b2a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/Site/SiteStorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,19 +452,21 @@ def verifyFiles(self, quick_check=False, add_optional=False, add_changed=True):
bad_files.append(file_inner_path)
continue

error = None
if quick_check:
ok = os.path.getsize(file_path) == content["files"][file_relative_path]["size"]
if not ok:
err = "Invalid size"
error = "Invalid size"
else:
try:
ok = self.site.content_manager.verifyFile(file_inner_path, open(file_path, "rb"))
except Exception as err:
error = err
ok = False

if not ok:
back["num_file_invalid"] += 1
self.log.debug("[INVALID] %s: %s" % (file_inner_path, err))
self.log.debug("[INVALID] %s: %s" % (file_inner_path, error))
if add_changed or content.get("cert_user_id"): # If updating own site only add changed user files
bad_files.append(file_inner_path)

Expand Down
5 changes: 3 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,19 @@ def siteVerify(self, address):
for content_inner_path in site.content_manager.contents:
s = time.time()
logging.info("Verifing %s signature..." % content_inner_path)
err = None
error = None
try:
file_correct = site.content_manager.verifyFile(
content_inner_path, site.storage.open(content_inner_path, "rb"), ignore_same=False
)
except Exception as err:
file_correct = False
error = err

if file_correct is True:
logging.info("[OK] %s (Done in %.3fs)" % (content_inner_path, time.time() - s))
else:
logging.error("[ERROR] %s: invalid file: %s!" % (content_inner_path, err))
logging.error("[ERROR] %s: invalid file: %s!" % (content_inner_path, error))
input("Continue?")
bad_files += content_inner_path

Expand Down

0 comments on commit db78b2a

Please sign in to comment.