Skip to content

Commit

Permalink
[73] Implement preserve replication functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinKyleJames committed May 8, 2024
1 parent 946bf88 commit 0348cf6
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions DSI/globus_gridftp_server_iRODS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extern "C" {
#include <irods/thread_pool.hpp>
#include <irods/filesystem.hpp>
#include <irods/base64.hpp>
#include <irods/touch.h>

// boost includes
#include <boost/algorithm/string.hpp>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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__);
Expand Down Expand Up @@ -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<long long>(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};

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0348cf6

Please sign in to comment.