@@ -254,13 +254,24 @@ def rename(self, source_file_names, destination_file_names):
254254 gcs_batches .append (gcs_current_batch )
255255
256256 # Execute GCS renames if any and return exceptions.
257- try :
258- for batch in gcs_batches :
259- self ._gcsIO ().copy_batch (batch )
260- self ._gcsIO ().delete_batch (source_file_names )
257+ exceptions = {}
258+ for batch in gcs_batches :
259+ copy_statuses = self ._gcsIO ().copy_batch (batch )
260+ copy_succeeded = []
261+ for src , dest , exception in copy_statuses :
262+ if exception :
263+ exceptions [(src , dest )] = exception
264+ else :
265+ copy_succeeded .append ((src , dest ))
266+ delete_batch = [src for src , dest in copy_succeeded ]
267+ delete_statuses = self ._gcsIO ().delete_batch (delete_batch )
268+ for i , (src , exception ) in enumerate (delete_statuses ):
269+ dest = copy_succeeded [i ][1 ]
270+ if exception :
271+ exceptions [(src , dest )] = exception
261272
262- except Exception as exception :
263- raise BeamIOError ("Rename operation failed" , exception )
273+ if exceptions :
274+ raise BeamIOError ("Rename operation failed" , exceptions )
264275
265276 def exists (self , path ):
266277 """Check if the provided path exists on the FileSystem.
@@ -329,7 +340,8 @@ def metadata(self, path):
329340 """
330341 try :
331342 file_metadata = self ._gcsIO ()._status (path )
332- return FileMetadata (path , file_metadata ['size' ], file_metadata ['updated' ])
343+ return FileMetadata (
344+ path , file_metadata ['size' ], file_metadata ['last_updated' ])
333345 except Exception as e : # pylint: disable=broad-except
334346 raise BeamIOError ("Metadata operation failed" , {path : e })
335347
@@ -348,7 +360,12 @@ def _delete_path(path):
348360 else :
349361 path_to_use = path
350362 match_result = self .match ([path_to_use ])[0 ]
351- self ._gcsIO ().delete_batch ([m .path for m in match_result .metadata_list ])
363+ statuses = self ._gcsIO ().delete_batch (
364+ [m .path for m in match_result .metadata_list ])
365+ # pylint: disable=used-before-assignment
366+ failures = [e for (_ , e ) in statuses if e is not None ]
367+ if failures :
368+ raise failures [0 ]
352369
353370 exceptions = {}
354371 for path in paths :
0 commit comments