Utilize the release callback returned by lockFileSync to release the lock file (!239)

The error people are getting about a lock file already existing is due to `checkFileSync` returning false if the lock file is "stale".
The default "stale" timeout is 10 seconds, so if a save takes longer than this, the user will end up in a state where they can no longer save.

The documentation for `proper-lockfile` recommends using the callback returned by `lockFileSync` to remove the lock file, so I've switched to using this, and the error no longer occurs with long running save operations

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/239
Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
This commit is contained in:
DrakiaXYZ 2024-02-28 07:56:53 +00:00 committed by chomp
parent 0433308fa8
commit 4b8b62ae83

View File

@ -175,7 +175,7 @@ export class VFS
fs.writeFileSync(filepath, ""); fs.writeFileSync(filepath, "");
} }
this.lockFileSync(filepath); const releaseCallback = this.lockFileSync(filepath);
if (!append && atomic) if (!append && atomic)
{ {
@ -186,10 +186,7 @@ export class VFS
fs.writeFileSync(filepath, data, options); fs.writeFileSync(filepath, data, options);
} }
if (this.checkFileSync(filepath)) releaseCallback();
{
this.unlockFileSync(filepath);
}
} }
public async writeFileAsync(filepath: any, data = "", append = false, atomic = true): Promise<void> public async writeFileAsync(filepath: any, data = "", append = false, atomic = true): Promise<void>
@ -307,12 +304,12 @@ export class VFS
await this.renamePromisify(oldPath, newPath); await this.renamePromisify(oldPath, newPath);
} }
protected lockFileSync(filepath: any): void protected lockFileSync(filepath: any): () => void
{ {
lockfile.lockSync(filepath); return lockfile.lockSync(filepath);
} }
protected checkFileSync(filepath: any): any protected checkFileSync(filepath: any): boolean
{ {
return lockfile.checkSync(filepath); return lockfile.checkSync(filepath);
} }