File tree 2 files changed +19
-6
lines changed 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -180,12 +180,24 @@ impl Cache {
180
180
. write_all ( & serialized)
181
181
. context ( "Failed to write serialized cache to temporary file." ) ?;
182
182
183
- temp_file. persist ( & self . path ) . with_context ( || {
184
- format ! (
185
- "Failed to rename temporary cache file to {}" ,
186
- self . path. display( )
187
- )
188
- } ) ?;
183
+ if let Err ( err) = temp_file. persist ( & self . path ) {
184
+ // On Windows, writing to the cache file can fail if the file is still open (e.g., if
185
+ // the user is running Ruff from multiple processes over the same directory).
186
+ if cfg ! ( windows) && err. error . kind ( ) == io:: ErrorKind :: PermissionDenied {
187
+ warn_user ! (
188
+ "Failed to write cache file '{}': {}" ,
189
+ self . path. display( ) ,
190
+ err. error
191
+ ) ;
192
+ } else {
193
+ return Err ( err) . with_context ( || {
194
+ format ! (
195
+ "Failed to rename temporary cache file to {}" ,
196
+ self . path. display( )
197
+ )
198
+ } ) ;
199
+ }
200
+ }
189
201
190
202
Ok ( ( ) )
191
203
}
Original file line number Diff line number Diff line change @@ -176,6 +176,7 @@ pub(crate) fn format(
176
176
duration
177
177
) ;
178
178
179
+ // Store the caches.
179
180
caches. persist ( ) ?;
180
181
181
182
// Report on any errors.
You can’t perform that action at this time.
0 commit comments