in reply to Re^2: Vexing Race Condition
in thread Vexing Race Condition

Actually Path:Tiny's trick is renaming a temporary file. My idea of opening read-write, locking then truncating turns out to be a non starter as mode +> clobbers the file and mode +< fails if the file doesn't already exist, I was able to run the script with no errors after touching the file although in the wild that would be another race condition. Opening the file in append mode as you suggest does work, so it's an option although using rename is probably more robust as it will also work for processes that don't use flock.

Replies are listed 'Best First'.
Re^4: Vexing Race Condition
by tybalt89 (Monsignor) on May 03, 2025 at 17:13 UTC

    Check out Path::Tiny::append with the truncate option. Path::Tiny has more than one trick up its sleeve.