Fixes to parentDirectory() and abspath()#533
Conversation
…rectory. Also works when the path has trailing slashes.
|
As stated above, I currently have this open against 5.2. I marked it with the 6.0 milestone so it will hopefully get attention while I'm out, but if we don't feel comfortable enough with it by the time we want to make the release, it could be considered for a future patch release. |
# Conflicts: # flow/Platform.cpp
|
I've merged in master and switched the base branch from release-6.0 to master. |
|
It's a bit unclear, and undocumented, exactly what behavior we want from parentDirectory() in context (fdbmonitor and flow/platform). Points to consider,
For inputs that actually exist, using realpath() is a good way to get a canonical path from which a parent can be found easily as it resolves ./ and ../ references and removes trailing and duplicate separators. However, the caller may wish to preserve symbolic links in the input so it can monitor the parent directory symlink for changes (fdbmonitor does this). While parentDirectory exists in fdbmonitor independently from flow/platform, it would be nice if one function definition could satisfy all use cases, perhaps with parameters. And of course there is reason for parentDirectory to work on input strings that do not actually exist on the filesystem. We should probably revisit abspath() behavior as well. Currently, abspath("/blah") returns "/blah" if /blah exists on the filesystem, and otherwise returns "<absolute_path_of_current_working_directory>/blah" which doesn't seem right for any use case. Also, abspath() will not remove trailing separators for paths that do not exist. |
…, or duplicate separators without using the filesystem or resolving symbolic links. absPath() redefined to use cleanPath() so it will return the same result for a path without symbolic links regardless of whether or not the path actually exists. Redefined parentDirectory() to use absPath() and error on certain inputs. Added comments describing behavior of these functions, and added a unit test which verbosely tests many inputs to them.
…mulation, did the same for cleanPath().
|
I've committed a significant refactoring which I think makes absPath() and parentDirectory() behave in sensible ways. They each use a new platform function called cleanPath() which canonicalizes a path without consulting the filesystem. Among the more serious bad behaviors fixed, it is no longer the case that you get a different result for The main thing to review is the unit test at the end of Platform.cpp and its output. I'm certain there are still edge cases to add. For convenience, here is the current output: PASS: cleanPath('') -> '' |
…ix-parent-directory
|
cleanPath() should probably handle '/' as well regardless of what the canonical separator is. On windows, cleanPath() would not work for fully qualified network paths which begin with '\'. |
|
It should probably be the case that |
…ot resolve symbolic links, making it suitable for use in fdbmonitor. CleanPath() will return "." instead of empty string to mean a relative path that refers to the current directory. Updated tests, and added new tests for ".".
…bolic links should be resolved when possible and whether the final resolved path must actually exist on the filesystem. Updated tests, added more cases.
…path() and parentDirectory() implementations from flow.
… prepend current working directory even when not resolving symlinks. Added more unit tests. Ported path operation unit tests to fdbmonitor() since the path manipulation function implementations are significantly different. Clarified some comments. The flow project version of abspath() does not allow resolveLinks to be false, for now, because behavior of this on Windows is not well thought out or tested.
…d commented call to testPathOps() for convenience.
… it only treats ~ as special if it is the first character.
…vable symbolic links.
ajbeamon
left a comment
There was a problem hiding this comment.
The GitHub UI won't let me approve because I originated this PR, but it looks good to me. Feel free to merge when the build checks are finished.
Fixes to parentDirectory() and abspath()
Fixes to parentDirectory() and abspath()
Fixes to parentDirectory() and abspath()
parentDirectory() and abspath() can now optionally resolve symbolic links and/or require the given path to exist. All ".." and "." references will now be fully resolved by both functions even if the path doesn't fully exist (if the mustExist flag allows success in this case). The following inputs are now handled correctly: