irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

rsFileSyncToArch.cpp
Go to the documentation of this file.
1 
3 /* rsFileSyncToArch.c - server routine that handles the fileSyncToArch
4  * API
5  */
6 
7 /* script generated code */
8 #include "fileSyncToArch.h"
9 #include "fileOpr.hpp"
10 #include "miscServerFunct.hpp"
11 #include "dataObjOpr.hpp"
12 #include "physPath.hpp"
13 #include "rsFileSyncToArch.hpp"
14 
15 // =-=-=-=-=-=-=-
16 #include "irods_log.hpp"
17 #include "irods_file_object.hpp"
19 #include "irods_stacktrace.hpp"
21 
23  rsComm_t* rsComm,
24  fileStageSyncInp_t* fileSyncToArchInp,
25  fileSyncOut_t** sync_out ) {
27  int remoteFlag;
28  int status;
29 
30  ( *sync_out ) = ( fileSyncOut_t* )malloc( sizeof( fileSyncOut_t ) );
31  bzero( ( *sync_out ), sizeof( fileSyncOut_t ) );
32 
33 // remoteFlag = resolveHost (&fileSyncToArchInp->addr, &rodsServerHost);
34  irods::error ret = irods::get_host_for_hier_string( fileSyncToArchInp->rescHier, remoteFlag, rodsServerHost );
35  if ( !ret.ok() ) {
36  irods::log( PASSMSG( "failed in call to irods::get_host_for_hier_string", ret ) );
37  return -1;
38  }
39 
40  if ( remoteFlag < 0 ) {
41  return remoteFlag;
42  }
43  else {
44  status = rsFileSyncToArchByHost( rsComm, fileSyncToArchInp, sync_out, rodsServerHost );
45  return status;
46  }
47 }
48 
49 int
51  int status;
52  int remoteFlag;
53 
54  if ( rodsServerHost == NULL ) {
56  "rsFileSyncToArchByHost: Input NULL rodsServerHost" );
58  }
59 
60  remoteFlag = rodsServerHost->localFlag;
61 
62  if ( remoteFlag == LOCAL_HOST ) {
63  status = _rsFileSyncToArch( rsComm, fileSyncToArchInp, sync_out );
64  }
65  else if ( remoteFlag == REMOTE_HOST ) {
66  status = remoteFileSyncToArch( rsComm, fileSyncToArchInp, sync_out, rodsServerHost );
67  }
68  else {
69  if ( remoteFlag < 0 ) {
70  return remoteFlag;
71  }
72  else {
74  "rsFileSyncToArchByHost: resolveHost returned value %d",
75  remoteFlag );
77  }
78  }
79 
80  return status;
81 }
82 
83 int
85  int status;
86 
87  if ( rodsServerHost == NULL ) {
89  "remoteFileSyncToArch: Invalid rodsServerHost" );
91  }
92 
93  if ( ( status = svrToSvrConnect( rsComm, rodsServerHost ) ) < 0 ) {
94  return status;
95  }
96 
97  status = rcFileSyncToArch( rodsServerHost->conn, fileSyncToArchInp, sync_out );
98 
99  if ( status < 0 ) {
101  "remoteFileSyncToArch: rcFileSyncToArch failed for %s",
102  fileSyncToArchInp->filename );
103  }
104 
105  return status;
106 }
107 
108 // =-=-=-=-=-=-=-=
109 // _rsFileSyncToArch - this the local version of rsFileSyncToArch.
111  rsComm_t* _comm,
112  fileStageSyncInp_t* _sync_inp,
113  fileSyncOut_t** _sync_out ) {
114  // =-=-=-=-=-=-=-
115  // XXXX need to check resource permission and vault permission
116  // when RCAT is available
117 
118  // =-=-=-=-=-=-=-
119  // prep
120  if ( _sync_inp->objPath[0] == '\0' ) {
121  std::stringstream msg;
122  msg << __FUNCTION__;
123  msg << " - Empty logical path.";
124  irods::log( LOG_ERROR, msg.str() );
126  }
127 
128  // =-=-=-=-=-=-=-
129  // make call to synctoarch via resource plugin
130  irods::file_object_ptr file_obj(
131  new irods::file_object(
132  _comm,
133  _sync_inp->objPath,
134  _sync_inp->filename, "", 0,
135  _sync_inp->mode,
136  _sync_inp->flags ) );
137  file_obj->resc_hier( _sync_inp->rescHier );
138 
139  // =-=-=-=-=-=-=-
140  // pass condInput
141  file_obj->cond_input( _sync_inp->condInput );
142 
143  // set object id if provided
144  char *id_str = getValByKey(&_sync_inp->condInput, DATA_ID_KW);
145  if (id_str) {
146  file_obj->id(strtol(id_str, NULL, 10));
147  }
148 
149  irods::error sync_err = fileSyncToArch( _comm, file_obj, _sync_inp->cacheFilename );
150 
151  if ( !sync_err.ok() ) {
152 
153  if ( getErrno( sync_err.code() ) == ENOENT ) {
154  // =-=-=-=-=-=-=-
155  // the directory does not exist, lets make one
156  int status = mkDirForFilePath(
157  _comm,
158  0,
159  _sync_inp->filename,
160  _sync_inp->rescHier,
161  getDefDirMode() );
162  if ( status < 0 ) {
163  rodsLog( LOG_ERROR, "mkDirForFilePath failed in _rsFileSyncToArch with status %d", status );
164  return status;
165  }
166  }
167  else if ( getErrno( sync_err.code() ) == EEXIST ) {
168  // =-=-=-=-=-=-=-
169  // an empty dir may be there, make the call to rmdir via the resource plugin
172  _sync_inp->filename,
173  _sync_inp->rescHier,
174  0, 0 ) );
175  coll_obj->cond_input( _sync_inp->condInput );
176  irods::error rmdir_err = fileRmdir( _comm, coll_obj );
177  if ( !rmdir_err.ok() ) {
178  std::stringstream msg;
179  msg << "fileRmdir failed for [";
180  msg << _sync_inp->filename;
181  msg << "]";
182  irods::error err = PASSMSG( msg.str(), sync_err );
183  irods::log( err );
184  }
185  }
186  else {
187  std::stringstream msg;
188  msg << "fileSyncToArch failed for [";
189  msg << _sync_inp->filename;
190  msg << "]";
191  irods::error err = PASSMSG( msg.str(), sync_err );
192  irods::log( err );
193  return sync_err.code();
194  }
195 
196  // =-=-=-=-=-=-=-
197  // make call to synctoarch via resource plugin
198  sync_err = fileSyncToArch( _comm, file_obj, _sync_inp->cacheFilename );
199  if ( !sync_err.ok() ) {
200  std::stringstream msg;
201  msg << "fileSyncToArch failed for [";
202  msg << _sync_inp->filename;
203  msg << "]";
204  msg << sync_err.code();
205  irods::error err = PASSMSG( msg.str(), sync_err );
206  irods::log( err );
207  }
208 
209  } // if !sync_err.ok()
210 
211  // =-=-=-=-=-=-=-
212  // has the file name has changed?
213  if ( *_sync_out ) {
214  rstrcpy( ( *_sync_out )->file_name, file_obj->physical_path().c_str(), MAX_NAME_LEN );
215  }
216 
217  return sync_err.code();
218 
219 } // _rsFileSyncToArch
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
getValByKey
char * getValByKey(const keyValPair_t *condInput, const char *keyWord)
Definition: rcMisc.cpp:675
fileStageSyncInp_t::mode
int mode
Definition: fileStageToCache.h:10
NULL
#define NULL
Definition: rodsDef.h:70
rsComm_t
Definition: rcConnect.h:145
getDefDirMode
int getDefDirMode()
Definition: physPath.cpp:1070
fileStageSyncInp_t::condInput
keyValPair_t condInput
Definition: fileStageToCache.h:18
SYS_INTERNAL_NULL_INPUT_ERR
@ SYS_INTERNAL_NULL_INPUT_ERR
Definition: rodsErrorTable.h:92
rodsServerHost::localFlag
int localFlag
Definition: rodsConnect.h:68
fileSyncToArch
irods::error fileSyncToArch(rsComm_t *, irods::first_class_object_ptr, const std::string &)
Definition: fileDriver.cpp:583
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
SYS_UNRECOGNIZED_REMOTE_FLAG
@ SYS_UNRECOGNIZED_REMOTE_FLAG
Definition: rodsErrorTable.h:88
irods_file_object.hpp
irods_stacktrace.hpp
fileStageSyncInp_t::rescHier
char rescHier[(1024+64)]
Definition: fileStageToCache.h:17
irods_collection_object.hpp
REMOTE_HOST
#define REMOTE_HOST
Definition: rodsConnect.h:45
irods::collection_object_ptr
boost::shared_ptr< collection_object > collection_object_ptr
Definition: irods_collection_object.hpp:85
LOCAL_HOST
#define LOCAL_HOST
Definition: rodsConnect.h:44
irods_resource_backport.hpp
PASSMSG
#define PASSMSG(message_, prev_error_)
Definition: irods_error.hpp:119
rsFileSyncToArch
int rsFileSyncToArch(rsComm_t *rsComm, fileStageSyncInp_t *fileSyncToArchInp, fileSyncOut_t **sync_out)
Definition: rsFileSyncToArch.cpp:22
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
SYS_INVALID_INPUT_PARAM
@ SYS_INVALID_INPUT_PARAM
Definition: rodsErrorTable.h:195
fileSyncToArch.h
irods::error::code
long long code() const
Definition: irods_error.cpp:194
DATA_ID_KW
#define DATA_ID_KW
Definition: rodsKeyWdDef.h:48
irods::get_host_for_hier_string
error get_host_for_hier_string(const std::string &, int &, rodsServerHost_t *&)
Definition: irods_resource_backport.cpp:581
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
fileStageSyncInp_t::filename
char filename[(1024+64)]
Definition: fileStageToCache.h:14
getErrno
int getErrno(int errCode)
Definition: rcMisc.cpp:3261
fileRmdir
irods::error fileRmdir(rsComm_t *, irods::first_class_object_ptr)
Definition: fileDriver.cpp:332
SYS_INVALID_SERVER_HOST
@ SYS_INVALID_SERVER_HOST
Definition: rodsErrorTable.h:89
svrToSvrConnect
int svrToSvrConnect(rsComm_t *rsComm, rodsServerHost_t *rodsServerHost)
Definition: miscServerFunct.cpp:106
_rsFileSyncToArch
int _rsFileSyncToArch(rsComm_t *_comm, fileStageSyncInp_t *_sync_inp, fileSyncOut_t **_sync_out)
Definition: rsFileSyncToArch.cpp:110
irods::collection_object
Definition: irods_collection_object.hpp:14
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
physPath.hpp
irods::log
void log(const error &)
Definition: irods_log.cpp:13
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
rsFileSyncToArch.hpp
irods::error
Definition: irods_error.hpp:23
miscServerFunct.hpp
fileStageSyncInp_t::objPath
char objPath[(1024+64)]
Definition: fileStageToCache.h:16
remoteFileSyncToArch
int remoteFileSyncToArch(rsComm_t *rsComm, fileStageSyncInp_t *fileSyncToArchInp, fileSyncOut_t **sync_out, rodsServerHost_t *rodsServerHost)
Definition: rsFileSyncToArch.cpp:84
irods::file_object
Definition: irods_file_object.hpp:19
fileOpr.hpp
rodsServerHost
Definition: rodsConnect.h:62
irods::file_object_ptr
boost::shared_ptr< file_object > file_object_ptr
Definition: irods_file_object.hpp:145
rsFileSyncToArchByHost
int rsFileSyncToArchByHost(rsComm_t *rsComm, fileStageSyncInp_t *fileSyncToArchInp, fileSyncOut_t **sync_out, rodsServerHost_t *rodsServerHost)
Definition: rsFileSyncToArch.cpp:50
fileStageSyncInp_t::flags
int flags
Definition: fileStageToCache.h:11
fileStageSyncInp_t
Definition: fileStageToCache.h:9
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
dataObjOpr.hpp
fileSyncOut_t
Definition: fileStageToCache.h:22
mkDirForFilePath
int mkDirForFilePath(rsComm_t *rsComm, size_t startDirLen, const std::string &filePath, const std::string &hier, int mode)
Definition: fileOpr.cpp:120
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
fileStageSyncInp_t::cacheFilename
char cacheFilename[(1024+64)]
Definition: fileStageToCache.h:15
rcFileSyncToArch
int rcFileSyncToArch(rcComm_t *conn, fileStageSyncInp_t *fileSyncToArchInp, fileSyncOut_t **)
Definition: rcFileSyncToArch.cpp:24
irods_log.hpp