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

Method hashFile

src/Content/ContentManager.py:584–595  ·  view source on GitHub ↗
(self, dir_inner_path, file_relative_path, optional=False)

Source from the content-addressed store, hash-verified

582 return diffs
583
584 def hashFile(self, dir_inner_path, file_relative_path, optional=False):
585 back = {}
586 file_inner_path = dir_inner_path + "/" + file_relative_path
587
588 file_path = self.site.storage.getPath(file_inner_path)
589 file_size = os.path.getsize(file_path)
590 sha512sum = CryptHash.sha512sum(file_path) # Calculate sha512 sum of file
591 if optional and not self.hashfield.hasHash(sha512sum):
592 self.optionalDownloaded(file_inner_path, self.hashfield.getHashId(sha512sum), file_size, own=True)
593
594 back[file_relative_path] = {"sha512": sha512sum, "size": os.path.getsize(file_path)}
595 return back
596
597 def isValidRelativePath(self, relative_path):
598 if ".." in relative_path.replace("\\", "/").split("/"):

Callers 1

hashFilesMethod · 0.95

Calls 4

optionalDownloadedMethod · 0.95
getPathMethod · 0.80
hasHashMethod · 0.80
getHashIdMethod · 0.45

Tested by

no test coverage detected