diff --git a/container b/container index d4f148434..d5141e5a5 100755 --- a/container +++ b/container @@ -689,10 +689,27 @@ def _verify_signature(hkp_client: str, data_file: pathlib.Path, def _extract_image(compressed_file: pathlib.Path): """Extract the image file.""" - decompressed_file = compressed_file.with_suffix('') + # Strip the .xz extension, then replace .img with .raw + decompressed_file = compressed_file.with_suffix('').with_suffix('.raw') + older_image = compressed_file.with_suffix('') + if decompressed_file.exists(): return decompressed_file + # Rename older image and its corresponding state files. + if older_image.exists(): + logger.info('Renaming .img file to .raw') + older_image.rename(decompressed_file) + + for ext in ['.setup', '.provisioned']: + old_state = older_image.with_suffix(older_image.suffix + ext) + new_state = decompressed_file.with_suffix( + decompressed_file.suffix + ext) + if old_state.exists(): + old_state.rename(new_state) + + return decompressed_file + logger.info('Decompressing file %s', compressed_file) partial_file = compressed_file.with_suffix('.partial') with partial_file.open('w', encoding='utf-8') as file_handle: @@ -715,7 +732,8 @@ def _get_compressed_image_path(distribution: str) -> pathlib.Path: def _get_image_file(distribution: str) -> pathlib.Path: """Return the path of the image file.""" compressed_image = _get_compressed_image_path(distribution) - return compressed_image.with_suffix('') + # Strip the .xz extension, then replace .img with .raw + return compressed_image.with_suffix('').with_suffix('.raw') def _get_project_folder() -> pathlib.Path: @@ -1337,9 +1355,8 @@ VirtualEthernet=yes if result.returncode: raise Exception(f'Image file {image_link} is not a symlink.') - subprocess.run(['sudo', 'rm', '--force', - str(image_link)], check=False) - + # May be linked to wrong place (such as old .img file) + subprocess.run(['sudo', 'rm', '--force', str(image_link)], check=False) subprocess.run([ 'sudo', 'ln', '--symbolic', str(image_file.resolve()),