Start using webmozart/pathutil for joining paths (#4287)

This commit is contained in:
Dylan T
2021-06-29 19:40:43 +01:00
committed by GitHub
parent aee7b03c1d
commit 32d7b1e6af
31 changed files with 252 additions and 172 deletions

View File

@@ -31,6 +31,7 @@ use pocketmine\scheduler\TaskScheduler;
use pocketmine\Server;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\Config;
use Webmozart\PathUtil\Path;
use function count;
use function dirname;
use function fclose;
@@ -86,7 +87,7 @@ abstract class PluginBase implements Plugin, CommandExecutor{
$this->dataFolder = rtrim($dataFolder, "/" . DIRECTORY_SEPARATOR) . "/";
//TODO: this is accessed externally via reflection, not unused
$this->file = rtrim($file, "/" . DIRECTORY_SEPARATOR) . "/";
$this->configFile = $this->dataFolder . "config.yml";
$this->configFile = Path::join($this->dataFolder, "config.yml");
$prefix = $this->getDescription()->getPrefix();
$this->logger = new PluginLogger($server->getLogger(), $prefix !== "" ? $prefix : $this->getName());
@@ -261,7 +262,7 @@ abstract class PluginBase implements Plugin, CommandExecutor{
return false;
}
$out = $this->dataFolder . $filename;
$out = Path::join($this->dataFolder, $filename);
if(!file_exists(dirname($out))){
mkdir(dirname($out), 0755, true);
}

View File

@@ -39,6 +39,7 @@ use pocketmine\Server;
use pocketmine\timings\TimingsHandler;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\Utils;
use Webmozart\PathUtil\Path;
use function array_intersect;
use function array_merge;
use function class_exists;
@@ -59,7 +60,6 @@ use function shuffle;
use function stripos;
use function strpos;
use function strtolower;
use const DIRECTORY_SEPARATOR;
/**
* Manages all the plugins
@@ -121,9 +121,9 @@ class PluginManager{
private function getDataDirectory(string $pluginPath, string $pluginName) : string{
if($this->pluginDataDirectory !== null){
return $this->pluginDataDirectory . $pluginName;
return Path::join($this->pluginDataDirectory, $pluginName);
}
return dirname($pluginPath) . DIRECTORY_SEPARATOR . $pluginName;
return Path::join(dirname($pluginPath), $pluginName);
}
/**