Eryk Sun <eryk...@gmail.com> added the comment:

> I'm not seeing what's wrong with your example.

"C:" or "C:spam\\eggs" are not absolute paths. They depend on the effective 
working directory on the drive. An absolute path should never depend on a 
working directory, which can change at random.

WinAPI SetEnvironmentVariableW() allows applications to set environment 
variables with names that begin with "=". These names are effectively reserved 
for special use by the OS, at least as documented. In particular, names of the 
form "=X:", where "X" is a drive letter, are used to store the working 
directory on a drive. The C runtime _[w]chdir() function sets these per-drive 
environment variables, as does Python's os.chdir(). As environment variables, 
they can be inherited by child processes.

When then Windows API resolves a file path to access a file, or in 
GetFullPathNameW(), a drive-relative path such as "X:" or "X:spam\\eggs" is 
resolved against either the current working directory (if it's on the drive) or 
the value of the "=X:" environment variable for the drive. If the latter isn't 
defined, it defaults to the root directory, e.g. "X:\\". If the current working 
directory is on the drive, the system updates the value of the "=X:" 
environment variable, if it exists.

> on Windows you have to resolve the drive separately from the 
> working directory and then concatenate them?

No, if self.drive is defined, then abspath(self.drive) should be called instead 
of getcwd(). In Windows, ntpath.abspath() calls WinAPI GetFullPathNameW(), 
which resolves the working directory on the drive.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue29688>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to