Skip to content

Conversation

jakepetroules
Copy link
Contributor

On all platforms, retrieving the current working directory is a failable operation. When a Configuration is given a null working directory, instead of resolving that to the current working directory at initialization time (which can't be done safely because Configuration.init is non-failable), make Configuration.workingDirectory optional and preserve any nil input through to process creation time. Both CreateProcess (Windows) and posix_spawn or fork/exec (POSIX) inherit the working directory of the calling process if it is not specified, so this doesn't change any behavior.

It also better matches the design of other properties on the Configuration struct like the Executable, which defer resolution of their concrete value rather than doing so at Configuration.init time.

Lastly, it removes incorrect code: the implementation of FilePath.currentWorkingDirectory could crash on POSIX platforms if the current directory was no longer accessible or getcwd failed for any other reason, and on Windows it would not properly support non-ASCII characters in path names nor path names longer than 260 characters.

On all platforms, retrieving the current working directory is a failable operation. When a Configuration is given a null working directory, instead of resolving that to the current working directory at initialization time (which can't be done safely because Configuration.init is non-failable), make Configuration.workingDirectory optional and preserve any nil input through to process creation time. Both CreateProcess (Windows) and posix_spawn or fork/exec (POSIX) inherit the working directory of the calling process if it is not specified, so this doesn't change any behavior.

It also better matches the design of other properties on the Configuration struct like the Executable, which defer resolution of their concrete value rather than doing so at Configuration.init time.

Lastly, it removes incorrect code: the implementation of FilePath.currentWorkingDirectory could crash on POSIX platforms if the current directory was no longer accessible or getcwd failed for any other reason, and on Windows it would not properly support non-ASCII characters in path names nor path names longer than 260 characters.
@jakepetroules jakepetroules merged commit 80bd50f into swiftlang:main Jun 13, 2025
21 checks passed
@jakepetroules jakepetroules deleted the fix-working-directory branch June 13, 2025 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants