Skip to content

Commit 38b1423

Browse files
committed
lib: reduce the length of temporary directory path
Refs: nodejs/node#57005 (comment)
1 parent 83ffabd commit 38b1423

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/temp-directory.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { join } from 'path';
22
import { promises as fs, realpathSync } from 'fs';
3-
import { randomUUID } from 'crypto';
43
import { tmpdir } from 'os';
4+
import { randomBytes } from 'crypto';
55

66
import { removeDirectory } from './utils.js';
77

88
export async function create(context) {
99
if (context.options && context.options.tmpDir) {
10-
context.path = join(context.options.tmpDir, randomUUID());
10+
context.path = join(context.options.tmpDir, randomBytes(4).toString('hex'));
1111
} else {
12-
context.path = join(tmpdir(), randomUUID());
12+
context.path = join(tmpdir(), randomBytes(4).toString('hex'));
1313
}
1414

1515
await fs.mkdir(context.path, { recursive: true });

test/test-temp-directory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ test('tempDirectory.create --tmpDir:', async (t) => {
4141
t.plan(2);
4242
await tempDirectory.create(contextTmpDir);
4343
t.ok(
44-
contextTmpDir.path.match(/thisisatest[/\\].*-.*-.*-.*-.*/),
44+
contextTmpDir.path.match(/thisisatest[/\\][0-9a-f]{8}/),
4545
'the path should match --tmpDir'
4646
);
4747
const stats = await fs.stat(contextTmpDir.path);

0 commit comments

Comments
 (0)