On Wed, Sep 15, 2021 at 4:20 AM Steven D'Aprano <steve@pearwood.info> wrote:
On Wed, Sep 15, 2021 at 08:53:21PM +1000, Chris Angelico wrote:

> Sometimes there is no valid path to something,

I don't understand what you mean by that. If there is no valid path to
something, where exactly are you cd'ing to, and how does it help you
with the thing that has no valid path to it?

No one has mentioned the other case where cd'ing somewhere makes paths
suddenly valid, and that is for long path names. Once you pass PATH_MAX
length your only options are to cd as deep as possible and continue relatively,
or to pass dir fds. The second is perhaps the better option, but harder to
implement as you have to handle extra fds and remember to clean them up and
I at least never remember how to thread fds through python code without going
and looking it up.

This also brings up the issue of how to restore the prior working directory. Just
remembering its path and calling a new chdir will fail, both in the long path case
and in the case that the old dir was deleted since last visit. We could hold an
open fd before leaving the old cwd, and that should allow us to return in both
cases. However I don't know how others feel about holding on to dir fds, especially
essentially hidden ones; it sounds ripe for FS deadlock.