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

Commit

Permalink
Do not assume that subdirectories of temporary and data directories e…
Browse files Browse the repository at this point in the history
…xist
  • Loading branch information
Jamie Snape committed Nov 7, 2014
1 parent b0c2a2f commit 600f9ce
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 27 deletions.
23 changes: 19 additions & 4 deletions core/controllers/components/UtilityComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,25 +344,32 @@ public static function run_sql_from_file($db, $sqlfile)
public static function getDataDirectory($subdir = '')
{
$settingModel = MidasLoader::loadModel('Setting');

try {
$dataDirectory = $settingModel->getValueByName('data_directory');
} catch (Exception $e) {
$dataDirectory = null;
}

if (!isset($dataDirectory) || empty($dataDirectory)) {
if (getenv('midas_data_path') !== false) {
$dataDirectory = getenv('midas_data_path');
} else {
$dataDirectory = BASE_PATH.'/data';
}
}

if ($subdir == '') {
$dataDirectory .= '/';
$path = $dataDirectory.'/';
} else {
$dataDirectory .= '/'.$subdir.'/';
$path = $dataDirectory.'/'.$subdir.'/';
}

if (is_writable($dataDirectory) && !file_exists($path)) {
mkdir($path, 0777, true);
}

return $dataDirectory;
return realpath($path);
}

/**
Expand All @@ -374,13 +381,15 @@ public static function getDataDirectory($subdir = '')
public static function getTempDirectory($subdir = "misc")
{
$settingModel = MidasLoader::loadModel('Setting');

try {
$tempDirectory = $settingModel->getValueByName('temp_directory');
} catch (Exception $e) {
// if the setting model hasn't been installed, or there is no
// value in the settings table for this, provide a default
$tempDirectory = null;
}

if (!isset($tempDirectory) || empty($tempDirectory)) {
if (getenv('midas_temp_path') !== false) {
$tempDirectory = getenv('midas_temp_path');
Expand All @@ -389,7 +398,13 @@ public static function getTempDirectory($subdir = "misc")
}
}

return $tempDirectory.'/'.$subdir;
$path = $tempDirectory.'/'.$subdir;

if (is_writable($tempDirectory) && !file_exists($path)) {
mkdir($path, 0777, true);
}

return realpath($path);
}

/**
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 0 additions & 3 deletions data/thumbnail/.gitignore

This file was deleted.

3 changes: 0 additions & 3 deletions data/visualize/.gitignore

This file was deleted.

4 changes: 3 additions & 1 deletion tmp/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pvw-data
*
!.gitignore
!.htaccess
2 changes: 0 additions & 2 deletions tmp/cache/db/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions tmp/cache/searchIndex/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions tmp/cache/translation/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions tmp/exportTest/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions tmp/misc/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions tmp/remoteprocessing/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions tmp/report/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions tmp/visualize/.gitignore

This file was deleted.

0 comments on commit 600f9ce

Please sign in to comment.