コード例 #1
0
ファイル: rodsPath.c プロジェクト: DICE-UNC/iRODS-FUSE-Mod
int
parseRodsPathStr (char *inPath, rodsEnv *myRodsEnv, char *outPath)
{
    int status;
    rodsPath_t rodsPath;

    rstrcpy (rodsPath.inPath, inPath, MAX_NAME_LEN);

    status = parseRodsPath (&rodsPath, myRodsEnv);

    if (status < 0) return status;

    rstrcpy (outPath, rodsPath.outPath, MAX_NAME_LEN);

    return (status);
}
コード例 #2
0
hFILE *hopen_irods(const char *filename, const char *mode)
{
    hFILE_irods *fp;
    rodsPath_t path;
    dataObjInp_t args;
    int ret;

    // Initialise the iRODS connection if this is the first use.
    if (irods.conn == NULL) { if (irods_init() < 0) return NULL; }

    if (strncmp(filename, "irods:", 6) == 0) filename += 6;
    else { errno = EINVAL; return NULL; }

    fp = (hFILE_irods *) hfile_init(sizeof (hFILE_irods), mode, 0);
    if (fp == NULL) return NULL;

    strncpy(path.inPath, filename, MAX_NAME_LEN-1);
    path.inPath[MAX_NAME_LEN-1] = '\0';

    ret = parseRodsPath(&path, &irods.env);
    if (ret < 0) goto error;

    memset(&args, 0, sizeof args);
    strcpy(args.objPath, path.outPath);
    args.openFlags = hfile_oflags(mode);
    if (args.openFlags & O_CREAT) {
        args.createMode = 0666;
        addKeyVal(&args.condInput, DEST_RESC_NAME_KW,irods.env.rodsDefResource);
    }

    ret = rcDataObjOpen(irods.conn, &args);
    if (ret < 0) goto error;
    fp->descriptor = ret;

    fp->base.backend = &irods_backend;
    return &fp->base;

error:
    hfile_destroy((hFILE *) fp);
    set_errno(ret);
    return NULL;
}
コード例 #3
0
ファイル: rodsPath.c プロジェクト: DICE-UNC/iRODS-FUSE-Mod
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);
}
コード例 #4
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;
}
コード例 #5
0
ファイル: icd.cpp プロジェクト: bpow/irods
int
main( int argc, char **argv ) {

    signal( SIGPIPE, SIG_IGN );

    int status, ix, i, fd, len;
    rodsArguments_t myRodsArgs;
    rodsEnv myEnv;
    char *envFile;
    char buffer[MAX_NAME_LEN];
    rodsPath_t rodsPath;
    rcComm_t *Conn;
    rErrMsg_t errMsg;

    status = parseCmdLineOpt( argc, argv, "vVh", 0, &myRodsArgs );
    if ( status ) {
        printf( "Use -h for help.\n" );
        exit( 1 );
    }
    if ( myRodsArgs.help == True ) {
        usage( argv[0] );
        exit( 0 );
    }
    ix = myRodsArgs.optind;

    status = getRodsEnv( &myEnv );
    envFile = getRodsEnvFileName();

    /* Just "icd", so cd to home, so just remove the session file */
    /* (can do this for now, since session has only the cwd). */
    if ( ix >= argc ) {
        status = unlink( envFile );
        if ( myRodsArgs.verbose == True ) {
            printf( "Deleting (if it exists) session envFile:%s\n", envFile );
            printf( "unlink status = %d\n", status );
        }
        exit( 0 );
    }

    memset( ( char* )&rodsPath, 0, sizeof( rodsPath ) );
    rstrcpy( rodsPath.inPath, argv[ix], MAX_NAME_LEN );
    parseRodsPath( &rodsPath, &myEnv );

    // =-=-=-=-=-=-=-
    // initialize pluggable api table
    irods::pack_entry_table& pk_tbl  = irods::get_pack_table();
    irods::api_entry_table& api_tbl = irods::get_client_api_table();
    init_api_table( api_tbl, pk_tbl );

    /* Connect and check that the path exists */
    Conn = rcConnect( myEnv.rodsHost, myEnv.rodsPort, myEnv.rodsUserName,
                      myEnv.rodsZone, 0, &errMsg );
    if ( Conn == NULL ) {
        exit( 2 );
    }

    status = clientLogin( Conn );
    if ( status != 0 ) {
        rcDisconnect( Conn );
        exit( 7 );
    }

    status = getRodsObjType( Conn, &rodsPath );
    printErrorStack( Conn->rError );
    rcDisconnect( Conn );

    if ( status < 0 ) {
        fprintf( stderr, "error %d getting type", status );
        exit( 4 );
    }

    if ( rodsPath.objType != COLL_OBJ_T || rodsPath.objState != EXIST_ST ) {
        printf( "No such directory (collection): %s\n", rodsPath.outPath );
        exit( 3 );
    }


    /* open the sessionfile and write or update it */
    if ( ( fd = open( envFile, O_CREAT | O_RDWR | O_TRUNC, 0644 ) ) < 0 ) {
        fprintf( stderr, "Unable to open envFile %s\n", envFile );
        exit( 5 );
    }

    snprintf( buffer, sizeof( buffer ), "{\n\"irods_cwd\": \"%s\"\n}\n", rodsPath.outPath );
    len = strlen( buffer );
    i = write( fd, buffer, len );
    close( fd );
    if ( i != len ) {
        fprintf( stderr, "Unable to write envFile %s\n", envFile );
        exit( 6 );
    }

    return 0;
}
コード例 #6
0
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;
}
コード例 #7
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