dmitri has asked for the wisdom of the Perl Monks concerning the following question:
rename(2) (and, therefore, Perl's own rename function) does not report an error when a file is renamed to itself. What is even more interesting, mtime of parent directory is not changed, either. So, nothing happens, but no error is reported? Why?
Some code:
perl -e '$s = rename("tags", "tags"); print STDOUT ($s ? "OK" : "FAIL" +), "\n";'
C code:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> int main (int argc, char **argv) { int rs; rs = rename(argv[1], argv[1]); if (-1 == rs) { fprintf(stderr, "Error renaming %s: %s\n", argv[1], strerror(e +rrno)); } else { printf("Rename of %s is OK\n", argv[1]); } exit(0); }
|
|---|