@@ -1311,8 +1311,11 @@ def validate_meta(meta: Optional[CacheMeta], id: str, path: Optional[str],
13111311 assert path is not None , "Internal error: meta was provided without a path"
13121312 if not manager .options .skip_cache_mtime_checks :
13131313 # 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
13161319 if data_mtime != meta .data_mtime :
13171320 manager .log ('Metadata abandoned for {}: data cache is modified' .format (id ))
13181321 return None
@@ -1508,9 +1511,6 @@ def write_cache(id: str, path: str, tree: MypyFile,
15081511 # Write data cache file, if applicable
15091512 # Note that for Bazel we don't record the data file's mtime.
15101513 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 )
15141514 manager .trace ("Interface for {} is unchanged" .format (id ))
15151515 else :
15161516 manager .trace ("Interface for {} has changed" .format (id ))
@@ -1527,7 +1527,12 @@ def write_cache(id: str, path: str, tree: MypyFile,
15271527 # Both have the effect of slowing down the next run a
15281528 # little bit due to an out-of-date cache file.
15291529 return interface_hash , None
1530+
1531+ try :
15301532 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
15311536
15321537 mtime = 0 if bazel else int (st .st_mtime )
15331538 size = st .st_size
0 commit comments