@@ -206,15 +206,19 @@ async def download_url(self, url, outfile=None):
206206 except Exception as e :
207207 print (f"Waiting for response.content.read of next chunk got error: { e } " )
208208 tries_left -= 1
209- #print(f"Downloaded chunk: {chunk}")
210- if not chunk :
209+ if tries_left == 0 :
211210 print ("ERROR: failed to download chunk, even with retries!" )
212211 return False
213- #print("writing chunk...")
214- fd .write (chunk )
215- #print("wrote chunk")
216- print (f"Done downloading { url } " )
217- return True
212+ else :
213+ print (f"Downloaded chunk: { chunk } " )
214+ if chunk :
215+ #print("writing chunk...")
216+ fd .write (chunk )
217+ #print("wrote chunk")
218+ else :
219+ print ("chunk is None while there was no error so this was the last one" )
220+ print (f"Done downloading { url } " )
221+ return True
218222 except Exception as e :
219223 print (f"download_url got exception { e } " )
220224 return False
@@ -504,6 +508,7 @@ async def download_and_install(self, zip_url, dest_folder, app_fullname):
504508 await TaskManager .sleep (1 ) # seems silly but otherwise it goes so quickly that the user can't tell something happened and gets confused
505509 # Download the .mpk file to temporary location
506510 try :
511+ # Make sure there's no leftover file filling the storage
507512 os .remove (temp_zip_path )
508513 except Exception :
509514 pass
@@ -514,18 +519,19 @@ async def download_and_install(self, zip_url, dest_folder, app_fullname):
514519 self .progress_bar .set_value (40 , True )
515520 temp_zip_path = "tmp/temp.mpk"
516521 print (f"Downloading .mpk file from: { zip_url } to { temp_zip_path } " )
517- try :
518- result = await self .appstore .download_url (zip_url , outfile = temp_zip_path )
519- if result is not True :
520- print ("Download failed..." )
521- self .set_install_label (app_fullname )
522+ result = await self .appstore .download_url (zip_url , outfile = temp_zip_path )
523+ if result is not True :
524+ print ("Download failed..." ) # Would be good to show an error to the user if this failed...
525+ else :
522526 self .progress_bar .set_value (60 , True )
523527 print ("Downloaded .mpk file, size:" , os .stat (temp_zip_path )[6 ], "bytes" )
524- except Exception as e :
525- print ("Download failed:" , str (e ))
526- # Would be good to show error message here if it fails...
527- # Step 2: install it:
528- PackageManager .install_mpk (temp_zip_path , dest_folder ) # ERROR: temp_zip_path might not be set if download failed!
528+ # Install it:
529+ PackageManager .install_mpk (temp_zip_path , dest_folder )
530+ # Make sure there's no leftover file filling the storage:
531+ try :
532+ os .remove (temp_zip_path )
533+ except Exception :
534+ pass
529535 # Success:
530536 await TaskManager .sleep (1 ) # seems silly but otherwise it goes so quickly that the user can't tell something happened and gets confused
531537 self .progress_bar .set_value (100 , False )
0 commit comments