Comments (17)
To reply to myself: https://unix.stackexchange.com/questions/256497/on-what-systems-is-foo-bar-different-from-foo-bar
Appearently Cygwin uses '//share/path' to access UNC shares, as does UWIN. And finally zOS uses '//path' for something implementation defined as well. The page also lists some no longer supported systems which used '//host/path' for networked file systems.
This complicates things...
from cpython.
IMHO we should consider dropping special handling for '//' at the start of a path for our path manipulation APIs. I cannot recall a Unix where '//foo' is different from '/foo', but it is an awfully long time that I've used anything other than Linux and macOS.
The Open Group documents that '//foo' may be special ("may be treated in an implementation defined way"), but AFAIK commonly used UNIX-y systems don't use this possibility.
Because most systems don't treat '//foo' specially we shouldn't change the behaviour of os.path.commonpath
as this will only lead to confusing users and might have a security impact for code that expects the current behaviour.
from cpython.
For reference, the original issue that introduced commonpath()
is bpo-10395/gh-54604.
And its behavior was discussed at https://mail.python.org/archives/list/[email protected]/thread/VHQTSU4ERTH262OPVZ6SEO2EYCFQF56G/.
from cpython.
As I wrote, it's complicated. My gut feeling is that we shouldn't change the behaviour for all platforms because of most platforms the two paths do no have a different meaning.
The platforms with special treatment for double slashes at the start of a path are not on our list of supported platforms, and are not tested in CI. As such we generally don't complicate the code base for them, although Cygwin used to be somewhat popular (but I haven't used Windows or Cygwin in a long time).
Because of this I'm still of the opinion what we should consider dropping specific support for double slashes at the start of paths in os.path
. That's something that needs discussion outside of this issue though, and that might lead to keeping support for this on a specific list of platforms such as Cygwin.
from cpython.
How '//share/path/../../file' is resolved on Cygwin? Is it equal to
/file
or//share/file
? The same question is for other platforms.
I have no idea. On any platform where "//path/subpath" is special the behaviour is implementation defined, and hence not something we can implement generically in CPython.
Perhaps such platforms should have a separate
os.path
andpathlib.Path
implementations. And have more complete support ofnormpath()
,split()
,splitroot()
,commonpath()
etc if//share
is considered a different root.
Probably. That's one more reason to just drop the limited support for this in the stdlib and reconsider when someone proposes to add support for such a platform to CPython. On first glance the only support we have is that normpath
doesn't remove the extraneous slash when there are exactly 2 slashes at the start of the path (introduced in bf222c9). Other path manipulation functions don't check for there double slashes at all.
from cpython.
cc. @ronaldoussoren
from cpython.
This is the reason I don't like the current implementation:
from posixpath import abspath, commonpath, splitdrive
def isparent(path1, path2):
drive1, tail1 = splitdrive(abspath(path1))
drive2, tail2 = splitdrive(abspath(path2))
return drive1 == drive2 and commonpath([tail1, tail2]) == tail1
if isparent("//foo", "//foo/bar"):
print("path1 is a parent of path2")
else:
print("path1 is not a parent of path2")
Output: path1 is not a parent of path2
.
from cpython.
If anything, this looks to me like a commonpath
documentation issue.
Moreover, if I were to write such a test, I would normalise tail1
before comparing it, or more probable: use a higher level API.
from cpython.
If anything, this looks to me like a
commonpath
documentation issue.
If that's the case, that's fine by me, but that should be confirmed by @ronaldoussoren.
Moreover, if I were to write such a test, I would normalise
tail1
before comparing it
The thing is: the paths are already normalised here, but that won't replace precisely 2 leading slashes. Which is intended behaviour.
from cpython.
The thing is: the paths are already normalised here, but that won't eliminate a leading
//
as intended.
splitdrive
does not normalise the paths, if that is what you imply.
from cpython.
No, the paths I'm passing to splitdrive()
are already normalised (I added abspath()
to make that clearer), but I would still need to apply commonpath()
to the tail to make the comparison work. I shouldn't have to do that.
from cpython.
Well, it is still a backwards-incompatible change.
from cpython.
Anyway, whether this will be accepted depends on whether this is intentional behaviour or not:
- If it's intentional, we should document and test this.
- If it isn't, we should document the new behaviour like how
os.path.isabs()
was changed to handle paths correctly starting with exactly one (back)slash on Windows.
from cpython.
Can we rediscuss the behaviour of commonpath(['//foo', '/foo'])
then? As these paths would have a different meaning.
I would prefer to return the empty string in this case as they're both absolute.
from cpython.
OK, then I'll close this issue for the time being. Could you start a discussion about this?
from cpython.
How '//share/path/../../file' is resolved on Cygwin? Is it equal to /file
or //share/file
? The same question is for other platforms.
Perhaps such platforms should have a separate os.path
and pathlib.Path
implementations. And have more complete support of normpath()
, split()
, splitroot()
, commonpath()
etc if //share
is considered a different root.
from cpython.
Other path manipulation functions don't check for there double slashes at all.
posixpath.splitroot()
:
Lines 162 to 164 in 4d4a6f1
The only function that doesn't handle it properly is posixpath.commonpath()
(posixpath.realpath()
works as intended: #117338).
from cpython.
Related Issues (20)
- pyrepl doesn't print result if any part came from paste HOT 2
- venv tutorial wrong/confusing about python version used HOT 8
- weird behavior of the import statement HOT 1
- Backport changes from python/cpython#119065 HOT 1
- Regular Expression: re.split behavior weird when have a sub pattern HOT 5
- "TypeError: catching classes that do not inherit from BaseException is not allowed" error when using generic in `except` block HOT 4
- Misleading sqlite3.Cursor.rowcount docs HOT 3
- New pyrepl gives a traceback on exit with "dumb" terminal HOT 11
- Unable to build to WASI HOT 8
- Inconsistent KeyboardInterrupt Handling in multiprocessing due to Context Manager Order
- difflib.py Differ.compare is too slow [for degenerate cases] HOT 36
- functools.partial does not re-set vector call.
- EnumType __call__ method description does not match the implementation HOT 1
- pathlib.Path.with_suffix(None) became allowed in Python 3.13b1 HOT 2
- Libmpec-dev not available on debian 12 when building Python HOT 7
- test_create_server_ssl_verified and test_create_unix_server_ssl_verified fail
- `tokenize.generate_tokens()` performance regression in 3.12 HOT 8
- functools.cache treats a named positional argument as a different one from an unnamed one HOT 1
- `asyncio.staggered` is missing `typing` import HOT 4
- The CSV file delimiter found with csv.Sniffer() is interpreted incorrectly HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cpython.