Subject: Re: Linux emulation and mkdir with trailing /
To: John Darrow <John.P.Darrow@wheaton.edu>
From: Andrew Brown <atatat@atatdot.net>
List: tech-kern
Date: 09/29/2000 01:38:39
>>fwiw, this particular case (and "install myprogram /usr/local/bin/"
>>from alan barrett) can be made to work the way some people expect by
>>changing mv and install slightly.  they could be taught to look for
>>trailing slashes and if they exist, simply append the last component
>>of the source argument.  eg:
>>
>>   mv foo bar/ -> rename("foo", "bar/foo")
>>   install myprogram /usr/local/bin/ -> ..."/usr/local/bin/myprogram"
>>
>>which *will* fail if the last component in the target path does not
>>exist as a directory.
>
>But that's not quite right, either.  In that case, if I mv /tmp/foo
>/tmp/bar/, and /tmp/bar/foo already exists as a directory, I will end
>up with /tmp/bar/foo/foo, instead of getting an error message as I should.

um...yeah, except this bring to mind another quirk that a lot of
people just can't get when i try to explain it to them.  try this.
no, better yet, see if you can guess what happens and then see if
you're right.

   % cd /tmp
   % mkdir foo
   % mkdir bar
   % mv bar foo/
   % mkdir bar
   % mv bar foo/
   % mkdir bar
   % mv bar foo/
   % mkdir bar
   % mv bar foo/

it seems that a file can replace a file by the same name and a
directory can replace an *empty* directory by the same name.  this
means that the following command will work twice, but not three times.

   % cd /tmp ; mkdir -p foo/bar ; mv foo frotz

i was surprised when i saw that it worked twice.

-- 
|-----< "CODE WARRIOR" >-----|
codewarrior@daemon.org             * "ah!  i see you have the internet
twofsonet@graffiti.com (Andrew Brown)                that goes *ping*!"
andrew@crossbar.com       * "information is power -- share the wealth."