Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch enhances the implementation of `Dir.current` on POSIX platforms to respects the environment variable `PWD`. The variable holds the path to the current working directory as entered by the user. This is in accordance with the `pwd` utility. There's a validation in place to check that the value actually points to the current working directory. Without this change, `Dir.current` would typically return the path with any symbolic links resolved and thus disregarding that the user might be in a different path via symbolic links. The change effectively implements the GNU extension `get_current_dir_name` (which is not portable) whereas the previous behaviour was equivalent to the standard `getcwd`. In fact, it is very similar to the [implementation of `get_current_dir_name` in musl](https://git.musl-libc.org/cgit/musl/tree/src/misc/get_current_dir_name.c?id=37e18b7bf307fa4a8c745feebfcba54a0ba74f30). Windows is not affected. The environment variable `PWD` is specific to POSIX. The Window API function `GetCurrentDirectoryW` already returns the path to the current directory as entered by the user and symbolic links are not resolved. The previous behaviour of `Dir.current` is equivalent to `File.real_path(Dir.current)`. `Dir.cd` is unaffected by this change. It does *not* set `$PWD` to the changed directory path.
- Loading branch information