Repository navigation
fix(server): symlinked settings stay linked when saved #73
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8aadb0b
fix(server): symlinked settings stay linked when saved
yordis ef6a531
docs(fork): link the symlinked settings entry to its pull request
yordis 23d648b
test(server): settings saves keep a symlinked file linked
yordis 69c725a
fix(server): dangling settings links stay linked and linked edits sti…
yordis 65ddbf9
fix(server): settings reload when a dangling link gets its destination
yordis 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import * as NodeServices from "@effect/platform-node/NodeServices"; | ||
| import { assert, it } from "@effect/vitest"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as FileSystem from "effect/FileSystem"; | ||
| import * as Path from "effect/Path"; | ||
|
|
||
| import { writeFileStringAtomically } from "./atomicWrite.ts"; | ||
|
|
||
| it.layer(NodeServices.layer)("writeFileStringAtomically", (it) => { | ||
| it.effect("keeps a symlinked file linked and rewrites its destination", () => | ||
| Effect.gen(function* () { | ||
| const fs = yield* FileSystem.FileSystem; | ||
| const path = yield* Path.Path; | ||
| const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-atomic-write-" }); | ||
| const destination = path.join(root, "dotfiles", "settings.json"); | ||
| const link = path.join(root, "home", "settings.json"); | ||
| yield* fs.makeDirectory(path.dirname(destination), { recursive: true }); | ||
| yield* fs.makeDirectory(path.dirname(link), { recursive: true }); | ||
| yield* fs.writeFileString(destination, "before"); | ||
| yield* fs.symlink(destination, link); | ||
|
|
||
| yield* writeFileStringAtomically({ filePath: link, contents: "after" }); | ||
|
|
||
| assert.strictEqual(yield* fs.readLink(link), destination); | ||
| assert.strictEqual(yield* fs.readFileString(destination), "after"); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("keeps a dangling symlink linked and creates its destination", () => | ||
| Effect.gen(function* () { | ||
| const fs = yield* FileSystem.FileSystem; | ||
| const path = yield* Path.Path; | ||
| const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-atomic-write-" }); | ||
| const destination = path.join(root, "dotfiles", "settings.json"); | ||
| const link = path.join(root, "home", "settings.json"); | ||
| yield* fs.makeDirectory(path.dirname(link), { recursive: true }); | ||
| yield* fs.symlink(destination, link); | ||
|
|
||
| yield* writeFileStringAtomically({ filePath: link, contents: "fresh" }); | ||
|
|
||
| assert.strictEqual(yield* fs.readLink(link), destination); | ||
| assert.strictEqual(yield* fs.readFileString(destination), "fresh"); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("creates a missing file and its directory", () => | ||
| Effect.gen(function* () { | ||
| const fs = yield* FileSystem.FileSystem; | ||
| const path = yield* Path.Path; | ||
| const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-atomic-write-" }); | ||
| const filePath = path.join(root, "nested", "settings.json"); | ||
|
|
||
| yield* writeFileStringAtomically({ filePath, contents: "fresh" }); | ||
|
|
||
| assert.strictEqual(yield* fs.readFileString(filePath), "fresh"); | ||
| }), | ||
| ); | ||
| }); |
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
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,31 @@ | ||
| # 0027: Symlinked settings stay linked | ||
|
|
||
| - PR: [TrogonStack/t3code#73](https://github.com/TrogonStack/t3code/pull/73) | ||
| - Status: active | ||
|
|
||
| ## What you can do now | ||
|
|
||
| - Keep T3 Code's settings in a dotfiles repository and link them into the T3 | ||
| home. Changing a setting in the app writes through the link, so the | ||
| repository copy is always the one in use. | ||
| - Edit settings from the app as often as you like without the link quietly | ||
| turning into a standalone copy that the repository no longer sees. | ||
|
|
||
| ## Why | ||
|
|
||
| Saving settings used to replace a linked file with a regular one. Nothing | ||
| failed and the app kept working, so the first sign was a later discovery that | ||
| the repository and the machine had drifted apart, with no record of which | ||
| changes happened where. Configuration that was supposed to be versioned had | ||
| stopped being versioned on the first save. | ||
|
|
||
| That silence is the reason to fix it rather than document it. A setup that | ||
| breaks loudly gets fixed on the spot; one that detaches without a trace costs | ||
| a reconciliation session weeks later, after the two copies have each picked up | ||
| changes the other lacks. | ||
|
|
||
| ## Upstream considerations | ||
|
|
||
| A clean upstream submission. Writes still land atomically, nothing changes for | ||
| anyone who does not use links, and the behavior is what a user who links a | ||
| config file expects. Once an equivalent lands upstream, this entry goes. |
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.
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.