mirror of
https://github.com/friendica/friendica
synced 2024-12-23 19:20:17 +00:00
Merge pull request #3166 from annando/bugfix-tempdir
More analytics to analyze the reason for constantly changing temp paths
This commit is contained in:
commit
ce953e5882
1 changed files with 64 additions and 12 deletions
76
boot.php
76
boot.php
|
@ -1415,6 +1415,53 @@ class App {
|
||||||
proc_close(proc_open($cmdline." &",array(),$foo,dirname(__FILE__)));
|
proc_close(proc_open($cmdline." &",array(),$foo,dirname(__FILE__)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the system user that is executing the script
|
||||||
|
*
|
||||||
|
* This mostly returns something like "www-data".
|
||||||
|
*
|
||||||
|
* @return string system username
|
||||||
|
*/
|
||||||
|
static function systemuser() {
|
||||||
|
if (!function_exists('posix_getpwuid') OR !function_exists('posix_geteuid')) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$processUser = posix_getpwuid(posix_geteuid());
|
||||||
|
return $processUser['name'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Checks if a given directory is usable for the system
|
||||||
|
*
|
||||||
|
* @return boolean the directory is usable
|
||||||
|
*/
|
||||||
|
static function directory_usable($directory) {
|
||||||
|
|
||||||
|
if ($directory == '') {
|
||||||
|
logger("Directory is empty. This shouldn't happen.", LOGGER_DEBUG);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file_exists($directory)) {
|
||||||
|
logger('Path "'.$directory.'" does not exist for user '.self::systemuser(), LOGGER_DEBUG);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (is_file($directory)) {
|
||||||
|
logger('Path "'.$directory.'" is a file for user '.self::systemuser(), LOGGER_DEBUG);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!is_dir($directory)) {
|
||||||
|
logger('Path "'.$directory.'" is not a directory for user '.self::systemuser(), LOGGER_DEBUG);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!is_writable($directory)) {
|
||||||
|
logger('Path "'.$temppath.'" is not writable for user '.self::systemuser(), LOGGER_DEBUG);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2319,8 +2366,9 @@ function get_itemcachepath() {
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
$itemcache = get_config('system','itemcache');
|
$itemcache = get_config('system','itemcache');
|
||||||
if (($itemcache != "") AND is_dir($itemcache) AND is_writable($itemcache))
|
if (($itemcache != "") AND App::directory_usable($itemcache)) {
|
||||||
return($itemcache);
|
return($itemcache);
|
||||||
|
}
|
||||||
|
|
||||||
$temppath = get_temppath();
|
$temppath = get_temppath();
|
||||||
|
|
||||||
|
@ -2330,7 +2378,7 @@ function get_itemcachepath() {
|
||||||
mkdir($itemcache);
|
mkdir($itemcache);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_dir($itemcache) AND is_writable($itemcache)) {
|
if (App::directory_usable($itemcache)) {
|
||||||
set_config("system", "itemcache", $itemcache);
|
set_config("system", "itemcache", $itemcache);
|
||||||
return($itemcache);
|
return($itemcache);
|
||||||
}
|
}
|
||||||
|
@ -2340,20 +2388,22 @@ function get_itemcachepath() {
|
||||||
|
|
||||||
function get_lockpath() {
|
function get_lockpath() {
|
||||||
$lockpath = get_config('system','lockpath');
|
$lockpath = get_config('system','lockpath');
|
||||||
if (($lockpath != "") AND is_dir($lockpath) AND is_writable($lockpath))
|
if (($lockpath != "") AND App::directory_usable($lockpath)) {
|
||||||
return($lockpath);
|
return($lockpath);
|
||||||
|
}
|
||||||
|
|
||||||
$temppath = get_temppath();
|
$temppath = get_temppath();
|
||||||
|
|
||||||
if ($temppath != "") {
|
if ($temppath != "") {
|
||||||
$lockpath = $temppath."/lock";
|
$lockpath = $temppath."/lock";
|
||||||
|
|
||||||
if (!is_dir($lockpath))
|
if (!is_dir($lockpath)) {
|
||||||
mkdir($lockpath);
|
mkdir($lockpath);
|
||||||
elseif (!is_writable($lockpath))
|
} elseif (!App::directory_usable($lockpath)) {
|
||||||
$lockpath = $temppath;
|
$lockpath = $temppath;
|
||||||
|
}
|
||||||
|
|
||||||
if (is_dir($lockpath) AND is_writable($lockpath)) {
|
if (App::directory_usable($lockpath)) {
|
||||||
set_config("system", "lockpath", $lockpath);
|
set_config("system", "lockpath", $lockpath);
|
||||||
return($lockpath);
|
return($lockpath);
|
||||||
}
|
}
|
||||||
|
@ -2368,7 +2418,7 @@ function get_lockpath() {
|
||||||
*/
|
*/
|
||||||
function get_spoolpath() {
|
function get_spoolpath() {
|
||||||
$spoolpath = get_config('system','spoolpath');
|
$spoolpath = get_config('system','spoolpath');
|
||||||
if (($spoolpath != "") AND is_dir($spoolpath) AND is_writable($spoolpath)) {
|
if (($spoolpath != "") AND App::directory_usable($spoolpath)) {
|
||||||
return($spoolpath);
|
return($spoolpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2379,11 +2429,11 @@ function get_spoolpath() {
|
||||||
|
|
||||||
if (!is_dir($spoolpath)) {
|
if (!is_dir($spoolpath)) {
|
||||||
mkdir($spoolpath);
|
mkdir($spoolpath);
|
||||||
} elseif (!is_writable($spoolpath)) {
|
} elseif (!App::directory_usable($spoolpath)) {
|
||||||
$spoolpath = $temppath;
|
$spoolpath = $temppath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_dir($spoolpath) AND is_writable($spoolpath)) {
|
if (App::directory_usable($spoolpath)) {
|
||||||
set_config("system", "spoolpath", $spoolpath);
|
set_config("system", "spoolpath", $spoolpath);
|
||||||
return($spoolpath);
|
return($spoolpath);
|
||||||
}
|
}
|
||||||
|
@ -2395,16 +2445,18 @@ function get_temppath() {
|
||||||
$a = get_app();
|
$a = get_app();
|
||||||
|
|
||||||
$temppath = get_config("system","temppath");
|
$temppath = get_config("system","temppath");
|
||||||
if (($temppath != "") AND is_dir($temppath) AND is_writable($temppath))
|
|
||||||
|
if (($temppath != "") AND App::directory_usable($temppath)) {
|
||||||
return($temppath);
|
return($temppath);
|
||||||
|
}
|
||||||
|
|
||||||
$temppath = sys_get_temp_dir();
|
$temppath = sys_get_temp_dir();
|
||||||
if (($temppath != "") AND is_dir($temppath) AND is_writable($temppath)) {
|
if (($temppath != "") AND App::directory_usable($temppath)) {
|
||||||
$temppath .= "/".$a->get_hostname();
|
$temppath .= "/".$a->get_hostname();
|
||||||
if (!is_dir($temppath))
|
if (!is_dir($temppath))
|
||||||
mkdir($temppath);
|
mkdir($temppath);
|
||||||
|
|
||||||
if (is_dir($temppath) AND is_writable($temppath)) {
|
if (App::directory_usable($temppath)) {
|
||||||
set_config("system", "temppath", $temppath);
|
set_config("system", "temppath", $temppath);
|
||||||
return($temppath);
|
return($temppath);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue