|  |  | @ -73,6 +73,11 @@ def unsparsify(f: StreamingDecompressor) -> Generator[bytes, None, None]: | 
			
		
	
		
		
			
				
					
					|  |  |  |     else: |  |  |  |     else: | 
			
		
	
		
		
			
				
					
					|  |  |  |       raise Exception("Unhandled sparse chunk type") |  |  |  |       raise Exception("Unhandled sparse chunk type") | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | # noop wrapper with same API as unsparsify() for non sparse images | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | def noop(f: StreamingDecompressor) -> Generator[bytes, None, None]: | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   while not f.eof: | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     yield f.read(1024 * 1024) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | def get_target_slot_number() -> int: |  |  |  | def get_target_slot_number() -> int: | 
			
		
	
		
		
			
				
					
					|  |  |  |   current_slot = subprocess.check_output(["abctl", "--boot_slot"], encoding='utf-8').strip() |  |  |  |   current_slot = subprocess.check_output(["abctl", "--boot_slot"], encoding='utf-8').strip() | 
			
		
	
	
		
		
			
				
					|  |  | @ -141,22 +146,20 @@ def flash_partition(target_slot_number: int, partition: dict, cloudlog): | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   path = get_partition_path(target_slot_number, partition) |  |  |  |   path = get_partition_path(target_slot_number, partition) | 
			
		
	
		
		
			
				
					
					|  |  |  |   with open(path, 'wb+') as out: |  |  |  |   with open(path, 'wb+') as out: | 
			
		
	
		
		
			
				
					
					|  |  |  |     partition_size = partition['size'] |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     # Flash partition |  |  |  |     # Flash partition | 
			
		
	
		
		
			
				
					
					|  |  |  |     if partition['sparse']: |  |  |  |     last_p = 0 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       raw_hash = hashlib.sha256() |  |  |  |     raw_hash = hashlib.sha256() | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       for chunk in unsparsify(downloader): |  |  |  |     f = unsparsify if partition['sparse'] else noop | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         raw_hash.update(chunk) |  |  |  |     for chunk in f(downloader): | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         out.write(chunk) |  |  |  |       raw_hash.update(chunk) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         p = int(out.tell() / partition_size * 100) |  |  |  |       out.write(chunk) | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       p = int(out.tell() / partition['size'] * 100) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       if p != last_p: | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         last_p = p | 
			
		
	
		
		
			
				
					
					|  |  |  |         print(f"Installing {partition['name']}: {p}") |  |  |  |         print(f"Installing {partition['name']}: {p}") | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |       if raw_hash.hexdigest().lower() != partition['hash_raw'].lower(): |  |  |  |     if raw_hash.hexdigest().lower() != partition['hash_raw'].lower(): | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         raise Exception(f"Unsparse hash mismatch '{raw_hash.hexdigest().lower()}'") |  |  |  |       raise Exception(f"Raw hash mismatch '{raw_hash.hexdigest().lower()}'") | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     else: |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |       while not downloader.eof: |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         out.write(downloader.read(1024 * 1024)) |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     if downloader.sha256.hexdigest().lower() != partition['hash'].lower(): |  |  |  |     if downloader.sha256.hexdigest().lower() != partition['hash'].lower(): | 
			
		
	
		
		
			
				
					
					|  |  |  |       raise Exception("Uncompressed hash mismatch") |  |  |  |       raise Exception("Uncompressed hash mismatch") | 
			
		
	
	
		
		
			
				
					|  |  | 
 |