Skip to content
Snippets Groups Projects
Commit b9eff656 authored by Laurent Peuch's avatar Laurent Peuch Committed by GitHub
Browse files

Merge pull request #76 from ryu2/master

Recover from corrupted cache file
parents 7d7b163d 1cf3c013
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -63,16 +63,23 @@ class BaronParserGenerator(ParserGenerator):
table = None
if os.path.exists(cache_file):
with open(cache_file) as f:
data = json.load(f)
stat_result = os.fstat(f.fileno())
if (
os.name == "nt" or (
stat_result.st_uid == os.getuid() and
stat.S_IMODE(stat_result.st_mode) == 0o0600
)
):
if self.data_is_valid(g, data):
table = LRTable.from_cache(g, data)
try:
data = json.load(f)
except:
os.remove(cache_file)
data = None
if data is not None:
stat_result = os.fstat(f.fileno())
if (
os.name == "nt" or (
stat_result.st_uid == os.getuid() and
stat.S_IMODE(stat_result.st_mode) == 0o0600
)
):
if self.data_is_valid(g, data):
table = LRTable.from_cache(g, data)
if table is None:
table = LRTable.from_grammar(g)
try:
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment