@@ -897,12 +897,17 @@ def write_cache(id: str, path: str, tree: MypyFile,
897
897
data_mtime = os .path .getmtime (data_json )
898
898
manager .trace ("Interface for {} is unchanged" .format (id ))
899
899
else :
900
- with open (data_json_tmp , 'w' ) as f :
901
- f .write (data_str )
902
- f .write ('\n ' )
903
- data_mtime = os .path .getmtime (data_json_tmp )
904
- os .replace (data_json_tmp , data_json )
905
900
manager .trace ("Interface for {} has changed" .format (id ))
901
+ try :
902
+ with open (data_json_tmp , 'w' ) as f :
903
+ f .write (data_str )
904
+ f .write ('\n ' )
905
+ os .replace (data_json_tmp , data_json )
906
+ data_mtime = os .path .getmtime (data_json )
907
+ except os .error as err :
908
+ # Most likely the error is the replace() call
909
+ # (see https://github.com/python/mypy/issues/3215).
910
+ manager .log ("Error writing data JSON file {}" .format (data_json_tmp ))
906
911
907
912
mtime = st .st_mtime
908
913
size = st .st_size
@@ -922,12 +927,17 @@ def write_cache(id: str, path: str, tree: MypyFile,
922
927
}
923
928
924
929
# Write meta cache file
925
- with open (meta_json_tmp , 'w' ) as f :
926
- if manager .options .debug_cache :
927
- json .dump (meta , f , indent = 2 , sort_keys = True )
928
- else :
929
- json .dump (meta , f )
930
- os .replace (meta_json_tmp , meta_json )
930
+ try :
931
+ with open (meta_json_tmp , 'w' ) as f :
932
+ if manager .options .debug_cache :
933
+ json .dump (meta , f , indent = 2 , sort_keys = True )
934
+ else :
935
+ json .dump (meta , f )
936
+ os .replace (meta_json_tmp , meta_json )
937
+ except os .error as err :
938
+ # Most likely the error is the replace() call
939
+ # (see https://github.com/python/mypy/issues/3215).
940
+ manager .log ("Error writing meta JSON file {}" .format (meta_json_tmp ))
931
941
932
942
return interface_hash
933
943
0 commit comments