Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 600f9ce

Browse files
author
Jamie Snape
committed
Do not assume that subdirectories of temporary and data directories exist
1 parent b0c2a2f commit 600f9ce

File tree

14 files changed

+22
-27
lines changed

14 files changed

+22
-27
lines changed

core/controllers/components/UtilityComponent.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,25 +344,32 @@ public static function run_sql_from_file($db, $sqlfile)
344344
public static function getDataDirectory($subdir = '')
345345
{
346346
$settingModel = MidasLoader::loadModel('Setting');
347+
347348
try {
348349
$dataDirectory = $settingModel->getValueByName('data_directory');
349350
} catch (Exception $e) {
350351
$dataDirectory = null;
351352
}
353+
352354
if (!isset($dataDirectory) || empty($dataDirectory)) {
353355
if (getenv('midas_data_path') !== false) {
354356
$dataDirectory = getenv('midas_data_path');
355357
} else {
356358
$dataDirectory = BASE_PATH.'/data';
357359
}
358360
}
361+
359362
if ($subdir == '') {
360-
$dataDirectory .= '/';
363+
$path = $dataDirectory.'/';
361364
} else {
362-
$dataDirectory .= '/'.$subdir.'/';
365+
$path = $dataDirectory.'/'.$subdir.'/';
366+
}
367+
368+
if (is_writable($dataDirectory) && !file_exists($path)) {
369+
mkdir($path, 0777, true);
363370
}
364371

365-
return $dataDirectory;
372+
return realpath($path);
366373
}
367374

368375
/**
@@ -374,13 +381,15 @@ public static function getDataDirectory($subdir = '')
374381
public static function getTempDirectory($subdir = "misc")
375382
{
376383
$settingModel = MidasLoader::loadModel('Setting');
384+
377385
try {
378386
$tempDirectory = $settingModel->getValueByName('temp_directory');
379387
} catch (Exception $e) {
380388
// if the setting model hasn't been installed, or there is no
381389
// value in the settings table for this, provide a default
382390
$tempDirectory = null;
383391
}
392+
384393
if (!isset($tempDirectory) || empty($tempDirectory)) {
385394
if (getenv('midas_temp_path') !== false) {
386395
$tempDirectory = getenv('midas_temp_path');
@@ -389,7 +398,13 @@ public static function getTempDirectory($subdir = "misc")
389398
}
390399
}
391400

392-
return $tempDirectory.'/'.$subdir;
401+
$path = $tempDirectory.'/'.$subdir;
402+
403+
if (is_writable($tempDirectory) && !file_exists($path)) {
404+
mkdir($path, 0777, true);
405+
}
406+
407+
return realpath($path);
393408
}
394409

395410
/**
File renamed without changes.
File renamed without changes.

data/thumbnail/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

data/visualize/.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

tmp/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
pvw-data
1+
*
2+
!.gitignore
3+
!.htaccess

tmp/cache/db/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

tmp/cache/searchIndex/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

tmp/cache/translation/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

tmp/exportTest/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)