11"""Cross-platform rclone installation utilities."""
22
3+ import os
34import platform
45import shutil
56import subprocess
@@ -116,7 +117,15 @@ def install_rclone_windows() -> None:
116117 if shutil .which ("winget" ):
117118 try :
118119 console .print ("[blue]Installing rclone via winget...[/blue]" )
119- run_command (["winget" , "install" , "Rclone.Rclone" ])
120+ run_command (
121+ [
122+ "winget" ,
123+ "install" ,
124+ "Rclone.Rclone" ,
125+ "--accept-source-agreements" ,
126+ "--accept-package-agreements" ,
127+ ]
128+ )
120129 console .print ("[green]rclone installed via winget[/green]" )
121130 return
122131 except RcloneInstallError :
@@ -165,6 +174,7 @@ def install_rclone(platform_override: Optional[str] = None) -> None:
165174 install_rclone_linux ()
166175 elif platform_name == "windows" :
167176 install_rclone_windows ()
177+ refresh_windows_path ()
168178 else :
169179 raise RcloneInstallError (f"Unsupported platform: { platform_name } " )
170180
@@ -180,6 +190,47 @@ def install_rclone(platform_override: Optional[str] = None) -> None:
180190 raise RcloneInstallError (f"Unexpected error during installation: { e } " ) from e
181191
182192
193+ def refresh_windows_path () -> None :
194+ """Refresh the Windows PATH environment variable for the current session."""
195+ if platform .system ().lower () != "windows" :
196+ return
197+
198+ # Importing here after performing platform detection. Also note that we have to ignore pylance/pyright
199+ # warnings about winreg attributes so that "errors" don't appear on non-Windows platforms.
200+ import winreg
201+
202+ user_key_path = r"Environment"
203+ system_key_path = r"System\CurrentControlSet\Control\Session Manager\Environment"
204+ new_path = ""
205+
206+ # Read user PATH
207+ try :
208+ reg_key = winreg .OpenKey (winreg .HKEY_CURRENT_USER , user_key_path , 0 , winreg .KEY_READ ) # type: ignore[reportAttributeAccessIssue]
209+ user_path , _ = winreg .QueryValueEx (reg_key , "PATH" ) # type: ignore[reportAttributeAccessIssue]
210+ winreg .CloseKey (reg_key ) # type: ignore[reportAttributeAccessIssue]
211+ except Exception :
212+ user_path = ""
213+
214+ # Read system PATH
215+ try :
216+ reg_key = winreg .OpenKey (winreg .HKEY_LOCAL_MACHINE , system_key_path , 0 , winreg .KEY_READ ) # type: ignore[reportAttributeAccessIssue]
217+ system_path , _ = winreg .QueryValueEx (reg_key , "PATH" ) # type: ignore[reportAttributeAccessIssue]
218+ winreg .CloseKey (reg_key ) # type: ignore[reportAttributeAccessIssue]
219+ except Exception :
220+ system_path = ""
221+
222+ # Merge user and system PATHs (system first, then user)
223+ if system_path and user_path :
224+ new_path = system_path + ";" + user_path
225+ elif system_path :
226+ new_path = system_path
227+ elif user_path :
228+ new_path = user_path
229+
230+ if new_path :
231+ os .environ ["PATH" ] = new_path
232+
233+
183234def get_rclone_version () -> Optional [str ]:
184235 """Get the installed rclone version."""
185236 if not is_rclone_installed ():
0 commit comments