MCPcopy
hub / github.com/HelloZeroNet/ZeroNet / hashFiles

Method hashFiles

src/Content/ContentManager.py:609–645  ·  view source on GitHub ↗
(self, dir_inner_path, ignore_pattern=None, optional_pattern=None)

Source from the content-addressed store, hash-verified

607
608 # Hash files in directory
609 def hashFiles(self, dir_inner_path, ignore_pattern=None, optional_pattern=None):
610 files_node = {}
611 files_optional_node = {}
612 if dir_inner_path and not self.isValidRelativePath(dir_inner_path):
613 ignored = True
614 self.log.error("- [ERROR] Only ascii encoded directories allowed: %s" % dir_inner_path)
615
616 for file_relative_path in self.site.storage.walk(dir_inner_path, ignore_pattern):
617 file_name = helper.getFilename(file_relative_path)
618
619 ignored = optional = False
620 if file_name == "content.json":
621 ignored = True
622 elif file_name.startswith(".") or file_name.endswith("-old") or file_name.endswith("-new"):
623 ignored = True
624 elif not self.isValidRelativePath(file_relative_path):
625 ignored = True
626 self.log.error("- [ERROR] Invalid filename: %s" % file_relative_path)
627 elif dir_inner_path == "" and self.site.storage.getDbFile() and file_relative_path.startswith(self.site.storage.getDbFile()):
628 ignored = True
629 elif optional_pattern and SafeRe.match(optional_pattern, file_relative_path):
630 optional = True
631
632 if ignored: # Ignore content.json, defined regexp and files starting with .
633 self.log.info("- [SKIPPED] %s" % file_relative_path)
634 else:
635 if optional:
636 self.log.info("- [OPTIONAL] %s" % file_relative_path)
637 files_optional_node.update(
638 self.hashFile(dir_inner_path, file_relative_path, optional=True)
639 )
640 else:
641 self.log.info("- %s" % file_relative_path)
642 files_node.update(
643 self.hashFile(dir_inner_path, file_relative_path)
644 )
645 return files_node, files_optional_node
646
647 # Create and sign a content.json
648 # Return: The new content if filewrite = False

Callers 1

signMethod · 0.95

Calls 6

isValidRelativePathMethod · 0.95
hashFileMethod · 0.95
errorMethod · 0.80
getDbFileMethod · 0.80
walkMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected