Merge pull request #3173 from annando/more-temp-stuff
Workaround for not createable spool path
This commit is contained in:
commit
55288e8e6e
3 changed files with 72 additions and 28 deletions
67
boot.php
67
boot.php
|
@ -1457,7 +1457,7 @@ class App {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!is_writable($directory)) {
|
if (!is_writable($directory)) {
|
||||||
logger('Path "'.$temppath.'" is not writable for user '.self::systemuser(), LOGGER_DEBUG);
|
logger('Path "'.$directory.'" is not writable for user '.self::systemuser(), LOGGER_DEBUG);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -2367,7 +2367,7 @@ function get_itemcachepath() {
|
||||||
|
|
||||||
$itemcache = get_config('system','itemcache');
|
$itemcache = get_config('system','itemcache');
|
||||||
if (($itemcache != "") AND App::directory_usable($itemcache)) {
|
if (($itemcache != "") AND App::directory_usable($itemcache)) {
|
||||||
return($itemcache);
|
return $itemcache;
|
||||||
}
|
}
|
||||||
|
|
||||||
$temppath = get_temppath();
|
$temppath = get_temppath();
|
||||||
|
@ -2380,7 +2380,7 @@ function get_itemcachepath() {
|
||||||
|
|
||||||
if (App::directory_usable($itemcache)) {
|
if (App::directory_usable($itemcache)) {
|
||||||
set_config("system", "itemcache", $itemcache);
|
set_config("system", "itemcache", $itemcache);
|
||||||
return($itemcache);
|
return $itemcache;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
|
@ -2389,25 +2389,32 @@ function get_itemcachepath() {
|
||||||
function get_lockpath() {
|
function get_lockpath() {
|
||||||
$lockpath = get_config('system','lockpath');
|
$lockpath = get_config('system','lockpath');
|
||||||
if (($lockpath != "") AND App::directory_usable($lockpath)) {
|
if (($lockpath != "") AND App::directory_usable($lockpath)) {
|
||||||
return($lockpath);
|
// We have a lock path and it is usable
|
||||||
|
return $lockpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We don't have a working preconfigured lock path, so we take the temp path.
|
||||||
$temppath = get_temppath();
|
$temppath = get_temppath();
|
||||||
|
|
||||||
if ($temppath != "") {
|
if ($temppath != "") {
|
||||||
|
// To avoid any interferences with other systems we create our own directory
|
||||||
$lockpath = $temppath."/lock";
|
$lockpath = $temppath."/lock";
|
||||||
|
|
||||||
if (!is_dir($lockpath)) {
|
if (!is_dir($lockpath)) {
|
||||||
mkdir($lockpath);
|
mkdir($lockpath);
|
||||||
} elseif (!App::directory_usable($lockpath)) {
|
|
||||||
$lockpath = $temppath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (App::directory_usable($lockpath)) {
|
if (App::directory_usable($lockpath)) {
|
||||||
|
// The new path is usable, we are happy
|
||||||
set_config("system", "lockpath", $lockpath);
|
set_config("system", "lockpath", $lockpath);
|
||||||
return($lockpath);
|
return $lockpath;
|
||||||
|
} else {
|
||||||
|
// We can't create a subdirectory, strange.
|
||||||
|
// But the directory seems to work, so we use it but don't store it.
|
||||||
|
return $temppath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reaching this point means that the operating system is configured badly.
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2419,25 +2426,32 @@ function get_lockpath() {
|
||||||
function get_spoolpath() {
|
function get_spoolpath() {
|
||||||
$spoolpath = get_config('system','spoolpath');
|
$spoolpath = get_config('system','spoolpath');
|
||||||
if (($spoolpath != "") AND App::directory_usable($spoolpath)) {
|
if (($spoolpath != "") AND App::directory_usable($spoolpath)) {
|
||||||
return($spoolpath);
|
// We have a spool path and it is usable
|
||||||
|
return $spoolpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We don't have a working preconfigured spool path, so we take the temp path.
|
||||||
$temppath = get_temppath();
|
$temppath = get_temppath();
|
||||||
|
|
||||||
if ($temppath != "") {
|
if ($temppath != "") {
|
||||||
|
// To avoid any interferences with other systems we create our own directory
|
||||||
$spoolpath = $temppath."/spool";
|
$spoolpath = $temppath."/spool";
|
||||||
|
|
||||||
if (!is_dir($spoolpath)) {
|
if (!is_dir($spoolpath)) {
|
||||||
mkdir($spoolpath);
|
mkdir($spoolpath);
|
||||||
} elseif (!App::directory_usable($spoolpath)) {
|
|
||||||
$spoolpath = $temppath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (App::directory_usable($spoolpath)) {
|
if (App::directory_usable($spoolpath)) {
|
||||||
|
// The new path is usable, we are happy
|
||||||
set_config("system", "spoolpath", $spoolpath);
|
set_config("system", "spoolpath", $spoolpath);
|
||||||
return($spoolpath);
|
return $spoolpath;
|
||||||
|
} else {
|
||||||
|
// We can't create a subdirectory, strange.
|
||||||
|
// But the directory seems to work, so we use it but don't store it.
|
||||||
|
return $temppath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reaching this point means that the operating system is configured badly.
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2447,22 +2461,33 @@ function get_temppath() {
|
||||||
$temppath = get_config("system", "temppath");
|
$temppath = get_config("system", "temppath");
|
||||||
|
|
||||||
if (($temppath != "") AND App::directory_usable($temppath)) {
|
if (($temppath != "") AND App::directory_usable($temppath)) {
|
||||||
return($temppath);
|
// We have a temp path and it is usable
|
||||||
|
return $temppath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We don't have a working preconfigured temp path, so we take the system path.
|
||||||
$temppath = sys_get_temp_dir();
|
$temppath = sys_get_temp_dir();
|
||||||
|
|
||||||
|
// Check if it is usable
|
||||||
if (($temppath != "") AND App::directory_usable($temppath)) {
|
if (($temppath != "") AND App::directory_usable($temppath)) {
|
||||||
$temppath .= "/".$a->get_hostname();
|
// To avoid any interferences with other systems we create our own directory
|
||||||
if (!is_dir($temppath))
|
$new_temppath .= "/".$a->get_hostname();
|
||||||
mkdir($temppath);
|
if (!is_dir($new_temppath))
|
||||||
|
mkdir($new_temppath);
|
||||||
|
|
||||||
if (App::directory_usable($temppath)) {
|
if (App::directory_usable($new_temppath)) {
|
||||||
set_config("system", "temppath", $temppath);
|
// The new path is usable, we are happy
|
||||||
return($temppath);
|
set_config("system", "temppath", $new_temppath);
|
||||||
|
return $new_temppath;
|
||||||
|
} else {
|
||||||
|
// We can't create a subdirectory, strange.
|
||||||
|
// But the directory seems to work, so we use it but don't store it.
|
||||||
|
return $temppath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return("");
|
// Reaching this point means that the operating system is configured badly.
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @deprecated
|
/// @deprecated
|
||||||
|
|
|
@ -857,10 +857,15 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we store the data in the spool directory
|
// Now we store the data in the spool directory
|
||||||
$file = 'item-'.round(microtime(true) * 10000).".msg";
|
// We use "microtime" to keep the arrival order and "mt_rand" to avoid duplicates
|
||||||
$spool = get_spoolpath().'/'.$file;
|
$file = 'item-'.round(microtime(true) * 10000).'-'.mt_rand().'.msg';
|
||||||
|
|
||||||
|
$spoolpath = get_spoolpath();
|
||||||
|
if ($spoolpath != "") {
|
||||||
|
$spool = $spoolpath.'/'.$file;
|
||||||
file_put_contents($spool, json_encode($arr));
|
file_put_contents($spool, json_encode($arr));
|
||||||
logger("Item wasn't stored - Item was spooled into file ".$file, LOGGER_DEBUG);
|
logger("Item wasn't stored - Item was spooled into file ".$file, LOGGER_DEBUG);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,27 @@ function spool_post_run($argv, $argc) {
|
||||||
|
|
||||||
$path = get_spoolpath();
|
$path = get_spoolpath();
|
||||||
|
|
||||||
if (is_writable($path)){
|
if (($path != '') AND is_writable($path)){
|
||||||
if ($dh = opendir($path)) {
|
if ($dh = opendir($path)) {
|
||||||
while (($file = readdir($dh)) !== false) {
|
while (($file = readdir($dh)) !== false) {
|
||||||
|
|
||||||
|
// It is not named like a spool file, so we don't care.
|
||||||
|
if (substr($file, 0, 5) != "item-") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$fullfile = $path."/".$file;
|
$fullfile = $path."/".$file;
|
||||||
|
|
||||||
|
// We don't care about directories either
|
||||||
if (filetype($fullfile) != "file") {
|
if (filetype($fullfile) != "file") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We can't read or write the file? So we don't care about it.
|
||||||
|
if (!is_writable($fullfile) OR !is_readable($fullfile)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$arr = json_decode(file_get_contents($fullfile), true);
|
$arr = json_decode(file_get_contents($fullfile), true);
|
||||||
|
|
||||||
// If it isn't an array then it is no spool file
|
// If it isn't an array then it is no spool file
|
||||||
|
|
Loading…
Reference in a new issue