@@ -1311,8 +1311,11 @@ def validate_meta(meta: Optional[CacheMeta], id: str, path: Optional[str],
1311
1311
assert path is not None , "Internal error: meta was provided without a path"
1312
1312
if not manager .options .skip_cache_mtime_checks :
1313
1313
# Check data_json; assume if its mtime matches it's good.
1314
- # TODO: stat() errors
1315
- data_mtime = manager .getmtime (meta .data_json )
1314
+ try :
1315
+ data_mtime = manager .getmtime (meta .data_json )
1316
+ except OSError :
1317
+ manager .log ('Metadata abandoned for {}: failed to stat data_json' .format (id ))
1318
+ return None
1316
1319
if data_mtime != meta .data_mtime :
1317
1320
manager .log ('Metadata abandoned for {}: data cache is modified' .format (id ))
1318
1321
return None
@@ -1508,9 +1511,6 @@ def write_cache(id: str, path: str, tree: MypyFile,
1508
1511
# Write data cache file, if applicable
1509
1512
# Note that for Bazel we don't record the data file's mtime.
1510
1513
if old_interface_hash == interface_hash :
1511
- # If the interface is unchanged, the cached data is guaranteed
1512
- # to be equivalent, and we only need to update the metadata.
1513
- data_mtime = manager .getmtime (data_json )
1514
1514
manager .trace ("Interface for {} is unchanged" .format (id ))
1515
1515
else :
1516
1516
manager .trace ("Interface for {} has changed" .format (id ))
@@ -1527,7 +1527,12 @@ def write_cache(id: str, path: str, tree: MypyFile,
1527
1527
# Both have the effect of slowing down the next run a
1528
1528
# little bit due to an out-of-date cache file.
1529
1529
return interface_hash , None
1530
+
1531
+ try :
1530
1532
data_mtime = manager .getmtime (data_json )
1533
+ except OSError :
1534
+ manager .log ("Error in os.stat({!r}), skipping cache write" .format (data_json ))
1535
+ return interface_hash , None
1531
1536
1532
1537
mtime = 0 if bazel else int (st .st_mtime )
1533
1538
size = st .st_size
0 commit comments