Removed RegionLoader::open()

this is nothing but a source of bugs.
This commit is contained in:
Dylan K. Taylor
2021-04-15 15:38:18 +01:00
parent edb590f681
commit 32c4a165cf
4 changed files with 7 additions and 21 deletions

View File

@ -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){

View File

@ -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];
}