New rename(2) function

Eric Blake
Fri Aug 10 03:23:00 GMT 2007

According to Christian Franke on 8/9/2007 10:38 AM:
> $ mv Foo foo
> mv: `Foo' and `foo' are the same file

It looks like mv uses stat() before trying rename(); and on a
case-insensitive system, both spellings name the same file.  Are you
suggesting that I should look into a cygwin-local patch to coreutils that
tries the rename if all that differs is case, even when stat() says it is
the same file?  But it looks like you are right - rename("A","a") only
sees a link count of 1, so the current implementation skips the same id
check, and then falls through to the Windows rename operation, which
apparently really does change the case.

> $ mkdir Bar
> $ mv Bar bar
> mv: cannot move `Bar' to a subdirectory of itself, `bar/Bar'

If you wanted rename semantics with directories, you should use 'mv -T Bar
bar'.  But that said, this probably falls in the same category as 'mv Foo
foo' for non-directories - it would need a cygwin-specific patch to try
the rename() even when stat() says there is no point to it.  And it would
require that we make the conscious decision to keep the current behavior,
where rename("A","a") with case-insensitive behavior changes the case.

> Probably, a case insensitive filesystem is not POSIX compliant at all ;-)

You got that right.  A true POSIX file system must be case sensitive,
supporting all 254 (exluding NUL and /) bytes.  However, POSIX is also
clear that not all file systems meet POSIX rules, so portable names are
limited to a-zA-Z0-9_.-.  I think you are correct that since having "A"
and "a" map to the same file id with only a link count of 1 already
violates POSIX, so skipping the same-id check (which is easier to code for
cygwin1.dll, but results in the case-changing rename rather than a no-op)
is no worse of a violation, so we might as well leave things that way for
cygwin.  I'll leave that decision up to Corinna, though.

Don't work too hard, make some time for fun as well!

Eric Blake   

More information about the Cygwin-developers mailing list