in reply to [OT] rename(2) -- renaming file to itself produces no error.

What error would you have it report? I think it's perfectly fine that it does nothing, and reports no error.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

  • Comment on •Re: [OT] rename(2) -- renaming file to itself produces no error.

Replies are listed 'Best First'.
Re: •Re: [OT] rename(2) -- renaming file to itself produces no error.
by dmitri (Priest) on Jan 07, 2004 at 22:49 UTC
    I feel that if I call a function that should modify the filesystem and the filesystem is not modified, an error should be reported. Maybe an ENOOP.

      Your text leads me to believe that you were attempting this operation merely for the side-effect of updating the mtime on the directory that the file is in. Is this true? If so, shame on you! :)

      Otherwise it strikes me as a violation of the principle of least surprise that rename would produce an error when asked to do something that is easy enough to do by doing nothing (principle of least action there)

        No, what happened was I was looking over a source tree which I happen (unfortunately) to maintain, and there was a silly rename that was a noop. The return value was checked, but no error was generated. Because no error was generated, this logical error was never detected. So, I got pissed of at rename(2).

        As for the "principle of least action", I explained my position in a previous post, and from the paragraph above you know why I prefer it :)