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

Method needFile

plugins/Bigfile/BigfilePlugin.py:745–781  ·  view source on GitHub ↗
(self, inner_path, *args, **kwargs)

Source from the content-addressed store, hash-verified

743 return back
744
745 def needFile(self, inner_path, *args, **kwargs):
746 if inner_path.endswith("|all"):
747 @util.Pooled(20)
748 def pooledNeedBigfile(inner_path, *args, **kwargs):
749 if inner_path not in self.bad_files:
750 self.log.debug("Cancelled piece, skipping %s" % inner_path)
751 return False
752 return self.needFile(inner_path, *args, **kwargs)
753
754 inner_path = inner_path.replace("|all", "")
755 file_info = self.needFileInfo(inner_path)
756
757 # Use default function to download non-optional file
758 if "piece_size" not in file_info:
759 return super(SitePlugin, self).needFile(inner_path, *args, **kwargs)
760
761 file_size = file_info["size"]
762 piece_size = file_info["piece_size"]
763
764 piece_num = int(math.ceil(float(file_size) / piece_size))
765
766 file_threads = []
767
768 piecefield = self.storage.piecefields.get(file_info["sha512"])
769
770 for piece_i in range(piece_num):
771 piece_from = piece_i * piece_size
772 piece_to = min(file_size, piece_from + piece_size)
773 if not piecefield or not piecefield[piece_i]:
774 inner_path_piece = "%s|%s-%s" % (inner_path, piece_from, piece_to)
775 self.bad_files[inner_path_piece] = self.bad_files.get(inner_path_piece, 1)
776 res = pooledNeedBigfile(inner_path_piece, blocking=False)
777 if res is not True and res is not False:
778 file_threads.append(res)
779 gevent.joinall(file_threads)
780 else:
781 return super(SitePlugin, self).needFile(inner_path, *args, **kwargs)
782
783
784@PluginManager.registerTo("ConfigPlugin")

Callers 15

pooledNeedBigfileMethod · 0.95
actionSiteMediaMethod · 0.45
openArchiveMethod · 0.45
actionPatchFileMethod · 0.45
resolveBitDomainMethod · 0.45
getPiecemapMethod · 0.45
openBigfileMethod · 0.45
readMethod · 0.45
testDownloadAllPiecesMethod · 0.45

Calls 2

needFileInfoMethod · 0.80
getMethod · 0.45

Tested by 7

testDownloadAllPiecesMethod · 0.36
testFileSizeMethod · 0.36
testFileRenameMethod · 0.36
testNullFileReadMethod · 0.36