def __exit__(self: 'FileChange', *exc) -> None:
"""Clean up after change -- both success and failure."""
if any(exc): # Failure -- rollback
if self.__valid_destination:
if self.__file_change:
# Ignore missing file on deletion
with suppress(FileNotFoundError):
self.new_path.unlink()
if self.__valid_source:
if self.__file_change:
self.tmp_path.rename(self.old_path)
if self.__store_change:
self.source[self.old_file.mod.id] = self.old_file
else: # Success -- change metadata
if self.__valid_destination:
self.destination[self.new_file.mod.id] = self.new_file
# Clean temporary file
if self.__valid_source and self.__file_change:
self.tmp_path.unlink()
评论列表
文章目录