File tree Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Original file line number Diff line number Diff line change 5454import tempfile
5555import os
5656import sys
57+ import time
5758
5859
5960__all__ = ('LooseObjectDB' , )
@@ -204,8 +205,8 @@ def store(self, istream):
204205 writer .close ()
205206 # END assure target stream is closed
206207 except :
207- if tmp_path :
208- os . remove (tmp_path )
208+ with suppress ( FileNotFoundError ) :
209+ remove (tmp_path )
209210 raise
210211 # END assure tmpfile removal on error
211212
@@ -228,9 +229,22 @@ def store(self, istream):
228229 rename (tmp_path , obj_path )
229230 # end rename only if needed
230231
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 )
234248 # END handle dry_run
235249
236250 istream .binsha = hex_to_bin (hexsha )
You can’t perform that action at this time.
0 commit comments