in reply to How to move/copy a file without overwriting an existing file

Part of the solution, if there may be multiple instances of the same script running, may be to maintain a lock file that mediates allocation of file names.

Possibly store the name and a next number for each used file. The atomic access to the lock file then adds a new name or increments the count on an existing name and in the process generates the name to be used.


DWIM is Perl's answer to Gödel
  • Comment on Re: How to move/copy a file without overwriting an existing file

Replies are listed 'Best First'.
Re^2: How to move/copy a file without overwriting an existing file
by bart (Canon) on Mar 31, 2006 at 06:50 UTC
    But that only improves on it if the other one is indeed using the same module. I won't even exclude the possibility that the other program is written in another language, like Java.

    I don't want my script to overwrite another file, ever, even if the other script occasionally might overwrite one of mine. I do not want my module to get the blame with good reason. Race conditions should be excluded from my side, always, all of the time.

    That limits the options a little, doesn't it?