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

Method createSparseFile

plugins/Bigfile/BigfilePlugin.py:406–423  ·  view source on GitHub ↗
(self, inner_path, size, sha512=None)

Source from the content-addressed store, hash-verified

404 self.site.settings["cache"]["piecefields"] = {}
405
406 def createSparseFile(self, inner_path, size, sha512=None):
407 file_path = self.getPath(inner_path)
408
409 file_dir = os.path.dirname(file_path)
410 if not os.path.isdir(file_dir):
411 os.makedirs(file_dir)
412
413 f = open(file_path, 'wb')
414 f.truncate(min(1024 * 1024 * 5, size)) # Only pre-allocate up to 5MB
415 f.close()
416 if os.name == "nt":
417 startupinfo = subprocess.STARTUPINFO()
418 startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
419 subprocess.call(["fsutil", "sparse", "setflag", file_path], close_fds=True, startupinfo=startupinfo)
420
421 if sha512 and sha512 in self.piecefields:
422 self.log.debug("%s: File not exists, but has piecefield. Deleting piecefield." % inner_path)
423 del self.piecefields[sha512]
424
425 def write(self, inner_path, content):
426 if "|" not in inner_path:

Callers 4

writeMethod · 0.95
checkBigfileMethod · 0.95
addTaskMethod · 0.80
testSparseFileMethod · 0.80

Calls 3

getPathMethod · 0.80
callMethod · 0.80
closeMethod · 0.45

Tested by 1

testSparseFileMethod · 0.64