Refactor validateDataPath and fix macOS unit tests #1932
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.
This PR creates a new function
closestCanonicalPaththat behaves likeQDir::canonicalPath, except that it will try to resolve symlinks for the nearest existing directory in the path if the path passed as an argument does not exist. For example, if/symlinkpoints to the directory/target, thenQDir("/symlink/example.txt").canonicalPath()andclosestCanonicalPath("/symlink/example.txt")will both return/target/example.txtif example.txt exists. If it does not exist, thenQDir::canonicalPathwill output an empty string while this new function will still output/target/example.txt.The motivation for this new function is twofold. It can be used to greatly simplify the implementation of
validateDataPath, which was much more complex that it would seem on first glance and I suspect did not handle certain edge cases correctly. Secondly, this new function can be used in some unit tests where comparing file path strings was failing because one or more of the directories were symlinks. Existing canonical path functions could not be used because the actual files were not created for the tests.This supersedes the changes made in #1928 to try to fix the unit tests. In my opinion,
validateDataDiris not the correct function to use in that situation. The intent ofvalidateDataDiris merely to make sure that project file paths do not refer to locations outside of the data directory. But for the failing asserts, what we want to test is that the file path stored in the keyframes points to where the actual files would be located if it was a real project. Equivalent filesystem paths should always resolve to the same string withclosestCanonicalPathand thus should be safe to use string comparison with.