New rename(2) function

Corinna Vinschen corinna-cygwin@cygwin.com
Tue Jul 31 15:57:00 GMT 2007


Hi Eric (in the first place),
hi cygwin-developers,

I have implemented the rename(2) function from scratch in Cygwin.  It
treates Cygwin shortcut symlinks and .exe binaries transparently.  Or
better, it tries to handle them transparently.

As the coreutils maintainer you are quite involved in how the rename
function is supposed to work, especially  due to Cygwin hacks for mv(1),
so I would like to ask you to give this new implementation a thorough
test.

It's rather tricky to explain how it tries to behave, but I do my best
below.  If you (or others) think there's a thinko in the plan, or you
find corner cases which behave strange or unexpected (that's probably
what's called a "bug"), I would like to discuss it here on
cygwin-developers.

Ok, here's the secret plan behind the new rename in the source code
order of testing:

- If oldpath doesn't exist => ENOENT
- If oldpath is a dir
  - If newpath exists and is not a dir => ENOTDIR
  - If newpath is a subdir of oldpath => EINVAL
- If oldpath is a file
  - If newpath doesn't exist
    - If fullpath(oldpath) and fullpath(newpath) only differ by
      their .exe or .lnk suffix, skip all other tests and just
      rename oldpath to newpath
    - If oldpath is a shortcut symlink and newpath is missing a .lnk
      suffix => rename oldpath to newpath.lnk
    - If oldpath is a .exe binary and newpath is missing a .exe
      suffix => rename oldpath to newpath.exe
  - If newpath is a dir => EISDIR
  - If newpath is a file
    - If fullpath(oldpath) and fullpath(newpath) only differ by
      their .exe or .lnk suffix, skip all other tests and rename
      oldpath to newpath as given.
    - If oldpath is a shortcut symlink and newpath is not a
      shortcut symlink and newpath doesn't have a .lnk suffix
      => delete newpath and rename oldpath to newpath.lnk
    - If oldpath is a .exe binary and newpath is missing a .exe
      => delete newpath and rename oldpath to newpath.exe.
    - This is very tricky:
      Otherwise, if oldpath is no shortcut symlink and no .exe binary,
      and newpath has a .lnk or .exe suffix, *and* the suffix has
      been given explicitely to the rename function, rather than
      being tacked on when creating the native Win32 path
      => If newpath is a shortcut symlink or .exe binary, delete it.
      => Drop the .lnk or .exe suffix from newpath and rename
	 oldpath to newpath w/o .lnk or .exe suffix.

If a file is going to be deleted, it's only deleted if the rename
itself was successful.

I hope the description is clear.  If not, feel free to ask.


Thanks in advance,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat



More information about the Cygwin-developers mailing list