Codesign: Make file watcher robust for network errors

This commit is contained in:
Sergey Sharybin 2020-02-21 11:00:11 +01:00
parent 973982a8e5
commit 1f8f4c8cfe
Notes: blender-bot 2023-02-14 07:39:46 +01:00
Referenced by issue #74074, Sculpt Mode: Airbrush stroke type stops after initialization
1 changed files with 26 additions and 2 deletions

View File

@ -70,8 +70,12 @@ class ArchiveWithIndicator:
self.archive_filepath = self.base_dir / archive_name
self.ready_indicator_filepath = self.base_dir / ready_indicator_name
def is_ready(self) -> bool:
"""Check whether the archive is ready for access."""
def is_ready_unsafe(self) -> bool:
"""
Check whether the archive is ready for access.
No guarding about possible network failres is done here.
"""
if not self.ready_indicator_filepath.exists():
return False
@ -105,6 +109,26 @@ class ArchiveWithIndicator:
return True
def is_ready(self) -> bool:
"""
Check whether the archive is ready for access.
Will tolerate possible network failures: if there is a network failure
or if there is still no proper permission on a file False is returned.
"""
# There are some intermitten problem happening at a random which is
# translates to "OSError : [WinError 59] An unexpected network error occurred".
# Some reports suggests it might be due to lack of permissions to the file,
# which might be applicable in our case since it's possible that file is
# initially created with non-accessible permissions and gets chmod-ed
# after initial creation.
try:
return self.is_ready_unsafe()
except OSError as e:
print(f'Exception checking archive: {e}')
return False
def tag_ready(self) -> None:
"""
Tag the archive as ready by creating the corresponding indication file.