From 0348cf67a1d6313cfc243466640645973ef8f2a8 Mon Sep 17 00:00:00 2001 From: Justin James Date: Tue, 7 May 2024 17:28:42 -0400 Subject: [PATCH] [73] Implement preserve replication functionality --- DSI/globus_gridftp_server_iRODS.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/DSI/globus_gridftp_server_iRODS.cpp b/DSI/globus_gridftp_server_iRODS.cpp index 85b58b5..2692d54 100644 --- a/DSI/globus_gridftp_server_iRODS.cpp +++ b/DSI/globus_gridftp_server_iRODS.cpp @@ -46,6 +46,7 @@ extern "C" { #include #include #include +#include // boost includes #include @@ -212,6 +213,7 @@ int convert_base64_to_hex_string(const std::string& base64_str, const int& bit_c return 0; } +// removes all trailing slashes and replaces consecutive slashes with a single slash int iRODS_l_reduce_path( char * path) @@ -282,6 +284,9 @@ struct globus_l_gfs_iRODS_handle_t uint64_t irods_parallel_file_size_threshold_bytes; bool first_write_done; + + // added to get file modification time from client + time_t utime; }; std::condition_variable outstanding_cntr_cv; @@ -2004,6 +2009,8 @@ globus_l_gfs_iRODS_recv( globus_gfs_transfer_info_t * transfer_info, void * user_arg) { + namespace fs = irods::experimental::filesystem; + GlobusGFSName(globus_l_gfs_iRODS_recv); globus_gfs_log_message(GLOBUS_GFS_LOG_INFO, "iRODS: %s called\n", __FUNCTION__); @@ -2041,6 +2048,15 @@ globus_l_gfs_iRODS_recv( } } + result = globus_gridftp_server_get_recv_modification_time(op, &iRODS_handle->utime); + if(result != GLOBUS_SUCCESS) + { + // continue but don't modify utime + globus_gfs_log_message(GLOBUS_GFS_LOG_ERR,"iRODS: globus_gridftp_server_get_recv_modification_time error.\n"); + iRODS_handle->utime = -1; + } + globus_gfs_log_message(GLOBUS_GFS_LOG_INFO,"iRODS: globus_gridftp_server_get_recv_modification_time returned %lld.\n", static_cast(iRODS_handle->utime)); + // the main thread is the first writer so thread_pool starts number_of_irods_write_threads-1 threads irods::thread_pool threads{number_of_irods_write_threads-1}; @@ -2180,6 +2196,19 @@ globus_l_gfs_iRODS_recv( memset (&dataObjCloseInp, 0, sizeof (dataObjCloseInp)); dataObjCloseInp.l1descInx = iRODS_handle->fd; rcDataObjClose(iRODS_handle->conn, &dataObjCloseInp); + + // update the modify time if preservation option selected + if (iRODS_handle->utime > 0) + { + nlohmann::json json_input; + json_input["logical_path"] = collection; + json_input["options"]["no_create"] = true; + json_input["options"]["seconds_since_epoch"] = iRODS_handle->utime; + if (const auto ec = rc_touch(iRODS_handle->conn, json_input.dump().data()); ec < 0) { + globus_gfs_log_message(GLOBUS_GFS_LOG_ERR, + "iRODS: Caught an error trying to update the modify time for [%s]. Continuing without updating modify time.\n", collection); + } + } free(collection); collection = nullptr;