mirror of
https://github.com/derrod/legendary.git
synced 2024-12-22 01:45:28 +00:00
[downloader] Fix patching games with reused chunks
This commit is contained in:
parent
a2197aec12
commit
c9961f4435
|
@ -146,12 +146,16 @@ class DLManager(Process):
|
|||
break
|
||||
continue
|
||||
|
||||
while task.chunk_guid in in_buffer:
|
||||
while (task.chunk_guid in in_buffer) or task.chunk_file:
|
||||
if task.chunk_file: # re-using from an old file
|
||||
res_shm = None
|
||||
else:
|
||||
res = in_buffer[task.chunk_guid]
|
||||
res_shm = res.shm
|
||||
|
||||
try:
|
||||
self.writer_queue.put(WriterTask(
|
||||
filename=current_file, shared_memory=res.shm,
|
||||
filename=current_file, shared_memory=res_shm,
|
||||
chunk_offset=task.chunk_offset, chunk_size=task.chunk_size,
|
||||
chunk_guid=task.chunk_guid, release_memory=task.cleanup,
|
||||
old_file=task.chunk_file # todo on-disk cache
|
||||
|
@ -160,7 +164,7 @@ class DLManager(Process):
|
|||
self.log.warning(f'Adding to queue failed: {e!r}')
|
||||
break
|
||||
|
||||
if task.cleanup:
|
||||
if task.cleanup and not task.chunk_file:
|
||||
del in_buffer[task.chunk_guid]
|
||||
|
||||
try:
|
||||
|
|
|
@ -172,7 +172,7 @@ class FileWorker(Process):
|
|||
continue
|
||||
|
||||
try:
|
||||
os.rename(os.path.join(self.base_path, j.temporary_filename), full_path)
|
||||
os.rename(os.path.join(self.base_path, j.old_filename), full_path)
|
||||
except OSError as e:
|
||||
self.log.error(f'Renaming file failed: {e!r}')
|
||||
self.o_q.put(WriterTaskResult(success=False, filename=j.filename))
|
||||
|
@ -212,7 +212,7 @@ class FileWorker(Process):
|
|||
post_write = time.time()
|
||||
elif j.old_file:
|
||||
pre_write = time.time()
|
||||
with open(os.path.join(self.base_path, j.cache_file), 'rb') as f:
|
||||
with open(os.path.join(self.base_path, j.old_file), 'rb') as f:
|
||||
if j.chunk_offset:
|
||||
f.seek(j.chunk_offset)
|
||||
current_file.write(f.read(j.chunk_size))
|
||||
|
|
Loading…
Reference in a new issue