Skip to content

Commit

Permalink
Lock both source and destination files when copying or renaming files
Browse files Browse the repository at this point in the history
This seems to resolve a race condition issue where a disabled mod was
imported as a part of a profile. Before the fix, renaming the file with
".old" extension when disabling the mod after copying it into profile
caused an EBUSY error.
  • Loading branch information
anttimaki committed Jan 17, 2025
1 parent 669d972 commit 1c6db46
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/providers/generic/file/NodeFs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default class NodeFs extends FsProvider {

async rename(path: string, newPath: string): Promise<void> {
return new Promise((resolve, reject) => {
NodeFs.lock.acquire(path, async () => {
NodeFs.lock.acquire([path, newPath], async () => {
try {
await fs.promises.rename(path, newPath);
resolve();
Expand All @@ -110,7 +110,7 @@ export default class NodeFs extends FsProvider {

async copyFile(from: string, to: string): Promise<void> {
return new Promise((resolve, reject) => {
NodeFs.lock.acquire(from, async () => {
NodeFs.lock.acquire([from, to], async () => {
try {
await fs.promises.copyFile(from, to);
resolve();
Expand Down

0 comments on commit 1c6db46

Please sign in to comment.