Doing it in yet another way, hopefully avoiding race conditions and file locks.