move isDirectoryUsable to System

This commit is contained in:
Philipp Holzer 2019-02-05 22:30:18 +01:00
parent 6a9d73f7d9
commit b79bd63231
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
4 changed files with 47 additions and 49 deletions

View file

@ -303,6 +303,44 @@ class System extends BaseObject
return $processUser['name'];
}
/**
* @brief Checks if a given directory is usable for the system
*
* @param $directory
* @param bool $check_writable
*
* @return boolean the directory is usable
*/
public static function isDirectoryUsable($directory, $check_writable = true)
{
if ($directory == '') {
Logger::log('Directory is empty. This shouldn\'t happen.', Logger::DEBUG);
return false;
}
if (!file_exists($directory)) {
Logger::log('Path "' . $directory . '" does not exist for user ' . static::getUser(), Logger::DEBUG);
return false;
}
if (is_file($directory)) {
Logger::log('Path "' . $directory . '" is a file for user ' . static::getUser(), Logger::DEBUG);
return false;
}
if (!is_dir($directory)) {
Logger::log('Path "' . $directory . '" is not a directory for user ' . static::getUser(), Logger::DEBUG);
return false;
}
if ($check_writable && !is_writable($directory)) {
Logger::log('Path "' . $directory . '" is not writable for user ' . static::getUser(), Logger::DEBUG);
return false;
}
return true;
}
/// @todo Move the following functions from boot.php
/*
function killme()