@@ -377,26 +377,36 @@ def fix_problematic_chunks(self, status):
377
377
# read the data raw
378
378
m = region_file .metadata [local_coords [0 ], local_coords [1 ]]
379
379
region_file .file .seek (m .blockstart * region .SECTOR_LENGTH + 5 )
380
- raw_chunk = region_file .file .read (m .length - 1 )
381
- # decompress byte by byte so we can get as much as we can before the error happens
382
- try :
380
+ # these status doesn't provide a good enough data, we could end up reading garbage
381
+ if m .status not in (region .STATUS_CHUNK_IN_HEADER , region .STATUS_CHUNK_MISMATCHED_LENGTHS ,
382
+ region .STATUS_CHUNK_OUT_OF_FILE , region .STATUS_CHUNK_OVERLAPPING ,
383
+ region .STATUS_CHUNK_ZERO_LENGTH ):
384
+ # get the raw data of the chunk
385
+ raw_chunk = region_file .file .read (m .length - 1 )
386
+ # decompress byte by byte so we can get as much as we can before the error happens
383
387
dc = zlib .decompressobj ()
384
388
out = ""
385
389
for i in raw_chunk :
386
390
out += dc .decompress (i )
387
- except :
388
- pass
389
- # compare the sizes of the new compressed strem and the old one to see if we've got something good
390
- cdata = zlib .compress (out .encode ())
391
- if len (cdata ) == len (raw_chunk ):
392
- # the chunk is probably good, write it in the region file
393
- region_file .write_blockdata (local_coords [0 ], local_coords [1 ], out )
394
- print ("The chunk {0},{1} in region file {2} was fixed successfully." .format (local_coords [0 ], local_coords [1 ], self .filename ))
395
- else :
396
- print ("The chunk {0},{1} in region file {2} couldn't be fixed." .format (local_coords [0 ], local_coords [1 ], self .filename ))
397
- #print("Extracted: " + str(len(out)))
398
- #print("Size of the compressed stream: " + str(len(raw_chunk)))
399
-
391
+ # compare the sizes of the new compressed strem and the old one to see if we've got something good
392
+ cdata = zlib .compress (out .encode ())
393
+ if len (cdata ) == len (raw_chunk ):
394
+ # the chunk is probably good, write it in the region file
395
+ region_file .write_blockdata (local_coords [0 ], local_coords [1 ], out )
396
+ print ("The chunk {0},{1} in region file {2} was fixed successfully." .format (local_coords [0 ], local_coords [1 ], self .filename ))
397
+ else :
398
+ print ("The chunk {0},{1} in region file {2} couldn't be fixed." .format (local_coords [0 ], local_coords [1 ], self .filename ))
399
+ #=======================================================
400
+ # print("Extracted: " + str(len(out)))
401
+ # print("Size of the compressed stream: " + str(len(raw_chunk)))
402
+ #=======================================================
403
+ except region .ChunkHeaderError :
404
+ # usually a chunk with zero length, pass
405
+ print ("The chunk {0},{1} in region file {2} couldn't be fixed." .format (local_coords [0 ], local_coords [1 ], self .filename ))
406
+ except region .RegionHeaderError :
407
+ # usually a chunk with zero length, pass
408
+ print ("The chunk {0},{1} in region file {2} couldn't be fixed." .format (local_coords [0 ], local_coords [1 ], self .filename ))
409
+
400
410
if status == c .CHUNK_MISSING_ENTITIES_TAG :
401
411
# The arguments to create the empty TAG_List have been somehow extracted by comparing
402
412
# the tag list from a healthy chunk with the one created by nbt
@@ -994,7 +1004,7 @@ def generate_report(self, standalone):
994
1004
table_data = []
995
1005
table_data .append (['Problem' , 'Count' ])
996
1006
for p in c .CHUNK_PROBLEMS :
997
- if chunk_counts [p ] is not 0 :
1007
+ if chunk_counts [p ] != 0 :
998
1008
table_data .append ([c .CHUNK_STATUS_TEXT [p ], chunk_counts [p ]])
999
1009
table_data .append (['Total' , chunk_counts ['TOTAL' ]])
1000
1010
text += table (table_data )
@@ -1007,7 +1017,7 @@ def generate_report(self, standalone):
1007
1017
table_data = []
1008
1018
table_data .append (['Problem' , 'Count' ])
1009
1019
for p in c .REGION_PROBLEMS :
1010
- if region_counts [p ] is not 0 :
1020
+ if region_counts [p ] != 0 :
1011
1021
table_data .append ([c .REGION_STATUS_TEXT [p ], region_counts [p ]])
1012
1022
table_data .append (['Total' , region_counts ['TOTAL' ]])
1013
1023
text += table (table_data )
@@ -1561,7 +1571,7 @@ def generate_report(self, standalone):
1561
1571
table_data = []
1562
1572
table_data .append (['Problem' , 'Count' ])
1563
1573
for p in c .CHUNK_PROBLEMS :
1564
- if chunk_counts [p ] is not 0 :
1574
+ if chunk_counts [p ] != 0 :
1565
1575
table_data .append ([c .CHUNK_STATUS_TEXT [p ], chunk_counts [p ]])
1566
1576
table_data .append (['Total' , chunk_counts ['TOTAL' ]])
1567
1577
text += table (table_data )
@@ -1574,7 +1584,7 @@ def generate_report(self, standalone):
1574
1584
table_data = []
1575
1585
table_data .append (['Problem' , 'Count' ])
1576
1586
for p in c .REGION_PROBLEMS :
1577
- if region_counts [p ] is not 0 :
1587
+ if region_counts [p ] != 0 :
1578
1588
table_data .append ([c .REGION_STATUS_TEXT [p ], region_counts [p ]])
1579
1589
table_data .append (['Total' , region_counts ['TOTAL' ]])
1580
1590
text += table (table_data )
0 commit comments