in reply to Writing to a file atomically without renaming

Hi,

You can use the Tie::File module, and move accross the file like a array, before writing you get the number of the last index of the array, then add data to the file, and then if it fails because of exception, you remove from the saved point towards.

If it's binary data you should use seek for moving, etc...

Could be a solution for what you want, if I understand well your problem.

On the other hand, must it be stored in the filesystem, because, depending on your needs, on RDBMS with transactions... you don't get this "problem".

Regards,

|fire| at irc
  • Comment on Re: Writing to a file atomically without renaming

Replies are listed 'Best First'.
Re^2: Writing to a file atomically without renaming
by nomis80 (Sexton) on Jun 30, 2005 at 19:45 UTC
    Yes, it must be stored in the filesystem. I'm starting to wonder how exactly RDBMS implement transactions. I don't think they use the rename() trick...
      They write blocks of data to holes in the file or at the end of the file, and if the transaction is committed they then change pointers in the tablespace to the new data, else if rollback they leave the pointers at the old data locations.


      -Waswas