Skip to content

Commit c9946ec

Browse files
bdmayesphernandez
andauthored
fix: Various rclone fixes for cloud sync on Windows (#410)
Signed-off-by: Brandon Mayes <[email protected]> Signed-off-by: Paul Hernandez <[email protected]> Signed-off-by: phernandez <[email protected]> Co-authored-by: Paul Hernandez <[email protected]> Co-authored-by: phernandez <[email protected]>
1 parent 0ba6f21 commit c9946ec

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/basic_memory/cli/commands/cloud/bisync_commands.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
"""Cloud bisync utility functions for Basic Memory CLI."""
22

3+
import asyncio
4+
import platform
5+
import subprocess
6+
import time
7+
from datetime import datetime
38
from pathlib import Path
49

510
from basic_memory.cli.commands.cloud.api_client import make_api_request

src/basic_memory/cli/commands/cloud/rclone_installer.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Cross-platform rclone installation utilities."""
22

3+
import os
34
import platform
45
import shutil
56
import 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+
183234
def get_rclone_version() -> Optional[str]:
184235
"""Get the installed rclone version."""
185236
if not is_rclone_installed():

0 commit comments

Comments
 (0)