From a828b25aed2cf81504689ad35ef1e2bb42889068 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Fri, 21 Feb 2025 08:47:09 +0100 Subject: [PATCH] lib: reduce the length of the temporary directory path (#1089) 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 84e60331..2afffa2e 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 296d867c..d7f1b43e 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);