int parseCmdLinePath (int argc, char **argv, int optInd, rodsEnv *myRodsEnv, int srcFileType, int destFileType, int flag, rodsPathInp_t *rodsPathInp) { int nInput; int i, status; int numSrc; nInput = argc - optInd; if (rodsPathInp == NULL) { rodsLog (LOG_ERROR, "parseCmdLinePath: NULL rodsPathInp input"); return (USER__NULL_INPUT_ERR); } memset (rodsPathInp, 0, sizeof (rodsPathInp_t)); if (nInput <= 0) { if ((flag & ALLOW_NO_SRC_FLAG) == 0) { return (USER__NULL_INPUT_ERR); } else { numSrc = 1; } } else if (nInput == 1) { numSrc = 1; } else if (destFileType == NO_INPUT_T) { /* no dest input */ numSrc = nInput; } else { numSrc = nInput - 1; } for (i = 0; i < numSrc; i++) { if (nInput <= 0) { /* just add cwd */ addSrcInPath (rodsPathInp, "."); } else { addSrcInPath (rodsPathInp, argv[optInd + i]); } if (srcFileType <= COLL_OBJ_T) { status = parseRodsPath (&rodsPathInp->srcPath[i], myRodsEnv); } else { status = parseLocalPath (&rodsPathInp->srcPath[i]); } if (status < 0) { return (status); } } if (destFileType != NO_INPUT_T) { rodsPathInp->destPath = (rodsPath_t*)malloc (sizeof (rodsPath_t)); memset (rodsPathInp->destPath, 0, sizeof (rodsPath_t)); if (nInput > 1) { rstrcpy (rodsPathInp->destPath->inPath, argv[argc - 1], MAX_NAME_LEN); } else { rstrcpy (rodsPathInp->destPath->inPath, ".", MAX_NAME_LEN); } if (destFileType <= COLL_OBJ_T) { status = parseRodsPath (rodsPathInp->destPath, myRodsEnv); } else { status = parseLocalPath (rodsPathInp->destPath); } } return (status); }
static int _upload (const char *iRODSPath) { int status; rcComm_t *conn; rodsPathInp_t rodsPathInp; rErrMsg_t errMsg; char bufferPath[MAX_NAME_LEN]; char destiRODSDir[MAX_NAME_LEN]; status = getParentDir(iRODSPath, destiRODSDir); if(status < 0) { rodsLog (LOG_DEBUG, "_upload: failed to get parent dir - %s", iRODSPath); return status; } status = _getBufferPath(iRODSPath, bufferPath); if(status < 0) { rodsLog (LOG_DEBUG, "_upload: failed to get Buffered lazy upload file path - %s", iRODSPath); return status; } // set src path memset( &rodsPathInp, 0, sizeof( rodsPathInp_t ) ); addSrcInPath( &rodsPathInp, bufferPath ); status = parseLocalPath (&rodsPathInp.srcPath[0]); if(status < 0) { rodsLog (LOG_DEBUG, "_upload: parseLocalPath error : %d", status); return status; } // set dest path rodsPathInp.destPath = ( rodsPath_t* )malloc( sizeof( rodsPath_t ) ); memset( rodsPathInp.destPath, 0, sizeof( rodsPath_t ) ); rstrcpy( rodsPathInp.destPath->inPath, destiRODSDir, MAX_NAME_LEN ); status = parseRodsPath (rodsPathInp.destPath, LazyUploadRodsEnv); if(status < 0) { rodsLog (LOG_DEBUG, "_upload: parseRodsPath error : %d", status); return status; } // Connect conn = rcConnect (LazyUploadRodsEnv->rodsHost, LazyUploadRodsEnv->rodsPort, LazyUploadRodsEnv->rodsUserName, LazyUploadRodsEnv->rodsZone, RECONN_TIMEOUT, &errMsg); if (conn == NULL) { rodsLog (LOG_DEBUG, "_upload: error occurred while connecting to irods"); return -EPIPE; } // Login if (strcmp (LazyUploadRodsEnv->rodsUserName, PUBLIC_USER_NAME) != 0) { status = clientLogin(conn); if (status != 0) { rodsLog (LOG_DEBUG, "_upload: ClientLogin error : %d", status); rcDisconnect(conn); return status; } } // upload Buffered file rodsLog (LOG_DEBUG, "_upload: upload %s", bufferPath); bool prev = LazyUploadRodsArgs->force; LazyUploadRodsArgs->force = True; status = putUtil (&conn, LazyUploadRodsEnv, LazyUploadRodsArgs, &rodsPathInp); LazyUploadRodsArgs->force = prev; rodsLog (LOG_DEBUG, "_upload: complete uploading %s -> %s", bufferPath, destiRODSDir); // Disconnect rcDisconnect(conn); if(status < 0) { rodsLog (LOG_DEBUG, "_upload: putUtil error : %d", status); return status; } return 0; }
static int _download(const char *path, struct stat *stbufIn) { int status; rcComm_t *conn; rodsPathInp_t rodsPathInp; rErrMsg_t errMsg; char preloadCachePath[MAX_NAME_LEN]; char preloadCacheWorkPath[MAX_NAME_LEN]; // set path for getUtil status = _getCachePath(path, preloadCachePath); if(status < 0) { rodsLogError(LOG_ERROR, status, "_download: _getCachePath error."); rodsLog (LOG_ERROR, "_download: failed to get cache path - %s", path); return status; } status = _getCacheWorkPath(path, preloadCacheWorkPath); if(status < 0) { rodsLogError(LOG_ERROR, status, "_download: _getCacheWorkPath error."); rodsLog (LOG_ERROR, "_download: failed to get cache work path - %s", path); return status; } rodsLog (LOG_DEBUG, "_download: download %s to %s", path, preloadCachePath); // set src path memset( &rodsPathInp, 0, sizeof( rodsPathInp_t ) ); addSrcInPath( &rodsPathInp, (char*)path ); status = parseRodsPath (&rodsPathInp.srcPath[0], PreloadRodsEnv); if(status < 0) { rodsLogError(LOG_ERROR, status, "_download: parseRodsPath error."); return status; } // set dest path rodsPathInp.destPath = ( rodsPath_t* )malloc( sizeof( rodsPath_t ) ); memset( rodsPathInp.destPath, 0, sizeof( rodsPath_t ) ); rstrcpy( rodsPathInp.destPath->inPath, preloadCacheWorkPath, MAX_NAME_LEN ); status = parseLocalPath (rodsPathInp.destPath); if(status < 0) { rodsLogError(LOG_ERROR, status, "_download: parseLocalPath error."); return status; } // Connect conn = rcConnect (PreloadRodsEnv->rodsHost, PreloadRodsEnv->rodsPort, PreloadRodsEnv->rodsUserName, PreloadRodsEnv->rodsZone, RECONN_TIMEOUT, &errMsg); if (conn == NULL) { rodsLog (LOG_ERROR, "_download: error occurred while connecting to irods"); return -EPIPE; } // Login if (strcmp (PreloadRodsEnv->rodsUserName, PUBLIC_USER_NAME) != 0) { status = clientLogin(conn); if (status != 0) { rodsLogError(LOG_ERROR, status, "_download: ClientLogin error."); rcDisconnect(conn); return status; } } // make dir prepareDir(preloadCachePath); // Preload rodsLog (LOG_DEBUG, "_download: download %s", path); status = getUtil (&conn, PreloadRodsEnv, PreloadRodsArgs, &rodsPathInp); rodsLog (LOG_DEBUG, "_download: complete downloading %s", path); // Disconnect rcDisconnect(conn); if(status < 0) { rodsLogError(LOG_ERROR, status, "_download: getUtil error."); return status; } // be careful when using Lock LOCK(PreloadLock); status = _completeDownload(preloadCacheWorkPath, preloadCachePath, stbufIn); if(status < 0) { rodsLogError(LOG_ERROR, status, "_download: _completeDownload error."); UNLOCK(PreloadLock); return status; } UNLOCK(PreloadLock); return 0; }
static int build_irods_path_structure( const path_list_t& _path_list, rodsEnv* _rods_env, int _src_type, int _dst_type, int _flag, rodsPathInp_t* _rods_paths ) { int numSrc = 0; if ( _rods_paths == NULL ) { return USER__NULL_INPUT_ERR; } memset( _rods_paths, 0, sizeof( rodsPathInp_t ) ); if ( _path_list.size() <= 0 ) { if ( ( _flag & ALLOW_NO_SRC_FLAG ) == 0 ) { return USER__NULL_INPUT_ERR; } else { numSrc = 1; } } else if ( _path_list.size() == 1 ) { numSrc = 1; } else if ( _dst_type == NO_INPUT_T ) { /* no dest input */ numSrc = _path_list.size(); } else { numSrc = _path_list.size() - 1; } int status = 0; for ( int i = 0; i < numSrc; i++ ) { if ( _path_list.size() <= 0 ) { /* just add cwd */ addSrcInPath( _rods_paths, "." ); } else { addSrcInPath( _rods_paths, _path_list[ i ].c_str() ); } if ( _src_type <= COLL_OBJ_T ) { status = parseRodsPath( &_rods_paths->srcPath[i], _rods_env ); } else { status = parseLocalPath( &_rods_paths->srcPath[i] ); } if ( status < 0 ) { return status; } } if ( _dst_type != NO_INPUT_T ) { _rods_paths->destPath = ( rodsPath_t* )malloc( sizeof( rodsPath_t ) ); memset( _rods_paths->destPath, 0, sizeof( rodsPath_t ) ); if ( _path_list.size() > 1 ) { rstrcpy( _rods_paths->destPath->inPath, _path_list.rbegin()->c_str(), MAX_NAME_LEN ); } else { rstrcpy( _rods_paths->destPath->inPath, ".", MAX_NAME_LEN ); } if ( _dst_type <= COLL_OBJ_T ) { status = parseRodsPath( _rods_paths->destPath, _rods_env ); } else { status = parseLocalPath( _rods_paths->destPath ); } } return status; } // build_irods_path_structure