getPathname(); if (strpos($path_source, $source) !== 0) { continue; } if ($exclude_regexp && preg_match($exclude_regexp, $path_source)) { continue; } $path_destination = $destination . substr($path_source, strlen($source)); if ($path->isDir()) { $status = self::isDirectory($path_destination) || self::createDirectory($path_destination, $path->getPerms()); if (!$status) { return false; } } else { $status = self::copy($path_source, $path_destination, $path->getPerms()); if (!$status) { return false; } } } return true; } /** * Move a directory. * * @param string $source * @param string $destination * @return bool */ public static function moveDirectory($source, $destination) { return self::move($source, $destination); } /** * Delete a directory recursively. * * @param string $dirname * @param bool $delete_self (optional) * @return bool */ public static function deleteDirectory($dirname, $delete_self = true) { $dirname = rtrim($dirname, '/\\'); if (!self::exists($dirname)) { return false; } if (!self::isDirectory($dirname)) { trigger_error('Delete target is not a directory: ' . $dirname, \E_USER_WARNING); return false; } $rdi_options = \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS; $rii_options = \RecursiveIteratorIterator::CHILD_FIRST; $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dirname, $rdi_options), $rii_options); foreach ($iterator as $path) { if ($path->isDir()) { if (!@rmdir($path->getPathname())) { trigger_error('Cannot delete directory: ' . $path->getPathname(), \E_USER_WARNING); return false; } } else { if (!@unlink($path->getPathname())) { trigger_error('Cannot delete file: ' . $path->getPathname(), \E_USER_WARNING); return false; } } } if ($delete_self) { $result = @rmdir($dirname); if (!$result) { trigger_error('Cannot delete directory: ' . $dirname, \E_USER_WARNING); return false; } else { return true; } } else { return true; } } /** * Get the current umask. * * @return int */ public static function getUmask() { if (self::$_umask === null) { self::$_umask = intval(config('file.umask'), 8) ?: 0; } return self::$_umask; } /** * Set the current umask. * * @param int $umask * @return void */ public static function setUmask($umask) { self::$_umask = intval($umask); } /** * Determine the best umask for this installation of Rhymix. * * @return int */ public static function recommendUmask() { // On Windows, set the umask to 0000. if (strncasecmp(\PHP_OS, 'Win', 3) === 0) { return 0000; } // Get the UID of the owner of the current file. $file_uid = fileowner(__FILE__); // Get the UID of the current PHP process. if (function_exists('posix_geteuid')) { $php_uid = posix_geteuid(); } else { $testfile = \RX_BASEDIR . 'files/cache/uidcheck'; if (self::exists($testfile)) { self::delete($testfile); } if (self::write($testfile, 'TEST')) { $php_uid = fileowner($testfile); self::delete($testfile); } else { $php_uid = -1; } } // If both UIDs are the same, set the umask to 0022. if ($file_uid == $php_uid) { return 0022; } // Otherwise, set the umask to 0000. else { return 0000; } } }