Repository navigation
fix(server): macOS service keeps its privacy grants across updates #34450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+221
−21
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
58de11d
test(server): reproduce #17225 launch agent program path changing per…
juliusmarminge 46604ac
fix(server): macOS launch agent keeps one program path across updates
juliusmarminge f15a4a6
fix(server): macOS launcher swap survives interruption and clones on …
juliusmarminge 4fabb88
fix(server): overlapping macOS installs keep a complete launcher
juliusmarminge f4af379
docs: macOS Full Disk Access for the service carries over updates
juliusmarminge 7a90b56
docs: note the one-time macOS re-grant when the service moves to its …
juliusmarminge 4c04c00
Merge remote-tracking branch 'origin/main' into fix/issue-17225
juliusmarminge d68d95a
test(server): hoist orDie in the boot service runner fake and drop a …
juliusmarminge 94871ad
Merge remote-tracking branch 'origin/main' into fix/issue-17225
juliusmarminge 5a7ddad
test(server): fold the duplicate launch agent path assertion into one…
juliusmarminge 83c66af
fix(server): swap only the macOS launcher executable so its path neve…
juliusmarminge a3f8003
Merge remote-tracking branch 'origin/main' into fix/issue-17225
tsukinoko-kun f334e1d
fix(server): hold the unit lease through launcher publish and removal
tsukinoko-kun 077930d
fix(server): finish uninstall removal before releasing the unit lease
tsukinoko-kun 011900a
Merge remote-tracking branch 'origin/main' into fix/issue-17225
juliusmarminge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // @effect-diagnostics nodeBuiltinImport:off -- Shared with the standalone launcher, which has no Effect runtime. | ||
| import * as NodeChildProcess from "node:child_process"; | ||
| import * as NodeFSP from "node:fs/promises"; | ||
| import * as NodePath from "node:path"; | ||
|
|
||
| /** | ||
| * macOS TCC keys a launch agent's privacy grants to its program path, so launchd starts a copy | ||
| * of the selected runtime's executable kept here. `__service-launcher` loads only Node built-ins, | ||
| * so the executable alone is the launcher. | ||
| */ | ||
| export const stableLauncherPaths = (baseDir: string) => { | ||
| const directory = NodePath.join(baseDir, "runtime", "launcher"); | ||
| return { | ||
| directory, | ||
| entryPath: NodePath.join(directory, "t3"), | ||
| sentinelPath: NodePath.join(directory, ".install-complete"), | ||
| }; | ||
| }; | ||
|
|
||
| // /bin/cp -c clones on APFS; Node's copyFile copies every byte on macOS. | ||
| const cloneFile = (source: string, destination: string) => | ||
| new Promise<boolean>((resolve) => { | ||
| NodeChildProcess.execFile( | ||
| "/bin/cp", | ||
| ["-c", "-p", source, destination], | ||
| { timeout: 60_000 }, | ||
| (error) => resolve(error === null), | ||
| ); | ||
| }); | ||
|
|
||
| /** | ||
| * Callers hold the unit's selection lease. Each file is renamed over its predecessor, so the | ||
| * program path never goes missing and a running launcher keeps its old inode. | ||
| */ | ||
| export async function publishStableLauncher( | ||
| baseDir: string, | ||
| sourceEntryPath: string, | ||
| version: string, | ||
| ): Promise<void> { | ||
| const paths = stableLauncherPaths(baseDir); | ||
| const stagedEntry = NodePath.join(paths.directory, ".t3.staged"); | ||
| const stagedSentinel = NodePath.join(paths.directory, ".install-complete.staged"); | ||
| await NodeFSP.mkdir(paths.directory, { recursive: true }); | ||
| try { | ||
| await NodeFSP.rm(stagedEntry, { force: true }); | ||
| if (!(await cloneFile(sourceEntryPath, stagedEntry))) { | ||
| await NodeFSP.copyFile(sourceEntryPath, stagedEntry); | ||
| } | ||
| await NodeFSP.writeFile(stagedSentinel, `${version}\n`); | ||
| await syncPath(stagedEntry); | ||
| await syncPath(stagedSentinel); | ||
| await NodeFSP.rename(stagedEntry, paths.entryPath); | ||
| await NodeFSP.rename(stagedSentinel, paths.sentinelPath); | ||
| await syncPath(paths.directory); | ||
| } finally { | ||
| await NodeFSP.rm(stagedEntry, { force: true }); | ||
| await NodeFSP.rm(stagedSentinel, { force: true }); | ||
| } | ||
| } | ||
|
|
||
| // The unit is written durably right after this, so the program it names must be too. | ||
| async function syncPath(filePath: string): Promise<void> { | ||
| const handle = await NodeFSP.open(filePath, "r"); | ||
| try { | ||
| await handle.sync(); | ||
| } finally { | ||
| await handle.close(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.