From 278966a256bd7229a08623727722dc003e43b2dc Mon Sep 17 00:00:00 2001 From: David Vierra Date: Mon, 8 Jun 2015 00:38:50 -1000 Subject: [PATCH] RevisionHistory: fix various functions not respecting deadChunks/deadFiles chunkPositions now removes dead chunks from the returned chunks readChunkBytes raises ChunkNotPresent for dead chunks readFile raises IOError for dead files --- src/mceditlib/revisionhistory.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/mceditlib/revisionhistory.py b/src/mceditlib/revisionhistory.py index c41074a..6de7cb7 100644 --- a/src/mceditlib/revisionhistory.py +++ b/src/mceditlib/revisionhistory.py @@ -556,12 +556,28 @@ class RevisionHistoryNode(object): raise RuntimeError("Accessing invalid node: %r" % self) node = self pos = set() + dead = set() + + # + # If a node is found in deadChunks: + # if found again in a later revision, it is alive + # if found again in this revision, it is still alive + # otherwise, it is dead + # + # `pos` contains all chunks found in this and later revisions. + # Thus, `pos` should be subtracted from `deadChunks` before adding `deadChunks` to `dead` + while node: - pos.update(node.worldFolder.chunkPositions(dimName)) + nodepos = set(node.worldFolder.chunkPositions(dimName)) + pos.update(nodepos) + + nodedead = set((cx, cz) for cx, cz, deadDim in node.deadChunks if deadDim == dimName) + nodedead.difference_update(pos) + dead.update(nodedead) node = node.parentNode - return pos + return pos - dead def chunkCount(self, dimName): node = self @@ -619,6 +635,8 @@ class RevisionHistoryNode(object): node = self while node: # Ask RevisionHistory for most recent node containing this chunk? + if (cx, cz, dimName) in node.deadChunks: + raise ChunkNotPresent((cx, cz), "Chunk was deleted") if node.worldFolder.containsChunk(cx, cz, dimName): data = node.worldFolder.readChunkBytes(cx, cz, dimName) return data @@ -694,6 +712,8 @@ class RevisionHistoryNode(object): raise RuntimeError("Accessing invalid node: %r" % self) node = self while node: + if path in node.deadFiles: + raise IOError("File not found (deleted)") if node.worldFolder.containsFile(path): data = node.worldFolder.readFile(path) if data is not None: