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