forked from ghostty-org/ghostty
-
Notifications
You must be signed in to change notification settings - Fork 6
Guard macOS restore paths for deleted worktrees #3
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 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fab00e9
Guard restored cwd paths from missing worktrees
nicosuave 51b2821
Disable vouch checks and tighten restore path rules
nicosuave 2b89649
Run CI on GitHub-hosted runners in ghostree
nicosuave f932354
Remove Namespace cache steps from hosted CI
nicosuave 93918cb
Use writable Zig cache dirs on hosted runners
nicosuave 6f61cfd
Use workspace Zig cache dirs for hosted CI
nicosuave 4673002
Skip upstream-only policy checks in ghostree CI
nicosuave 8b545a5
Fix Ghostree CI macOS and workflow auth failures
nicosuave f0f4a97
Re-enable full CI jobs in ghostree workflows
nicosuave ea87cc1
Normalize Zig cache paths in check-zig-cache script
nicosuave e18708d
nix: force absolute cache env for zon2nix
nicosuave 97a4f44
nix: patch zon2nix cache path access
nicosuave 707822e
nix: format devShell with alejandra style
nicosuave e70fb40
nix: apply alejandra formatting
nicosuave ac8955e
macos: fix permission response typo pattern
nicosuave c4116c9
ci: fix workflow failures on fork
nicosuave 197e953
ci: fix prettier and swiftlint runner compatibility
nicosuave 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
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,27 @@ | ||
| import Foundation | ||
|
|
||
| enum RestorablePath { | ||
| static func normalizedExistingDirectoryPath(_ path: String?) -> String? { | ||
| guard let path else { return nil } | ||
| let standardized = URL(fileURLWithPath: path).standardizedFileURL.path | ||
| var isDirectory: ObjCBool = false | ||
| guard FileManager.default.fileExists(atPath: standardized, isDirectory: &isDirectory), | ||
| isDirectory.boolValue else { | ||
| return nil | ||
| } | ||
|
|
||
| return standardized | ||
| } | ||
|
|
||
| static func existingDirectoryURL(_ url: URL?) -> URL? { | ||
| guard let url else { return nil } | ||
| let standardized = url.standardizedFileURL | ||
| var isDirectory: ObjCBool = false | ||
| guard FileManager.default.fileExists(atPath: standardized.path, isDirectory: &isDirectory), | ||
| isDirectory.boolValue else { | ||
| return nil | ||
| } | ||
|
|
||
| return standardized | ||
| } | ||
| } | ||
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,43 @@ | ||
| import Foundation | ||
| import Testing | ||
| @testable import Ghostree | ||
|
|
||
| struct RestorablePathTests { | ||
| @Test func normalizedExistingDirectoryPathReturnsStandardizedDirectory() async throws { | ||
| let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true) | ||
| let directory = root.appendingPathComponent("worktree", isDirectory: true) | ||
| try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true) | ||
| defer { try? FileManager.default.removeItem(at: root) } | ||
|
|
||
| let input = directory.appendingPathComponent("..", isDirectory: true) | ||
| .appendingPathComponent("worktree", isDirectory: true).path | ||
| let result = RestorablePath.normalizedExistingDirectoryPath(input) | ||
|
|
||
| #expect(result == directory.standardizedFileURL.path) | ||
| } | ||
|
|
||
| @Test func normalizedExistingDirectoryPathRejectsMissingOrFilePaths() async throws { | ||
| let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true) | ||
| try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true) | ||
| defer { try? FileManager.default.removeItem(at: root) } | ||
|
|
||
| let missing = root.appendingPathComponent("missing", isDirectory: true).path | ||
| #expect(RestorablePath.normalizedExistingDirectoryPath(missing) == nil) | ||
|
|
||
| let file = root.appendingPathComponent("file.txt") | ||
| try "x".write(to: file, atomically: true, encoding: .utf8) | ||
| #expect(RestorablePath.normalizedExistingDirectoryPath(file.path) == nil) | ||
| } | ||
|
|
||
| @Test func existingDirectoryURLReturnsOnlyExistingDirectoryURLs() async throws { | ||
| let root = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true) | ||
| try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true) | ||
| defer { try? FileManager.default.removeItem(at: root) } | ||
|
|
||
| let existing = RestorablePath.existingDirectoryURL(root) | ||
| #expect(existing?.path == root.standardizedFileURL.path) | ||
|
|
||
| let missing = root.appendingPathComponent("gone", isDirectory: true) | ||
| #expect(RestorablePath.existingDirectoryURL(missing) == nil) | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
normalizedExistingDirectoryPathstandardizes the input before checking existence, which can turn an invalid path into a valid parent (for example,"/tmp/missing/../"becomes"/tmp"and passes). Because this helper is now used for restoring and persisting pwd/worktree state, malformed or stale paths containing..can be silently accepted as a different directory instead of being rejected, undermining the deleted-worktree guard.Useful? React with 👍 / 👎.