Skip to content

Commit

Permalink
release in finally
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Jul 19, 2022
1 parent f0f8725 commit bed01ad
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/node-file-trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ export class Job {
await this.fileIOQueue.acquire();
try {
const link = await fsReadlink(path);
this.fileIOQueue.release();
// also copy stat cache to symlink
const stats = this.statCache.get(path);
if (stats)
Expand All @@ -170,12 +169,14 @@ export class Job {
return link;
}
catch (e) {
this.fileIOQueue.release();
if (e.code !== 'EINVAL' && e.code !== 'ENOENT' && e.code !== 'UNKNOWN')
throw e;
this.symlinkCache.set(path, null);
return null;
}
finally {
this.fileIOQueue.release();
}
}

async isFile (path: string) {
Expand All @@ -198,18 +199,19 @@ export class Job {
await this.fileIOQueue.acquire();
try {
const stats = await fsStat(path);
this.fileIOQueue.release();
this.statCache.set(path, stats);
return stats;
}
catch (e) {
this.fileIOQueue.release();
if (e.code === 'ENOENT') {
this.statCache.set(path, null);
return null;
}
throw e;
}
finally {
this.fileIOQueue.release();
}
}

async resolve (id: string, parent: string, job: Job, cjsResolve: boolean): Promise<string | string[]> {
Expand All @@ -222,18 +224,19 @@ export class Job {
await this.fileIOQueue.acquire();
try {
const source = (await fsReadFile(path)).toString();
this.fileIOQueue.release();
this.fileCache.set(path, source);
return source;
}
catch (e) {
this.fileIOQueue.release();
if (e.code === 'ENOENT' || e.code === 'EISDIR') {
this.fileCache.set(path, null);
return null;
}
throw e;
}
finally {
this.fileIOQueue.release();
}
}

async realpath (path: string, parent?: string, seen = new Set()): Promise<string> {
Expand Down

0 comments on commit bed01ad

Please sign in to comment.