@@ -158,14 +158,36 @@ def update_cli():
158158 console .print (f"[info]Target installation path: { current_exe } [/info]" )
159159
160160 download_url = asset ["browser_download_url" ]
161- temp_file = Path (f"/tmp/portabase_update" ) if system != "windows" else Path (f"{ current_exe } .new" )
161+ import tempfile
162+ # Create a temporary file that won't have permission issues or conflicts
163+ fd , temp_path = tempfile .mkstemp (prefix = "portabase_update_" )
164+ temp_file = Path (temp_path )
165+ os .close (fd )
162166
163- with console . status ( f"[bold magenta]Downloading { asset_name } ...[/bold magenta]" ) :
164- response = requests .get (download_url , stream = True )
167+ try :
168+ response = requests .get (download_url , stream = True , timeout = 15 )
165169 response .raise_for_status ()
166- with open (temp_file , "wb" ) as f :
167- for chunk in response .iter_content (chunk_size = 8192 ):
168- f .write (chunk )
170+ total_size = int (response .headers .get ('content-length' , 0 ))
171+
172+ from rich .progress import Progress , SpinnerColumn , TextColumn , BarColumn , DownloadColumn , TransferSpeedColumn
173+
174+ with Progress (
175+ SpinnerColumn (),
176+ TextColumn ("[progress.description]{task.description}" ),
177+ BarColumn (),
178+ DownloadColumn (),
179+ TransferSpeedColumn (),
180+ console = console
181+ ) as progress :
182+ task = progress .add_task (f"Downloading { asset_name } ..." , total = total_size )
183+ with open (temp_file , "wb" ) as f :
184+ for chunk in response .iter_content (chunk_size = 8192 ):
185+ if chunk :
186+ f .write (chunk )
187+ progress .update (task , advance = len (chunk ))
188+ except Exception as e :
189+ if temp_file .exists (): temp_file .unlink ()
190+ raise e
169191
170192 if system != "windows" :
171193 temp_file .chmod (0o755 )
0 commit comments