@@ -802,7 +802,8 @@ def _setcontents(self,
802802 errors = None ,
803803 chunk_size = 1024 * 64 ,
804804 progress_callback = None ,
805- finished_callback = None ):
805+ finished_callback = None ,
806+ bypass_lock = False ):
806807 """Does the work of setcontents. Factored out, so that `setcontents_async` can use it"""
807808 if progress_callback is None :
808809 progress_callback = lambda bytes_written : None
@@ -822,9 +823,10 @@ def _setcontents(self,
822823 read = data .read
823824 chunk = read (chunk_size )
824825 if isinstance (chunk , six .text_type ):
825- f = self .open (path , 'wt' , encoding = encoding , errors = errors )
826+ f = self .open (path , 'wt' , encoding = encoding , errors = errors ,
827+ bypass_lock = bypass_lock )
826828 else :
827- f = self .open (path , 'wb' )
829+ f = self .open (path , 'wb' , bypass_lock = bypass_lock )
828830 write = f .write
829831 try :
830832 while chunk :
@@ -848,7 +850,8 @@ def _setcontents(self,
848850 finished_callback ()
849851 return bytes_written
850852
851- def setcontents (self , path , data = b'' , encoding = None , errors = None , chunk_size = 1024 * 64 ):
853+ def setcontents (self , path , data = b'' , encoding = None , errors = None ,
854+ chunk_size = 1024 * 64 , bypass_lock = False ):
852855 """A convenience method to create a new file from a string or file-like object
853856
854857 :param path: a path of the file to create
@@ -858,7 +861,7 @@ def setcontents(self, path, data=b'', encoding=None, errors=None, chunk_size=102
858861 :param chunk_size: Number of bytes to read in a chunk, if the implementation has to resort to a read / copy loop
859862
860863 """
861- return self ._setcontents (path , data , encoding = encoding , errors = errors , chunk_size = 1024 * 64 )
864+ return self ._setcontents (path , data , encoding = encoding , errors = errors , chunk_size = 1024 * 64 , bypass_lock = bypass_lock )
862865
863866 def setcontents_async (self ,
864867 path ,
@@ -1143,7 +1146,8 @@ def copy(self, src, dst, overwrite=False, chunk_size=1024 * 64):
11431146 src_file = None
11441147 try :
11451148 src_file = self .open (src , "rb" )
1146- self .setcontents (dst , src_file , chunk_size = chunk_size )
1149+ self .setcontents (dst , src_file , chunk_size = chunk_size ,
1150+ bypass_lock = True )
11471151 except ResourceNotFoundError :
11481152 if self .exists (src ) and not self .exists (dirname (dst )):
11491153 raise ParentDirectoryMissingError (dst )
0 commit comments