atomic
This commit is contained in:
parent
2dad36e68a
commit
33540964e4
2 changed files with 4 additions and 1 deletions
|
|
@ -389,7 +389,7 @@ class FileHandler:
|
||||||
# This tries to prevent corrupted writes if the processed dies mid-write,
|
# This tries to prevent corrupted writes if the processed dies mid-write,
|
||||||
atomic_dst = f"{dst_file_path}-ytdl-sub-incomplete"
|
atomic_dst = f"{dst_file_path}-ytdl-sub-incomplete"
|
||||||
shutil.copyfile(src=src_file_path, dst=atomic_dst)
|
shutil.copyfile(src=src_file_path, dst=atomic_dst)
|
||||||
shutil.move(src=atomic_dst, dst=src_file_path)
|
shutil.move(src=atomic_dst, dst=dst_file_path)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def move(cls, src_file_path: Union[str, Path], dst_file_path: Union[str, Path]):
|
def move(cls, src_file_path: Union[str, Path], dst_file_path: Union[str, Path]):
|
||||||
|
|
|
||||||
|
|
@ -614,6 +614,8 @@ class EnhancedDownloadArchive:
|
||||||
self.save_file_to_output_directory(
|
self.save_file_to_output_directory(
|
||||||
file_name=self.file_name, output_file_name=self._migrated_file_name, copy_file=True
|
file_name=self.file_name, output_file_name=self._migrated_file_name, copy_file=True
|
||||||
)
|
)
|
||||||
|
FileHandler.delete(file_path=self.working_file_path)
|
||||||
|
|
||||||
# and delete the old one if the name differs
|
# and delete the old one if the name differs
|
||||||
if self._file_name != self._migrated_file_name:
|
if self._file_name != self._migrated_file_name:
|
||||||
self.delete_file_from_output_directory(file_name=self.file_name)
|
self.delete_file_from_output_directory(file_name=self.file_name)
|
||||||
|
|
@ -621,6 +623,7 @@ class EnhancedDownloadArchive:
|
||||||
elif not self.get_file_handler_transaction_log().is_empty:
|
elif not self.get_file_handler_transaction_log().is_empty:
|
||||||
self._download_mapping.to_file(output_json_file=self.working_file_path)
|
self._download_mapping.to_file(output_json_file=self.working_file_path)
|
||||||
self.save_file_to_output_directory(file_name=self.file_name, copy_file=True)
|
self.save_file_to_output_directory(file_name=self.file_name, copy_file=True)
|
||||||
|
FileHandler.delete(file_path=self.working_file_path)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def delete_file_from_output_directory(self, file_name: str):
|
def delete_file_from_output_directory(self, file_name: str):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue