mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-07-06 14:41:11 +08:00
Truncate file to 0 before restarting.
This commit is contained in:
parent
dd6258c9c3
commit
72e081933a
@ -361,9 +361,13 @@ class DownloadJob:
|
|||||||
"GET", self.spec.url, credential_id=self.spec.credential_id, headers=headers
|
"GET", self.spec.url, credential_id=self.spec.credential_id, headers=headers
|
||||||
) as (resp, _final):
|
) as (resp, _final):
|
||||||
if offset > 0 and resp.status == 200:
|
if offset > 0 and resp.status == 200:
|
||||||
# Resume not honoured -> start over from the beginning.
|
# Resume not honoured -> start over from the beginning. Truncate
|
||||||
|
# the existing partial so stale trailing bytes from the prior
|
||||||
|
# attempt cannot survive past the new (possibly shorter) end.
|
||||||
offset = 0
|
offset = 0
|
||||||
seg.bytes_done = 0
|
seg.bytes_done = 0
|
||||||
|
self.state.bytes_done = 0
|
||||||
|
await self._writer.truncate(0)
|
||||||
elif offset > 0 and resp.status != 206:
|
elif offset > 0 and resp.status != 206:
|
||||||
self._raise_for_status(resp.status)
|
self._raise_for_status(resp.status)
|
||||||
elif offset == 0 and resp.status != 200:
|
elif offset == 0 and resp.status != 200:
|
||||||
|
|||||||
@ -43,6 +43,14 @@ class FileWriter:
|
|||||||
_EXECUTOR, os.ftruncate, self._fd, size
|
_EXECUTOR, os.ftruncate, self._fd, size
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def truncate(self, size: int = 0) -> None:
|
||||||
|
"""Truncate the file to ``size`` bytes (default: empty it)."""
|
||||||
|
if self._fd is None:
|
||||||
|
return
|
||||||
|
await asyncio.get_running_loop().run_in_executor(
|
||||||
|
_EXECUTOR, os.ftruncate, self._fd, size
|
||||||
|
)
|
||||||
|
|
||||||
async def write_at(self, offset: int, data: bytes) -> None:
|
async def write_at(self, offset: int, data: bytes) -> None:
|
||||||
assert self._fd is not None, "writer not opened"
|
assert self._fd is not None, "writer not opened"
|
||||||
await asyncio.get_running_loop().run_in_executor(
|
await asyncio.get_running_loop().run_in_executor(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user