From ff28a5f9ce16604b55f80e18cab97d20bc4e7ccb Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Thu, 20 Feb 2025 11:52:16 +0100 Subject: [PATCH] lib: reduce the length of the temporary directory path Refs: https://github.com/nodejs/node/pull/57005#issuecomment-2666921592 --- lib/temp-directory.js | 6 +++--- test/test-temp-directory.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/temp-directory.js b/lib/temp-directory.js index 84e60331b..2afffa2e2 100644 --- a/lib/temp-directory.js +++ b/lib/temp-directory.js @@ -1,15 +1,15 @@ import { join } from 'path'; import { promises as fs, realpathSync } from 'fs'; -import { randomUUID } from 'crypto'; +import { randomBytes } from 'crypto'; import { tmpdir } from 'os'; import { removeDirectory } from './utils.js'; export async function create(context) { if (context.options && context.options.tmpDir) { - context.path = join(context.options.tmpDir, randomUUID()); + context.path = join(context.options.tmpDir, randomBytes(4).toString('hex')); } else { - context.path = join(tmpdir(), randomUUID()); + context.path = join(tmpdir(), randomBytes(4).toString('hex')); } await fs.mkdir(context.path, { recursive: true }); diff --git a/test/test-temp-directory.js b/test/test-temp-directory.js index 296d867c4..d7f1b43e0 100644 --- a/test/test-temp-directory.js +++ b/test/test-temp-directory.js @@ -41,7 +41,7 @@ test('tempDirectory.create --tmpDir:', async (t) => { t.plan(2); await tempDirectory.create(contextTmpDir); t.ok( - contextTmpDir.path.match(/thisisatest[/\\].*-.*-.*-.*-.*/), + contextTmpDir.path.match(/thisisatest[/\\][0-9a-f]{8}/), 'the path should match --tmpDir' ); const stats = await fs.stat(contextTmpDir.path);