Fix inconsistent link_path behavior #194
Merged
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.
When calling
path
on a file using the local transport, it would call Train::Extras::LinuxFile.path which would in turn call read_target_path if the file was a symlink (which calls thereadlink
OS program). The return value would be stored in@link_path
which is then returned wheneverlink_path
is called on the file.readlink
does not operate the same way on macOS like it does on Linux variants. Specifically, in the case of cascading symlinks (a -> b -> c), it will return "c" on Linux but "b" on macOS. This leads to inconsistent behavior depending on if you callpath
beforelink_path
sincepath
stores a value in@link_path
. For example:Example 1 (calling path before link_path):
Example 2 (calling link_path before path):
Plus, we have the Ruby stdlib calls we can and should use when local so Windows, Linux, and macOS users have a consistent experience. Therefore, this change implements a
path
method override on the Local File class to avoid LinuxFile from getting in the way.