Skip to content

Commit d92eacc

Browse files
committed
Add support for non-relative paths
1 parent 8952cff commit d92eacc

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

setup/backup.class.inc.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,9 @@ public static function MakeSafeMySQLCommand($sMySQLBinDir, string $sCmd)
651651
public static function GetTmpDir(Config $oConfig): string
652652
{
653653
$sTmpDir = $oConfig->GetModuleSetting('itop-backup', 'backup_tmpdir', 'data/');
654+
if (utils::RealPath(APPROOT.$sTmpDir, APPROOT) === false) $sTmpDir = APPROOT.$sTmpDir;
654655

655-
$sTmpDir = tempnam(empty($sTmpDir) ? SetupUtils::getTmpDir() : APPROOT.$sTmpDir , 'itop-backup-');
656+
$sTmpDir = @tempnam(empty($sTmpDir) ? SetupUtils::getTmpDir() : $sTmpDir , 'itop-backup-');
656657
unlink($sTmpDir); // I need a directory, not a file...
657658
SetupUtils::builddir($sTmpDir);
658659

tests/php-unit-tests/unitary-tests/setup/DBBackupTest.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public function MakeNameProvider(): array
201201
* @covers DBBackup::GetTmpDir
202202
* @dataProvider GetTmpDirProvider
203203
*/
204-
public function testGetTmpDir(string $sTmpDir, string $sStartsWith): void
204+
public function testGetTmpDir(?string $sTmpDir, string $sStartsWith): void
205205
{
206206
$this->RequireOnceItopFile('setup/setuputils.class.inc.php');
207207
$oConfig = \utils::GetConfig(true);
@@ -217,6 +217,10 @@ public function testGetTmpDir(string $sTmpDir, string $sStartsWith): void
217217
public function GetTmpDirProvider(): array
218218
{
219219
return [
220+
'Not configured' => [
221+
null,
222+
static::GetAppRoot() . 'data/itop-backup',
223+
],
220224
'Default settings' => [
221225
'data/',
222226
static::GetAppRoot() . 'data/itop-backup',
@@ -225,17 +229,9 @@ public function GetTmpDirProvider(): array
225229
'',
226230
sys_get_temp_dir() . '/itop-backup',
227231
],
228-
'System directory attempt with existing root dir' => [
229-
'/lib',
230-
static::GetAppRoot() . 'lib/itop-backup',
231-
],
232-
'System directory attempt with non existing root dir' => [
233-
'/etc',
234-
static::GetAppRoot() . 'data/itop-backup',
235-
],
236-
'Breakout attempt' => [
237-
'../../../var',
238-
static::GetAppRoot() . 'data/itop-backup',
232+
'Fixed system directory' => [
233+
'/tmp',
234+
'/tmp/itop-backup',
239235
],
240236
];
241237
}

0 commit comments

Comments
 (0)