Пример #1
0
int
rsMkCollR( rsComm_t *rsComm, const char *startColl, const char *destColl ) {
    int status;
    int startLen;
    int pathLen, tmpLen;
    char tmpPath[MAX_NAME_LEN];

    startLen = strlen( startColl );
    pathLen = strlen( destColl );

    rstrcpy( tmpPath, destColl, MAX_NAME_LEN );

    tmpLen = pathLen;

    while ( tmpLen > startLen ) {
        if ( isCollAllKinds( rsComm, tmpPath, NULL ) >= 0 ) {
            break;
        }

        /* Go backward */

        while ( tmpLen && tmpPath[tmpLen] != '/' ) {
            tmpLen --;
        }
        tmpPath[tmpLen] = '\0';
    }

    /* Now we go forward and make the required coll */
    while ( tmpLen < pathLen ) {
        collInp_t collCreateInp;

        /* Put back the '/' */
        tmpPath[tmpLen] = '/';
        memset( &collCreateInp, 0, sizeof( collCreateInp ) );
        rstrcpy( collCreateInp.collName, tmpPath, MAX_NAME_LEN );
        status = rsCollCreate( rsComm, &collCreateInp );

        if ( status == CAT_NAME_EXISTS_AS_DATAOBJ && isTrashPath( tmpPath ) ) {
            /* name conflict with a data object in the trash collection */
            dataObjCopyInp_t dataObjRenameInp;
            memset( &dataObjRenameInp, 0, sizeof( dataObjRenameInp ) );

            dataObjRenameInp.srcDataObjInp.oprType =
                dataObjRenameInp.destDataObjInp.oprType = RENAME_DATA_OBJ;
            rstrcpy( dataObjRenameInp.srcDataObjInp.objPath, tmpPath,
                     MAX_NAME_LEN );
            rstrcpy( dataObjRenameInp.destDataObjInp.objPath, tmpPath,
                     MAX_NAME_LEN );
            appendRandomToPath( dataObjRenameInp.destDataObjInp.objPath );

            status = rsDataObjRename( rsComm, &dataObjRenameInp );
            if ( status >= 0 ) {
                status = rsCollCreate( rsComm, &collCreateInp );
            }
        }
        /* something may be added by rsCollCreate */
        clearKeyVal( &collCreateInp.condInput );
        if ( status < 0 ) {
            // =-=-=-=-=-=-=-
            // JMC - backport 4819
            if ( status == CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME ) {
                rodsLog( LOG_DEBUG,
                         "rsMkCollR: rsCollCreate - coll %s already exist.stat = %d",
                         tmpPath, status );
                status = 0;
            }
            else {
                rodsLog( LOG_ERROR,
                         "rsMkCollR: rsCollCreate failed for %s, status =%d",
                         tmpPath, status );
            }
            // =-=-=-=-=-=-=-
            return status;
        }
        while ( tmpLen && tmpPath[tmpLen] != '\0' ) {
            tmpLen ++;
        }
    }
    return 0;
}
Пример #2
0
int
rsMvCollToTrash( rsComm_t *rsComm, collInp_t *rmCollInp ) {
    int status;
    char trashPath[MAX_NAME_LEN];
    dataObjCopyInp_t dataObjRenameInp;
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut = NULL;
    int continueInx;
    dataObjInfo_t dataObjInfo;

    /* check permission of files */

    memset( &genQueryInp, 0, sizeof( genQueryInp ) );
    status = rsQueryDataObjInCollReCur( rsComm, rmCollInp->collName,
                                        &genQueryInp, &genQueryOut, ACCESS_DELETE_OBJECT, 0 );

    memset( &dataObjInfo, 0, sizeof( dataObjInfo ) );
    while ( status >= 0 ) {
        sqlResult_t *subColl, *dataObj, *rescName;
        ruleExecInfo_t rei;

        /* check if allow to delete */

        if ( ( subColl = getSqlResultByInx( genQueryOut, COL_COLL_NAME ) )
                == NULL ) {
            rodsLog( LOG_ERROR,
                     "rsMvCollToTrash: getSqlResultByInx for COL_COLL_NAME failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }

        if ( ( dataObj = getSqlResultByInx( genQueryOut, COL_DATA_NAME ) )
                == NULL ) {
            rodsLog( LOG_ERROR,
                     "rsMvCollToTrash: getSqlResultByInx for COL_DATA_NAME failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }

        if ( ( rescName = getSqlResultByInx( genQueryOut, COL_D_RESC_NAME ) )
                == NULL ) {
            rodsLog( LOG_ERROR,
                     "rsMvCollToTrash: getSqlResultByInx for COL_D_RESC_NAME failed" );
            return UNMATCHED_KEY_OR_INDEX;
        }

        snprintf( dataObjInfo.objPath, MAX_NAME_LEN, "%s/%s",
                  subColl->value, dataObj->value );
        rstrcpy( dataObjInfo.rescName, rescName->value, NAME_LEN );

        initReiWithDataObjInp( &rei, rsComm, NULL );
        rei.doi = &dataObjInfo;

        status = applyRule( "acDataDeletePolicy", NULL, &rei, NO_SAVE_REI );

        if ( status < 0 && status != NO_MORE_RULES_ERR &&
                status != SYS_DELETE_DISALLOWED ) {
            rodsLog( LOG_NOTICE,
                     "rsMvCollToTrash: acDataDeletePolicy error for %s. status = %d",
                     dataObjInfo.objPath, status );
            return status;
        }

        if ( rei.status == SYS_DELETE_DISALLOWED ) {
            rodsLog( LOG_NOTICE,
                     "rsMvCollToTrash:disallowed for %s via DataDeletePolicy,status=%d",
                     dataObjInfo.objPath, rei.status );
            return rei.status;
        }

        continueInx = genQueryOut->continueInx;

        freeGenQueryOut( &genQueryOut );

        if ( continueInx > 0 ) {
            /* More to come */
            genQueryInp.continueInx = continueInx;
            status =  rsGenQuery( rsComm, &genQueryInp, &genQueryOut );
        }
        else {
            break;
        }
    }

    if ( status < 0 && status != CAT_NO_ROWS_FOUND ) {
        rodsLog( LOG_ERROR,
                 "rsMvCollToTrash: rsQueryDataObjInCollReCur error for %s, stat=%d",
                 rmCollInp->collName, status );
        return status;
    }

    status = rsMkTrashPath( rsComm, rmCollInp->collName, trashPath );

    if ( status < 0 ) {
        appendRandomToPath( trashPath );
        status = rsMkTrashPath( rsComm, rmCollInp->collName, trashPath );
        if ( status < 0 ) {
            return status;
        }
    }

    memset( &dataObjRenameInp, 0, sizeof( dataObjRenameInp ) );

    dataObjRenameInp.srcDataObjInp.oprType =
        dataObjRenameInp.destDataObjInp.oprType = RENAME_COLL;

    rstrcpy( dataObjRenameInp.destDataObjInp.objPath, trashPath, MAX_NAME_LEN );
    rstrcpy( dataObjRenameInp.srcDataObjInp.objPath, rmCollInp->collName,
             MAX_NAME_LEN );

    status = rsDataObjRename( rsComm, &dataObjRenameInp );

    while ( status == CAT_NAME_EXISTS_AS_COLLECTION ) {
        appendRandomToPath( dataObjRenameInp.destDataObjInp.objPath );
        status = rsDataObjRename( rsComm, &dataObjRenameInp );
    }

    if ( status < 0 ) {
        rodsLog( LOG_ERROR,
                 "mvCollToTrash: rcDataObjRename error for %s, status = %d",
                 dataObjRenameInp.destDataObjInp.objPath, status );
        return status;
    }

    return status;
}
Пример #3
0
/**
 * \fn msiDataObjAutoMove(msParam_t *inpParam1, msParam_t *inpParam2, msParam_t *inpParam3,
 *                      msParam_t *inpParam4, msParam_t *inpParam5, ruleExecInfo_t *rei)
 *
 * \brief This microservice is used to automatically move the newly created file into a destination collection.
 *
 * \module core
 *
 * \since 2.2
 *
 * \author  Bing Zhu
 * \date    2009-07
 *
 * \note This microservice changes the ownership for the dataset(s) being moved.
 *
 * \usage See clients/icommands/test/rules3.0/
 *
 * \param[in] inpParam1 - a STR_MS_T containing the object name with path. It usually comes from query as "$objPat
 *                          like /zone/../%" in the deployed microservice
 * \param[in] inpParam2 - a STR_MS_T containing the leading collection name to be truncated
 * \param[in] inpParam3 - a STR_MS_T containing the destination collection
 * \param[in] inpParam4 - a STR_MS_T containing the new owner
 * \param[in] inpParam5 - a STR_MS_T containing a flag for whether the checksum should be computed
                        \li true - default - will compute the checksum
                        \li false - will not compute the checksum
 * \param[in,out] rei - The RuleExecInfo structure that is automatically
 *    handled by the rule engine. The user does not include rei as a
 *    parameter in the rule invocation.
 *
 * \DolVarDependence none
 * \DolVarModified none
 * \iCatAttrDependence none
 * \iCatAttrModified none
 * \sideeffect none
 *
 * \return integer
 * \retval 0 upon success
 * \pre none
 * \post none
 * \sa none
**/
int msiDataObjAutoMove( msParam_t *inpParam1, msParam_t *inpParam2, msParam_t *inpParam3,
                        msParam_t *inpParam4, msParam_t *inpParam5, ruleExecInfo_t *rei ) {
    char *obj_path, *truct_path, *dest_coll, *new_owner;
    char *new_truct_path;
    char *new_obj_path;
    int  t;
    int  new_truct_path_len;
    rsComm_t *rsconn;
    char  mdest_coll[MAX_NAME_LEN];

    char  query_str[2048];
    genQueryInp_t genQueryInp;
    genQueryOut_t *genQueryOut = NULL;

    char new_obj_parent[MAX_NAME_LEN];
    char obj_name[MAX_NAME_LEN];

    collInp_t collCreateInp;
    dataObjCopyInp_t dataObjRenameInp;
    modAccessControlInp_t myModAccessCntlInp;

    dataObjInp_t myDataObjInp;
    char own_perm[20], null_perm[20];
    char user_name[NAME_LEN], zone_name[NAME_LEN];

    char *sTmpstr;
    int compute_checksum = 0;
    char *chksum_str = NULL;
    char tmpstr[1024];

    strcpy( own_perm, "own" );
    strcpy( null_perm, "null" );

    if ( rei == NULL || rei->rsComm == NULL ) {
        rodsLog( LOG_ERROR,
                 "msiDataObjAutoMove: input rei or rei->rsComm is NULL" );
        return ( SYS_INTERNAL_NULL_INPUT_ERR );
    }

    rsconn = rei->rsComm;

    if ( inpParam1 == NULL ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: input objpath (inpParam1) is NULL." );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }
    obj_path = ( char * )inpParam1->inOutStruct;
    if ( ( obj_path == NULL ) || ( strlen( obj_path ) == 0 ) ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: input objpath (inpParam1->inOutStruct) is NULL." );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }

    if ( inpParam2 == NULL ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: input truct_path (inpParam2) is NULL." );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }
    truct_path = ( char * )inpParam2->inOutStruct;
    if ( ( truct_path == NULL ) || ( strlen( truct_path ) == 0 ) ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: input truct_path (inpParam2->inOutStruct) is NULL." );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }

    if ( inpParam3 == NULL ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: input dest_coll (inpParam3) is NULL." );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }
    dest_coll = ( char * )inpParam3->inOutStruct;
    if ( ( dest_coll == NULL ) || ( strlen( dest_coll ) == 0 ) ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: input dest_coll (inpParam3->inOutStruct) is NULL." );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }

    if ( inpParam4 == NULL ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: input new_owner (inpParam4) is NULL." );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }
    new_owner = ( char * )inpParam4->inOutStruct;
    if ( new_owner != NULL ) {
        if ( strlen( new_owner ) == 0 ) {
            new_owner = NULL;
        }
        else if ( strcmp( new_owner, "null" ) == 0 ) {
            new_owner = NULL;
        }
    }
    if ( new_owner != NULL ) {
        user_name[0] = '\0';
        zone_name[0] = '\0';
        t = parseUserName( new_owner, user_name, zone_name );
        if ( t < 0 ) {
            rodsLog( LOG_ERROR, "msiDataObjAutoMove: parseUserName() failed. errStatus=%d.", t );
            return t;
        }
        if ( strlen( zone_name ) == 0 ) {
            strcpy( zone_name, rei->uoip->rodsZone );
        }
    }

    if ( inpParam5 == NULL ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: input compute_checksum (inpParam5) is NULL." );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }
    sTmpstr = ( char * )inpParam5->inOutStruct;
    compute_checksum = 1;   /* default to true */
    if ( ( sTmpstr != NULL ) && ( strlen( sTmpstr ) >= 0 ) ) {
        if ( strcmp( sTmpstr, "false" ) == 0 ) {
            compute_checksum = 0;
        }
    }

    if ( compute_checksum == 1 ) {
        chksum_str =  NULL;
        memset( &myDataObjInp, 0, sizeof( dataObjInp_t ) );
        strncpy( myDataObjInp.objPath, obj_path, MAX_NAME_LEN );
        addKeyVal( &myDataObjInp.condInput, VERIFY_CHKSUM_KW, "" );
        sprintf( tmpstr, "%d", 0 );
        addKeyVal( &myDataObjInp.condInput, REPL_NUM_KW, tmpstr );
        t = rsDataObjChksum( rsconn, &myDataObjInp, &chksum_str );
        if ( t < 0 ) {
            rodsLog( LOG_ERROR, "msiDataObjAutoMove: rsDataObjChksum() for '%s' failed. errStatus=%d.", obj_path, t );
            return t;
        }
    }

    if ( new_owner != NULL ) {
        /* add ownership */
        memset( &myModAccessCntlInp, 0, sizeof( modAccessControlInp_t ) );
        myModAccessCntlInp.recursiveFlag = False;
        myModAccessCntlInp.accessLevel = own_perm;
        myModAccessCntlInp.userName = user_name;
        myModAccessCntlInp.zone = zone_name;
        myModAccessCntlInp.path = obj_path;
        t = rsModAccessControl( rsconn, &myModAccessCntlInp );
        if ( t < 0 ) {
            rodsLog( LOG_ERROR, "msiDataObjAutoMove: rsModAccessControl() add new owner for '%s' failed. errStatus=%d.", obj_path, t );
            return t;
        }

    }

    t = strlen( truct_path );
    new_truct_path = ( char * )calloc( t + 2, sizeof( char ) );
    if ( truct_path[t - 1] != '/' ) {
        strcpy( new_truct_path, truct_path );
        new_truct_path_len = t;
    }
    else {
        strcpy( new_truct_path, truct_path );
        new_truct_path[t] = '/';
        new_truct_path[t + 1] = '\0';
        new_truct_path_len = t + 1;
    }
    if ( strncmp( new_truct_path, obj_path, t ) != 0 ) {
        /* when the object is not match, we don't move */
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: The object path, %s, is not in the specified collection, %s.", obj_path, new_truct_path );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }

    t = strlen( dest_coll );
    new_obj_path = ( char * )calloc( t + strlen( obj_path ), sizeof( char ) );
    strcpy( mdest_coll, dest_coll );
    if ( dest_coll[t - 1] == '/' ) {
        mdest_coll[t - 1] = '\0';
    }
    sprintf( new_obj_path, "%s/%s", mdest_coll, &( obj_path[new_truct_path_len + 1] ) );
    sprintf( query_str, "SELECT COLL_NAME WHERE COLL_NAME like '%s%%'", mdest_coll );

    /* check if the dest_coll exists */
    memset( &genQueryInp, 0, sizeof( genQueryInp_t ) );
    t = fillGenQueryInpFromStrCond( query_str, &genQueryInp );
    if ( t < 0 ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: fillGenQueryInpFromStrCond() failed. errStatus=%d", t );
        free( new_obj_path ); // JMC cppcheck - leak
        free( new_truct_path ); // JMC cppcheck - leak
        return t;
    }
    genQueryInp.maxRows = MAX_SQL_ROWS;
    genQueryInp.continueInx = 0;
    t = rsGenQuery( rsconn, &genQueryInp, &genQueryOut );
    if ( t < 0 ) {
        if ( t == CAT_NO_ROWS_FOUND ) {
            rodsLog( LOG_ERROR, "msiDataObjAutoMove: The destination collection '%s' does not exist.", dest_coll );
        }
        else {
            rodsLog( LOG_ERROR, "msiDataObjAutoMove: rsGenQuery() failed. errStatus=%d", t );
        }
        free( new_obj_path ); // JMC cppcheck - leak
        free( new_truct_path ); // JMC cppcheck - leak
        return t;
    }

    /* separate new_obj_path with path and name */
    t = splitPathByKey( new_obj_path, new_obj_parent, obj_name, '/' );
    if ( t < 0 ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: splitPathByKey() failed for splitting '%s'. errStatus=%d.", new_obj_path, t );
        free( new_obj_path ); // JMC cppcheck - leak
        free( new_truct_path ); // JMC cppcheck - leak
        return t;
    }

    /* fprintf(stderr,"msiDataObjAutoMove: newpar=%s, obj_name=%s, from=%s\n", new_obj_parent, obj_name, obj_path); */

    /* create the dires in new_obj_path 'imkidr -p'*/
    if ( strlen( new_obj_parent ) > strlen( mdest_coll ) ) {
        memset( &collCreateInp, 0, sizeof( collCreateInp ) );
        rstrcpy( collCreateInp.collName, new_obj_parent, MAX_NAME_LEN );
        addKeyVal( &collCreateInp.condInput, RECURSIVE_OPR__KW, "" );   /* always have '-p' option. */
        t = rsCollCreate( rsconn, &collCreateInp );
        if ( t < 0 ) {
            rodsLog( LOG_ERROR, "msiDataObjAutoMove: rsCollCreate() failed for %s. errStatus=%d.", new_obj_parent, t );
            free( new_obj_path ); // JMC cppcheck - leak
            free( new_truct_path ); // JMC cppcheck - leak
            return t;
        }
    }

    fprintf( stderr, "new_obj_path=%s, obj_path=%s\n", new_obj_path, obj_path );
    /* renamed the obj_path to new_obj_path */
    memset( &dataObjRenameInp, 0, sizeof( dataObjCopyInp_t ) );
    rstrcpy( dataObjRenameInp.destDataObjInp.objPath, new_obj_path, MAX_NAME_LEN );
    rstrcpy( dataObjRenameInp.srcDataObjInp.objPath, obj_path, MAX_NAME_LEN );
    t = rsDataObjRename( rsconn, &dataObjRenameInp );
    if ( t < 0 ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: rsDataObjRename() failed. errStatus=%d.", t );
        free( new_obj_path ); // JMC cppcheck - leak
        free( new_truct_path ); // JMC cppcheck - leak
        return t;
    }

    memset( &myModAccessCntlInp, 0, sizeof( modAccessControlInp_t ) );
    myModAccessCntlInp.recursiveFlag = False;
    myModAccessCntlInp.accessLevel = null_perm;
    myModAccessCntlInp.userName = rei->uoic->userName;
    myModAccessCntlInp.zone = zone_name;
    myModAccessCntlInp.path = new_obj_path;
    t = rsModAccessControl( rsconn, &myModAccessCntlInp );
    if ( t < 0 ) {
        rodsLog( LOG_ERROR, "msiDataObjAutoMove: rsModAccessControl() remove user for '%s' failed. errStatus=%d.", obj_path, t );
    }

    free( new_truct_path ); // JMC cppcheck - leak
    return 0;
}
Пример #4
0
int
rsMvDataObjToTrash (rsComm_t *rsComm, dataObjInp_t *dataObjInp,
dataObjInfo_t **dataObjInfoHead)
{
    int status;
    char trashPath[MAX_NAME_LEN];
    dataObjCopyInp_t dataObjRenameInp;

    if (strstr ((*dataObjInfoHead)->dataType, BUNDLE_STR) != NULL) {
	return SYS_CANT_MV_BUNDLE_DATA_TO_TRASH;
    }

    if (getValByKey (&dataObjInp->condInput, DATA_ACCESS_KW) == NULL) {
        addKeyVal (&dataObjInp->condInput, DATA_ACCESS_KW,
          ACCESS_DELETE_OBJECT);
    }

    status = getDataObjInfo (rsComm, dataObjInp, dataObjInfoHead,
      ACCESS_DELETE_OBJECT, 0);

    if (status < 0) {
        rodsLog (LOG_NOTICE,
          "rsMvDataObjToTrash: getDataObjInfo error for %s. status = %d",
          dataObjInp->objPath, status);
        return (status);
    }

    status = chkPreProcDeleteRule (rsComm, dataObjInp, *dataObjInfoHead);
    if (status < 0) return status;

#if 0   /* done in chkPreProcDeleteRule */

    initReiWithDataObjInp (&rei, rsComm, dataObjInp);
    rei.doi = *dataObjInfoHead;

    status = applyRule ("acDataDeletePolicy", NULL, &rei, NO_SAVE_REI);

    if (status < 0 && status != NO_MORE_RULES_ERR &&
      status != SYS_DELETE_DISALLOWED) {
        rodsLog (LOG_NOTICE,
          "rsMvDataObjToTrash: acDataDeletePolicy error for %s. status = %d",
          dataObjInp->objPath, status);
        return (status);
    }

    if (rei.status == SYS_DELETE_DISALLOWED) {
        rodsLog (LOG_NOTICE,
        "rsMvDataObjToTrash:disallowed for %s via DataDeletePolicy,status=%d",
          dataObjInp->objPath, rei.status);
        return (rei.status);
    }
#endif

    status = rsMkTrashPath (rsComm, dataObjInp->objPath, trashPath);

    if (status < 0) {
        return (status);
    }

    memset (&dataObjRenameInp, 0, sizeof (dataObjRenameInp));

    dataObjRenameInp.srcDataObjInp.oprType =
      dataObjRenameInp.destDataObjInp.oprType = RENAME_DATA_OBJ;

    rstrcpy (dataObjRenameInp.destDataObjInp.objPath, trashPath, MAX_NAME_LEN);
    rstrcpy (dataObjRenameInp.srcDataObjInp.objPath, dataObjInp->objPath,
      MAX_NAME_LEN);

    status = rsDataObjRename (rsComm, &dataObjRenameInp);

    while (status == CAT_NAME_EXISTS_AS_DATAOBJ || 
      status == CAT_NAME_EXISTS_AS_COLLECTION || 
      status == SYS_PHY_PATH_INUSE || 
      getErrno (status) == EISDIR) {
        appendRandomToPath (dataObjRenameInp.destDataObjInp.objPath);
	status = rsDataObjRename (rsComm, &dataObjRenameInp);
#if 0
        if (status1 < 0) {
            rodsLog (LOG_ERROR,
              "rsMvDataObjToTrash: rsDataObjRename error for %s",
              dataObjRenameInp.destDataObjInp.objPath);
	} else {
	    status = 0;
	}
#endif
    }
    if (status < 0) {
        rodsLog (LOG_ERROR,
          "rsMvDataObjToTrash: rcDataObjRename error for %s, status = %d",
          dataObjRenameInp.destDataObjInp.objPath, status);
        return (status);
    }
    return (status);
}
Пример #5
0
int
rsMvDataObjToTrash( rsComm_t *rsComm, dataObjInp_t *dataObjInp,
                    dataObjInfo_t **dataObjInfoHead ) {
    int status;
    char trashPath[MAX_NAME_LEN];
    dataObjCopyInp_t dataObjRenameInp;

    if ( strstr( ( *dataObjInfoHead )->dataType, BUNDLE_STR ) != NULL ) { // JMC - backport 4658
        return SYS_CANT_MV_BUNDLE_DATA_TO_TRASH;
    }

    if ( getValByKey( &dataObjInp->condInput, DATA_ACCESS_KW ) == NULL ) {
        addKeyVal( &dataObjInp->condInput, DATA_ACCESS_KW,
                   ACCESS_DELETE_OBJECT );
    }

    status = getDataObjInfo( rsComm, dataObjInp, dataObjInfoHead,
                             ACCESS_DELETE_OBJECT, 0 );
    if ( status < 0 ) {
        rodsLog( LOG_NOTICE,
                 "rsMvDataObjToTrash: getDataObjInfo error for %s. status = %d",
                 dataObjInp->objPath, status );
        return status;
    }

    status = chkPreProcDeleteRule( rsComm, dataObjInp, *dataObjInfoHead );
    if ( status < 0 ) {
        return status;
    }


    status = rsMkTrashPath( rsComm, dataObjInp->objPath, trashPath );

    if ( status < 0 ) {
        return status;
    }

    memset( &dataObjRenameInp, 0, sizeof( dataObjRenameInp ) );

    dataObjRenameInp.srcDataObjInp.oprType =
        dataObjRenameInp.destDataObjInp.oprType = RENAME_DATA_OBJ;

    rstrcpy( dataObjRenameInp.destDataObjInp.objPath, trashPath, MAX_NAME_LEN );
    rstrcpy( dataObjRenameInp.srcDataObjInp.objPath, dataObjInp->objPath,
             MAX_NAME_LEN );

    status = rsDataObjRename( rsComm, &dataObjRenameInp );

    while ( status == CAT_NAME_EXISTS_AS_DATAOBJ ||
            status == CAT_NAME_EXISTS_AS_COLLECTION ||
            status == SYS_PHY_PATH_INUSE ||
            getErrno( status ) == EISDIR ) {
        appendRandomToPath( dataObjRenameInp.destDataObjInp.objPath );
        status = rsDataObjRename( rsComm, &dataObjRenameInp );
    }
    if ( status < 0 ) {
        rodsLog( LOG_ERROR,
                 "rsMvDataObjToTrash: rcDataObjRename error for %s, status = %d",
                 dataObjRenameInp.destDataObjInp.objPath, status );
        return status;
    }
    return status;
}