From 37cdfac6b9bd42f85b74f2f36d0959f02efa4506 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Mon, 17 Feb 2020 18:49:33 +0100 Subject: Codesign: Harden check for archive being ready for sign Seems like sometimes files are being only partially ready, which makes it so there are unsigned files, failing to deliver fully signed bundle. Now expected archive file size is stored into stamp file and is checked against size of the archive file on another side. There are some bare prints used for debugging, would need to switch it to a proper logger (or to be removed). --- .../buildbot/codesign/archive_with_indicator.py | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'build_files/buildbot/codesign') diff --git a/build_files/buildbot/codesign/archive_with_indicator.py b/build_files/buildbot/codesign/archive_with_indicator.py index ad3fe1c6ac7..d1af207df83 100644 --- a/build_files/buildbot/codesign/archive_with_indicator.py +++ b/build_files/buildbot/codesign/archive_with_indicator.py @@ -74,12 +74,35 @@ class ArchiveWithIndicator: """Check whether the archive is ready for access.""" if not self.ready_indicator_filepath.exists(): return False + # Sometimes on macOS indicator file appears prior to the actual archive # despite the order of creation and os.sync() used in tag_ready(). # So consider archive not ready if there is an indicator without an # actual archive. if not self.archive_filepath.exists(): + print('Found indicator without actual archive, waiting for archive ' + f'({self.archive_filepath}) to appear.') + return False + + # Read archive size from indicator/ + # + # Assume that file is either empty or is fully written. This is being checked + # by performing ValueError check since empty string will throw this exception + # when attempted to be converted to int. + expected_archive_size_str = self.ready_indicator_filepath.read_text() + try: + expected_archive_size = int(expected_archive_size_str) + except ValueError: + print(f'Invalid archive size "{expected_archive_size_str}"') return False + + # Wait for until archive is fully stored. + actual_archive_size = self.archive_filepath.stat().st_size + if actual_archive_size != expected_archive_size: + print('Partial/invalid archive size (expected ' + f'{expected_archive_size} got {actual_archive_size})') + return False + return True def tag_ready(self) -> None: @@ -96,7 +119,8 @@ class ArchiveWithIndicator: # an actual file. if util.get_current_platform() != util.Platform.WINDOWS: os.sync() - self.ready_indicator_filepath.touch() + archive_size = self.archive_filepath.stat().st_size + self.ready_indicator_filepath.write_text(str(archive_size)) def clean(self) -> None: """ -- cgit v1.2.3