diff --git a/pymods/irods_utils/irods_utils.py b/pymods/irods_utils/irods_utils.py index 70d5a69c379a951a2aeb9c7785808f2eefd10efb..a19d3c631c8a6de0b43a2594761c568006225915 100644 --- a/pymods/irods_utils/irods_utils.py +++ b/pymods/irods_utils/irods_utils.py @@ -391,14 +391,18 @@ def confirmed_put( irods_sesh, file_pathname, new_obj_ipath, metadata_dict=None, logging.error( f"FATAL: Failed to get size of file to upload. file_pathname: {file_pathname} ex: {ex}" ) raise - if upload_file_size == 0 and existing_obj != None and replace_existing and skip_on_zero_len : - logging.warning( f"got zero len file with replace_existing -- removing current data object. ipath: {new_obj_ipath}" ) - try: - existing_obj.unlink(force=True) - return 0 - except Exception as ex: - logging.warning( "Failed remove zero line file on replace_existing and skip_on_zero_len. ipath: {new_obj_ipath} ex: {ex} " ) - raise + # Return if zero sized objects are to be discarded. Check if an existing object needs to be removed. + if upload_file_size == 0 and skip_on_zero_len: + if existing_obj != None and replace_existing: + logging.warning( f"Got zero len file. Removing existing iRODS obj. file_pathname: {file_pathname} ipath: {new_obj_ipath}" ) + try: + existing_obj.unlink(force=True) + except Exception as ex: + logging.error( "Failed remove existing zero line file on replace_existing and skip_on_zero_len. ipath: {new_obj_ipath} ex: {ex} " ) + raise + else: + logging.debug( f"Got zero len file with skip_on_zero_len set. Returning. file_pathname: {file_pathname} ipath: {new_obj_ipath}" ) + return 0 # Make a timestamped partial tmp file name which, if the upload somehow fails here, will be left behind # Hopefully this does not happen much, but we have seen at least on case so far.