mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-06 11:57:10 +00:00
Removed RegionLoader::open()
this is nothing but a source of bugs.
This commit is contained in:
parent
edb590f681
commit
32c4a165cf
@ -80,15 +80,13 @@ class RegionLoader{
|
||||
/** @var int */
|
||||
public $lastUsed = 0;
|
||||
|
||||
public function __construct(string $filePath){
|
||||
$this->filePath = $filePath;
|
||||
$this->garbageTable = new RegionGarbageMap([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws CorruptedRegionException
|
||||
*/
|
||||
public function open() : void{
|
||||
public function __construct(string $filePath){
|
||||
$this->filePath = $filePath;
|
||||
$this->garbageTable = new RegionGarbageMap([]);
|
||||
|
||||
clearstatcache(false, $this->filePath);
|
||||
$exists = file_exists($this->filePath);
|
||||
if(!$exists){
|
||||
|
@ -115,24 +115,18 @@ abstract class RegionWorldProvider extends BaseWorldProvider{
|
||||
if(!isset($this->regions[$index = morton2d_encode($regionX, $regionZ)])){
|
||||
$path = $this->pathToRegion($regionX, $regionZ);
|
||||
|
||||
$region = new RegionLoader($path);
|
||||
try{
|
||||
$region->open();
|
||||
$this->regions[$index] = new RegionLoader($path);
|
||||
}catch(CorruptedRegionException $e){
|
||||
$logger = \GlobalLogger::get();
|
||||
$logger->error("Corrupted region file detected: " . $e->getMessage());
|
||||
|
||||
$region->close(); //Do not write anything to the file
|
||||
|
||||
$backupPath = $path . ".bak." . time();
|
||||
rename($path, $backupPath);
|
||||
$logger->error("Corrupted region file has been backed up to " . $backupPath);
|
||||
|
||||
$region = new RegionLoader($path);
|
||||
$region->open(); //this will create a new empty region to replace the corrupted one
|
||||
$this->regions[$index] = new RegionLoader($path); //this will create a new empty region to replace the corrupted one
|
||||
}
|
||||
|
||||
$this->regions[$index] = $region;
|
||||
}
|
||||
return $this->regions[$index];
|
||||
}
|
||||
|
@ -44,7 +44,6 @@ class RegionLoaderTest extends TestCase{
|
||||
unlink($this->regionPath);
|
||||
}
|
||||
$this->region = new RegionLoader($this->regionPath);
|
||||
$this->region->open();
|
||||
}
|
||||
|
||||
public function tearDown() : void{
|
||||
@ -65,7 +64,6 @@ class RegionLoaderTest extends TestCase{
|
||||
$this->region->close();
|
||||
|
||||
$r = new RegionLoader($this->regionPath);
|
||||
$r->open();
|
||||
self::assertSame($data, $r->readChunk(0, 0));
|
||||
}
|
||||
|
||||
@ -122,12 +120,10 @@ class RegionLoaderTest extends TestCase{
|
||||
public function testRegionHeaderCachedFilesizeRegression() : void{
|
||||
$this->region->close();
|
||||
$region = new RegionLoader($this->regionPath); //now we have a region, so the header will be verified, triggering two filesize() calls
|
||||
$region->open();
|
||||
$data = str_repeat("hello", 2000);
|
||||
$region->writeChunk(0, 0, $data); //add some data to the end of the file, to make the cached filesize invalid
|
||||
$region->close();
|
||||
$region = new RegionLoader($this->regionPath);
|
||||
$region->open();
|
||||
self::assertSame($data, $region->readChunk(0, 0));
|
||||
}
|
||||
}
|
||||
|
@ -107,9 +107,8 @@ function main(array $argv) : int{
|
||||
$doneCount = 0;
|
||||
$totalCount = count($files);
|
||||
foreach($files as $file => $size){
|
||||
$oldRegion = new RegionLoader($file);
|
||||
try{
|
||||
$oldRegion->open();
|
||||
$oldRegion = new RegionLoader($file);
|
||||
}catch(CorruptedRegionException $e){
|
||||
$logger->error("Damaged region in file $file (" . $e->getMessage() . "), skipping");
|
||||
$corruptedFiles[] = $file;
|
||||
@ -119,7 +118,6 @@ function main(array $argv) : int{
|
||||
|
||||
$newFile = $file . ".compacted";
|
||||
$newRegion = new RegionLoader($newFile);
|
||||
$newRegion->open();
|
||||
|
||||
$emptyRegion = true;
|
||||
$corruption = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user