File tree 1 file changed +19
-5
lines changed
1 file changed +19
-5
lines changed Original file line number Diff line number Diff line change 54
54
import tempfile
55
55
import os
56
56
import sys
57
+ import time
57
58
58
59
59
60
__all__ = ('LooseObjectDB' , )
@@ -204,8 +205,8 @@ def store(self, istream):
204
205
writer .close ()
205
206
# END assure target stream is closed
206
207
except :
207
- if tmp_path :
208
- os . remove (tmp_path )
208
+ with suppress ( FileNotFoundError ) :
209
+ remove (tmp_path )
209
210
raise
210
211
# END assure tmpfile removal on error
211
212
@@ -228,9 +229,22 @@ def store(self, istream):
228
229
rename (tmp_path , obj_path )
229
230
# end rename only if needed
230
231
231
- # make sure its readable for all ! It started out as rw-- tmp file
232
- # but needs to be rwrr
233
- chmod (obj_path , self .new_objects_mode )
232
+ # Ensure rename is actually done and file is stable
233
+ for _ in range (10 ): # Retry up to 10 times
234
+ with suppress (PermissionError ):
235
+ # make sure its readable for all ! It started out as rw-- tmp file
236
+ # but needs to be rwrr
237
+ chmod (obj_path , self .new_objects_mode )
238
+ break
239
+ time .sleep (0.1 )
240
+ else :
241
+ raise PermissionError (
242
+ "Impossible to apply `chmod` to file {}" .format (obj_path )
243
+ )
244
+
245
+ # Cleanup
246
+ with suppress (FileNotFoundError ):
247
+ remove (tmp_path )
234
248
# END handle dry_run
235
249
236
250
istream .binsha = hex_to_bin (hexsha )
You can’t perform that action at this time.
0 commit comments