From ce7841bc87310c3cb9fe7b925781ed550f9ca5a3 Mon Sep 17 00:00:00 2001 From: Blake Fitch <blake.fitch@tuebingen.mpg.de> Date: Wed, 3 Jul 2024 13:21:45 +0200 Subject: [PATCH] separate case of skipping zero len file from removing (unlinking) preexisting iRODS object for replace_existing flag --- pymods/irods_utils/irods_utils.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pymods/irods_utils/irods_utils.py b/pymods/irods_utils/irods_utils.py index 70d5a69..a19d3c6 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. -- GitLab