| 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: |