-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export samefile, make it smarter for nonexistent inputs #9436
Comments
Copying my comment from the other issue. As this seems really tricky, and can vary depending on the filesystem, it looks like it's best to actually try to open files (when checking whether a file already exists) or compare their inodes (when checking for equality), instead of trying to normalize paths:
|
I'm blind. We already have a Line 117 in 98ce78b
We should just be conscious of when to use it, try to keep it in mind, see if we're doing path comparisons anywhere without realizing this potential gotcha. |
Sorry, I was vaguely following this and kind of confused. Didn't realized that samefile was not exported – it should be. |
As mentioned here #9376 (comment) |
Indeed. But contrary to what @staticfloat said there, I think path normalization is too brittle, as rules vary even depending on the filesystem the file is on. Python's So the only reliable way to find out if two non-existent files are (would be) the same is to create one of them, and remove it afterwards. That may be a bit too many operations happening behind the scenes. A smarter solution would be to fail only when none of the two files exist. If one of them exists, and |
I think that |
I'm fine with that too. People can just create the files and then call |
If one is willing to take it that far, that's the ultimate test if two paths are the same on a given file system. |
Well the |
Agreed with @tkelman on all counts. Also, I hadn't really thought through the problems with nonexistant files once things like symlinks are considered, it's entirely possible that |
on linux, on windows, |
That's a fair point that if one exists while the other doesn't it's safe to just return |
@vtjnash that case was only supposed to be considered when neither file exists. |
i think Stefan made a good point that it isn't called |
Yep, let's just leave it that if EITHER file doesn't exist, (including the case where BOTH don't exist) we return false. |
I'd prefer an exception to be raised. Else people may not realize that if they create both files, they may end up being the same, and that can create terrible security bugs. |
samefile is never valid as a security check (effectively, it's only |
this is somewhat improved by fec7ef1 (now returns false if either input does not exist), but |
Looks like a good candidate for the "intro issue" label (it was already "up for grabs"). |
Just realized at #9376 (comment) that anywhere we do file path comparisons is potentially very error-prone on case-insensitive filesystems. We have
realpath
andnormpath
which look similar but are implemented differently, and neither appear to be doing anything about case. Should we have a special string literal specifically for file paths that has comparison defined? Or a differently-named function to compare if file paths point to the same thing?normalize_string
withcasefold=true
might be the sane thing to use here, but do we currently have an API for determining whether the file system is case sensitive? On Mac it's configurable so can't always be assumed one way or the other, right?The text was updated successfully, but these errors were encountered: