Subject: Re: Linux emulation and mkdir with trailing /
To: None <>
From: John Darrow <>
List: tech-kern
Date: 09/29/2000 00:32:12
>>Perhaps it's just a learned expectation that "mv foo bar/" will rename
>>"foo" to "bar" if there's no pre-existing directory "bar", but I
>>personally am not surprised in any way by that happening.
>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.

I just caught up on this discussion, but the earlier quote from the
standards seems clear to me:  trailing slashes are valid as a no-op, but
_only_ if the preceding component is a directory - thus _normally_ requiring
it to already exist.  The special case is mkdir, which may be creating the
directory in question.  As such, it seems the simplest way to follow the
standard is for the name lookup routines to strip the trailing slashes only
if they find a valid directory already exists, and to otherwise (either no
existing entry, or a non-directory found) return an error, and for the
mkdir(2) call to strip off the trailing slashes on its own before calling
the lookup routine.


John Darrow - Senior Technical Specialist               Office: 630/752-5201
Computing Services, Wheaton College, Wheaton, IL 60187  Fax:    630/752-5968
Alphapage:            Pager:  630/316-0707