Skip to content

Commit 1c88d5a

Browse files
committed
Ensure an unique installation directory to avoid conflicts
1 parent 96c5f06 commit 1c88d5a

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

datadog-setup.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -517,26 +517,22 @@ function install($options)
517517
}
518518

519519
// Preparing clean tmp folder to extract files
520-
$tmpDir = sys_get_temp_dir() . '/dd-install';
520+
do {
521+
$tmpDir = sys_get_temp_dir() . '/dd-install-' . bin2hex(random_bytes(8));
522+
} while (file_exists($tmpDir));
521523
$tmpArchiveRoot = $tmpDir . '/dd-library-php';
522524
$tmpArchiveTraceRoot = $tmpDir . '/dd-library-php/trace';
523525
$tmpArchiveAppsecRoot = $tmpDir . '/dd-library-php/appsec';
524526
$tmpArchiveAppsecLib = "{$tmpArchiveAppsecRoot}/lib";
525527
$tmpArchiveAppsecEtc = "{$tmpArchiveAppsecRoot}/etc";
526528
$tmpArchiveProfilingRoot = $tmpDir . '/dd-library-php/profiling';
527529
$tmpSrcDir = $tmpArchiveTraceRoot . '/src';
528-
if (!file_exists($tmpDir)) {
529-
execute_or_exit("Cannot create directory '$tmpDir'. Try setting a different temporary directory by setting the sys_temp_dir INI variable. E.g. php -d sys_temp_dir=" . (IS_WINDOWS ? 'C:\path\to\temp\dir' : "/path/to/temp/dir") . (isset($_SERVER["argv"][0]) ? " {$_SERVER["argv"][0]}" : ""), "mkdir " . (IS_WINDOWS ? "" : "-p ") . escapeshellarg($tmpDir));
530-
}
530+
531+
execute_or_exit("Cannot create directory '$tmpDir'. Try setting a different temporary directory by setting the sys_temp_dir INI variable. This directory must exist. E.g. php -d sys_temp_dir=" . (IS_WINDOWS ? 'C:\path\to\temp\dir' : "/path/to/temp/dir") . (isset($_SERVER["argv"][0]) ? " {$_SERVER["argv"][0]}" : ""), "mkdir " . (IS_WINDOWS ? "" : "-m 700 ") . escapeshellarg($tmpDir));
532+
531533
register_shutdown_function(function () use ($tmpDir) {
532-
execute_or_exit("Cannot remove temporary directory '$tmpDir'", (IS_WINDOWS ? "rd /s /q " : "rm -rf ") . escapeshellarg($tmpDir));
534+
execute_or_exit("Cannot remove temporary directory '$tmpDir'. You might have to remove it yourself.", (IS_WINDOWS ? "rd /s /q " : "rm -rf ") . escapeshellarg($tmpDir));
533535
});
534-
if (!IS_WINDOWS) {
535-
execute_or_exit(
536-
"Cannot clean '$tmpDir'",
537-
"rm -rf " . escapeshellarg($tmpDir) . "/* "
538-
);
539-
}
540536

541537
// Retrieve and extract the archive to a tmp location
542538
if (isset($options[OPT_FILE])) {

0 commit comments

Comments
 (0)