On Tue, 12 Apr 2022 at 04:46, Eryk Sun <eryk...@gmail.com> wrote:
>
> On 4/11/22, Chris Angelico <ros...@gmail.com> wrote:
> >
> > If you say `open("/spam")`, Windows uses "default drive" + "explicit
> > directory".
>
> You can think of a default drive as being the drive of the current
> working directory, but there is no "default drive" per se that's
> stored separate from the working directory.

Ah, fair. I described it that way because I thought that it was
equivalent, but I stand corrected.

> Python and most other filesystem libraries generalize a UNC
> "\\server\share" path as a 'drive', in addition to drive-letter drives
> such as "Z:". However, the working directory is only remembered
> separately from the process working directory in the case of
> drive-letter drives, not UNC shares.
>
> If the working directory is r"\\server\share\foo\bar", then r"\spam"
> resolves to r"\\server\share\spam".
>
> If the working directory is r"\\server\share\foo\bar", then "spam"
> resolves to r"\\server\share\foo\bar\spam". However, the system will
> actually access this path relative to an open handle for the working
> directory.

Which raises the question: what if the current directory no longer has
a path name? Or is that simply not possible on Windows? I know that on
Linux, I can unlink a directory while being in it (which creates
interesting problems for bash, git, and other tools, but not
fundamental ones for the process model itself), and many references
WILL be resolved correctly. Or I can move the directory to another
parent, and "pwd" says the original name (because that's a shell
feature), but "ls .." will list the contents of the new directory.

> A handle for the process working directory is always kept open and
> thus protected from being renamed or deleted. Per-drive working
> directories are not kept open. They're just stored as path names in
> reserved environment variables.
>
> > Hence there are 26 current directories (one per drive), plus the
> > selection of current drive, which effectively chooses your current
> > directory.
>
> If the process working directory is a DOS drive path, then 26 working
> directories are possible. If the process working directory is a UNC
> path, then 27 working directories are possible.

Yup yup. This is what I get for oversimplifying and forgetting that
UNC names are paths/drives too.

(Don't even get me started on prefixing paths with \\?\ and what that
changes. Windows has bizarre backward compatibility constraints.)

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/3P677SA7ENGBKIK2YFIPYLERYT6KLRXW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to