示例#1
0
int
main( int argc, char **argv ) {
    int status, ix;
    rodsArguments_t myRodsArgs;
    rodsEnv myEnv;
    char *envFile;

    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();
    status = unlink( envFile );
    if ( myRodsArgs.verbose == True ) {
        printf( "Deleting (if it exists) session envFile:%s\n", envFile );
        printf( "unlink status = %d\n", status );
    }

    if ( ix < argc ) {
        if ( strcmp( argv[ix], "full" ) == 0 ) {
            if ( myRodsArgs.verbose == True ) {
                obfRmPw( 0 );
            }
            else {
                obfRmPw( 1 );
            }
        }
        else {
            printf( "option %s is unrecognized\n", argv[ix] );
        }
    }

    exit( 0 );
}
示例#2
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;
}