Eryk Sun <[email protected]> added the comment:
> # I thought this would have to be 16, i.e. a path length over 4096, PATH_MAX
> # but seemingly just crossing 1050 is enough to fail
If os.pathconf() and PC_PATH_MAX are supported, the maximum allowed length of
an absolute path is os.pathconf('/', os.pathconf_names['PC_PATH_MAX']). I think
it also depends on the mounted filesystems that the path traverses.
If os.chdir is in os.supports_fd, the context manager can use dirfd =
os.open(os.getcwd(), os.O_RDONLY). Using an fd should also work around the
deleted directory case, though POSIX doesn't specify whether fchdir() succeeds
in this case. It does in Linux, and the resulting state is the same as deleting
the current working directory.
In Windows, SetCurrentDirectoryW() resolves the full path. So the result from
os.getcwd() should always work with os.chdir(). The context manager could
prevent the original directory from getting deleted by opening it without
delete sharing (e.g. via _winapi.CreateFile). Though it may be more reasonable
to just let it fail to restore the original working directory.
----------
nosy: +eryksun
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue45545>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com