8227ce941a
It looks like lockfile implementation did still suffer from a race condition. Only when creating the file with O_EXCL, file creation fails if the file does already exist. One could use O_EXCL, but Windows might use another flag to achieve the same. Moreover, O_EXCL doesn't work as expected if the files are accessed over NFS. In contrast, mkdir() is atomic in every of the mentioned cases. Aside from using a lockdirectory, this patch also backups the current wallet.dat contents to wallet.bck in case writing a possibly hefty amount of JSON to the new wallet.dat fails. It is hoped that at least one of the .bck and .dat files has usable contents in case failure.