chore(tracing): remove extra fs.access call (#21855)

This commit is contained in:
Dmitry Gozman 2023-03-21 19:01:09 -07:00 committed by GitHub
parent d9a9bb5a8c
commit 295a8ec92b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -421,14 +421,10 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
this._allResources.add(sha1);
const resourcePath = path.join(this._state!.resourcesDir, sha1);
this._appendTraceOperation(async () => {
try {
// Perhaps we've already written this resource?
await fs.promises.access(resourcePath);
} catch (e) {
// If not, let's write! Note that async access is safe because we
// never remove resources until the very end.
await fs.promises.writeFile(resourcePath, buffer).catch(() => {});
}
// Note: 'wx' flag only writes when the file does not exist.
// See https://nodejs.org/api/fs.html#file-system-flags.
// This way tracing never have to write the same resource twice.
await fs.promises.writeFile(resourcePath, buffer, { flag: 'wx' }).catch(() => {});
});
}