/**
* Method to determine if script owns the path.
*
* @param string $path Path to check ownership.
*
* @return boolean True if the php script owns the path passed.
*
* @since 1.7.0
*/
public static function isOwner($path)
{
$tmp = md5(Crypt::genRandomBytes());
$ssp = ini_get('session.save_path');
$jtp = JPATH_SITE . '/tmp';
// Try to find a writable directory
$dir = false;
foreach ([$jtp, $ssp, '/tmp'] as $currentDir) {
if (is_writable($currentDir)) {
$dir = $currentDir;
break;
}
}
if ($dir) {
$test = $dir . '/' . $tmp;
// Create the test file
$blank = '';
File::write($test, $blank, false);
// Test ownership
$return = fileowner($test) == fileowner($path);
// Delete the test file
File::delete($test);
return $return;
}
return false;
}