[OT] strange interaction between open and cwd

Baz Walter bazwal at ftml.net
Tue May 4 10:38:23 EDT 2010


On 04/05/10 03:25, Grant Edwards wrote:
> On 2010-05-04, Charles<C.Sanders at DeleteThis.Bom.GOV.AU>  wrote:
>
>>> I don't see how it's inelegant at all.  Perhaps it's
>>> counter-intuitive if you don't understand how a Unix filesystem
>>> works, but the underlying filesystem model is very simple, regular,
>>> and elegant.
>>>
>>>> but probably makes some bit of the OS's job slightly easier and is
>>>> usually good enough in practice. Pragmatism is a bitch sometimes. :-)
>>>
>>
>> I agree that the Unix file system is quite elegant, but can be
>> counter-intuitive for people who are used to the "one file, one name"
>> paradigm.
>
> I guess I've been using Unix for too long (almost 30 years).  I don't
> think I was consciously aware of a "one file, one name" paradigm.  Is
> that a characteristic of Dos, Windows or Mac filesystems?
>
>> [...]
>
>> In the OP's case, references to the directory have been removed from
>> the file system, but his process still has the current working
>> directory reference to it, so it has not actually been deleted. When
>> he opens "../abc.txt", the OS searches the current directory for ".."
>> and finds the inode for /home/baz/tmp, then searches that directory
>> (/home/baz/tmp) for abc.txt and finds it.
>
> Exactly.  I probably should have taken the time to explain that as
> well as you did.  One forgets that there are a log of new Unix users
> who've never been taught how the filesystem works.

actually, what i failed to grok is that whatever '..' refers to is all 
that is needed to find the file 'abc.txt' *even if the current directory 
has been deleted*. an absolute path just isn't needed. this has really 
got nothing to do with how unix filesystems work per se or "one file, 
one name", but more to do with simple reference counting. when i 
mentioned in my original post how windows handles attempts to delete the 
cwd differently, i should have put two and two together and figured this 
all out for myself. but i don't think it's immediately obvious what the 
consequences of (re)moving the cwd are, even if you've been using unix 
filesystems for a while. in know for a fact that i have used several 
linux programs in the past that didn't handle this possiblity 
gracefully, so it's not just new users that can be caught out by this.



More information about the Python-list mailing list