Skip to content
Python

Mac: no Downloads permission prompt at start

Rohit C Prasadb7b4a87dee0c
diff --git a/coworker/server/manager.py b/coworker/server/manager.py
index 6270aa31..b68ca90c 100644
--- a/coworker/server/manager.py
+++ b/coworker/server/manager.py
@@ -16,6 +16,7 @@ import re
import shlex
import shutil
import subprocess
+import sys
import time
import uuid
from pathlib import Path
@@ -269,6 +270,27 @@ def configured_opening(event, thread_target: str, folder: str) -> str:
return "\n\n".join(lines)
+# macOS asks the user before an app touches Desktop, Documents or Downloads, and even a
+# stat() of a path inside them counts. The recent-folders list is read when the app starts,
+# so one past session in ~/Downloads put up the permission prompt on every launch (owner
+# hit 2026-09-29) although our own prompt text says we never scan those folders. Folders
+# under them are reported as present without looking; opening one checks it for real.
+_MAC_ASKED_FOLDERS = ("Desktop", "Documents", "Downloads")
+
+
+def folder_present(path: str) -> bool:
+ """Whether a remembered folder still exists, without triggering a macOS permission
+ prompt for the folders macOS guards."""
+ p = Path(path).expanduser()
+ if sys.platform == "darwin":
+ home = Path.home()
+ for name in _MAC_ASKED_FOLDERS:
+ guarded = home / name
+ if p == guarded or guarded in p.parents:
+ return True
+ return p.is_dir()
+
+
class SessionManager:
def __init__(
self,
@@ -554,7 +576,7 @@ class SessionManager:
return [
{
**self.workspace_command_trust(path),
- "exists": Path(path).is_dir(),
+ "exists": folder_present(path),
}
for path in self.workspace_trust.list()
]
@@ -572,7 +594,7 @@ class SessionManager:
continue
except OSError:
pass
- out.append({"path": path, "name": p.name, "exists": p.is_dir()})
+ out.append({"path": path, "name": p.name, "exists": folder_present(path)})
return out
DEFAULT_SCRATCH_BASE = "~/OpenWorker"
diff --git a/tests/test_folder_present.py b/tests/test_folder_present.py
new file mode 100644
index 00000000..dd6ab22e
--- /dev/null
+++ b/tests/test_folder_present.py
@@ -0,0 +1,29 @@
+"""The recent-folders list must not make macOS ask about Desktop, Documents or Downloads."""
+
+from pathlib import Path
+
+from coworker.server import manager as manager_mod
+
+
+def test_folders_macos_guards_are_reported_present_without_looking(tmp_path, monkeypatch):
+ monkeypatch.setattr(manager_mod.sys, "platform", "darwin")
+ monkeypatch.setattr(Path, "home", classmethod(lambda cls: tmp_path))
+ looked: list[str] = []
+ real_is_dir = Path.is_dir
+ monkeypatch.setattr(Path, "is_dir", lambda self: looked.append(str(self)) or real_is_dir(self))
+ for name in ("Desktop", "Documents", "Downloads"):
+ assert manager_mod.folder_present(str(tmp_path / name / "project")) is True
+ assert manager_mod.folder_present(str(tmp_path / name)) is True
+ assert looked == [] # never stat()ed: that is what puts the prompt up
+ (tmp_path / "code").mkdir()
+ assert manager_mod.folder_present(str(tmp_path / "code")) is True
+ assert manager_mod.folder_present(str(tmp_path / "gone")) is False
+ assert looked # ordinary folders are still checked
+
+
+def test_elsewhere_every_folder_is_checked(tmp_path, monkeypatch):
+ monkeypatch.setattr(manager_mod.sys, "platform", "linux")
+ monkeypatch.setattr(Path, "home", classmethod(lambda cls: tmp_path))
+ assert manager_mod.folder_present(str(tmp_path / "Downloads" / "project")) is False
+ (tmp_path / "Downloads" / "project").mkdir(parents=True)
+ assert manager_mod.folder_present(str(tmp_path / "Downloads" / "project")) is True