mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-22 02:46:37 +00:00
PluginBase: make saveResource() use copy() instead of overengineered streams garbage
This commit is contained in:
parent
7826e0a11e
commit
37f2dafae1
@ -30,19 +30,16 @@ use pocketmine\command\PluginCommand;
|
|||||||
use pocketmine\lang\KnownTranslationFactory;
|
use pocketmine\lang\KnownTranslationFactory;
|
||||||
use pocketmine\scheduler\TaskScheduler;
|
use pocketmine\scheduler\TaskScheduler;
|
||||||
use pocketmine\Server;
|
use pocketmine\Server;
|
||||||
use pocketmine\utils\AssumptionFailedError;
|
|
||||||
use pocketmine\utils\Config;
|
use pocketmine\utils\Config;
|
||||||
use pocketmine\utils\Utils;
|
use pocketmine\utils\Utils;
|
||||||
use Symfony\Component\Filesystem\Path;
|
use Symfony\Component\Filesystem\Path;
|
||||||
|
use function copy;
|
||||||
use function count;
|
use function count;
|
||||||
use function dirname;
|
use function dirname;
|
||||||
use function fclose;
|
|
||||||
use function file_exists;
|
use function file_exists;
|
||||||
use function fopen;
|
|
||||||
use function mkdir;
|
use function mkdir;
|
||||||
use function rtrim;
|
use function rtrim;
|
||||||
use function str_contains;
|
use function str_contains;
|
||||||
use function stream_copy_to_stream;
|
|
||||||
use function strtolower;
|
use function strtolower;
|
||||||
use function trim;
|
use function trim;
|
||||||
use const DIRECTORY_SEPARATOR;
|
use const DIRECTORY_SEPARATOR;
|
||||||
@ -251,26 +248,21 @@ abstract class PluginBase implements Plugin, CommandExecutor{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$out = Path::join($this->dataFolder, $filename);
|
$source = Path::join($this->resourceFolder, $filename);
|
||||||
if(file_exists($out) && !$replace){
|
if(!file_exists($source)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(($resource = $this->getResource($filename)) === null){
|
$destination = Path::join($this->dataFolder, $filename);
|
||||||
|
if(file_exists($destination) && !$replace){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!file_exists(dirname($out))){
|
if(!file_exists(dirname($destination))){
|
||||||
mkdir(dirname($out), 0755, true);
|
mkdir(dirname($destination), 0755, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$fp = fopen($out, "wb");
|
return copy($source, $destination);
|
||||||
if($fp === false) throw new AssumptionFailedError("fopen() should not fail with wb flags");
|
|
||||||
|
|
||||||
$ret = stream_copy_to_stream($resource, $fp) > 0;
|
|
||||||
fclose($fp);
|
|
||||||
fclose($resource);
|
|
||||||
return $ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user