diff --git a/pymods/irods_utils/irods_utils.py b/pymods/irods_utils/irods_utils.py index 51da26d2cabb4be6710371aa2e9fab9f1714fc10..9fc32f8b4c4d816893f00fd95fd4ef7382898c0c 100644 --- a/pymods/irods_utils/irods_utils.py +++ b/pymods/irods_utils/irods_utils.py @@ -350,11 +350,12 @@ def streaming_transfer_file_to_object( args ): return rc, hash_digest256, hash_digest512, transfer_size # Returns None or the data_object irods ref. -def confirmed_put( irods_sesh, file_pathname, new_obj_ipath, metadata_dict=None, datatype=None, block_size=(2**28) ): +def confirmed_put( irods_sesh, file_pathname, new_obj_ipath, metadata_dict=None, datatype=None, block_size=(2**28), replace_existing=None ): logging.debug( "file_pathname: " + file_pathname + " new_obj_ipath: " + new_obj_ipath + " datatype: " + datatype - + " block_size: " + str( block_size ) ) + + " block_size: " + str( block_size ) + + " replace_existing " + str( replace_existing) ) # NOTE: this routine uploades the file as a temporary iRODS object. # Common sense suggests checking if the objct already exsists, a rare condition first. @@ -504,6 +505,14 @@ def confirmed_put( irods_sesh, file_pathname, new_obj_ipath, metadata_dict=None, logging.debug( "file " + file_pathname + " in place at ipath " + new_obj_ipath ) + if existing_obj != None and replace_existing: + logging.warning( f"replace_existing flag set. Removing old data object. ipath: {dup_ipath}" ) + try: + dup_obj = irods_sesh.data_objects.get( dup_ipath ) + dup_obj.unlink(force=True) + except Exception as ex: + logging.warning( "Failed remove dup when remove_existing flag set. ipath: {dup_ipath} ex: {ex} " ) + new_obj = None try: new_obj = irods_sesh.data_objects.get( new_obj_ipath )