[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-ideas
Subject:    [Python-ideas] Re: os.workdir() context manager
From:       Jeremiah Paige <ucodery () gmail ! com>
Date:       2021-09-16 16:59:34
Message-ID: CABYtpUmRt+tNauvKob1bOC-n_58o_mjD_Krs6damEyHzyq8Ctw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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.

Regards,
~Jeremiah

[Attachment #5 (text/html)]

<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" \
class="gmail_attr">On Wed, Sep 15, 2021 at 4:20 AM Steven D&#39;Aprano &lt;<a \
href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wed, Sep 15, 2021 \
at 08:53:21PM +1000, Chris Angelico wrote:<br> <br>
&gt; Sometimes there is no valid path to something,<br>
<br>
I don&#39;t understand what you mean by that. If there is no valid path to <br>
something, where exactly are you cd&#39;ing to, and how does it help you <br>
with the thing that has no valid path to it?<br></blockquote><div><br></div><div>No \
one has mentioned the other case where cd&#39;ing somewhere makes \
paths</div><div>suddenly valid, and that is for long path names. Once you pass \
PATH_MAX</div><div>length your only options are to cd as deep as possible and \
continue relatively,</div><div>or to pass dir fds. The second is perhaps the better \
option, but harder to</div><div>implement as you have to handle extra fds and \
remember to clean them up and</div><div>I at least never remember how to thread fds \
through python code without  going</div><div>and looking it \
up.</div><div><br></div><div>This also brings up the issue of how to restore the \
prior working directory. Just</div><div>remembering its path and calling a new chdir \
will fail, both in the long path case</div><div>and in the case that the old dir was \
deleted since last visit. We could hold an</div><div>open fd before leaving the old \
cwd, and that should allow us to return in both</div><div>cases. However I don&#39;t \
know how others feel about holding on to dir fds, especially</div><div>essentially \
hidden ones; it  sounds ripe for FS \
deadlock.</div><div><br></div><div>Regards,</div><div>~Jeremiah</div></div></div>



_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@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/L37QIXGPPBSQJFOHI5O3QZCKDEHKDVTJ/
 Code of Conduct: http://python.org/psf/codeofconduct/



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic