Esempio n. 1
0
int
dataObjCreateAndReg( rsComm_t *rsComm, int l1descInx ) {

    dataObjInfo_t *myDataObjInfo = L1desc[l1descInx].dataObjInfo;
    int status;

    status = dataCreate( rsComm, l1descInx );

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

    /* only register new copy */
    status = svrRegDataObj( rsComm, myDataObjInfo );
    if ( status < 0 ) {
        l3Unlink( rsComm, myDataObjInfo );
        rodsLog( LOG_NOTICE,
                 "dataObjCreateAndReg: rsRegDataObj for %s failed, status = %d",
                 myDataObjInfo->objPath, status );
        return ( status );
    }
    else {
        myDataObjInfo->replNum = status;
        return ( 0 );
    }
}
Esempio n. 2
0
int
_l3DataPutSingleBuf( rsComm_t *rsComm, int l1descInx, dataObjInp_t *dataObjInp,
                     bytesBuf_t *dataObjInpBBuf ) {
    int status = 0;
    int bytesWritten;
    dataObjInfo_t *myDataObjInfo;

    myDataObjInfo = L1desc[l1descInx].dataObjInfo;

    bytesWritten = l3FilePutSingleBuf( rsComm, l1descInx, dataObjInpBBuf );
    if ( bytesWritten >= 0 ) {
        if ( L1desc[l1descInx].replStatus == NEWLY_CREATED_COPY &&
                myDataObjInfo->specColl == NULL &&
                L1desc[l1descInx].remoteZoneHost == NULL ) {
            /* the check for remoteZoneHost host is not needed because
             * the put would have done in the remote zone. But it make
             * the code easier to read (similar ro copy).
             */
            status = svrRegDataObj( rsComm, myDataObjInfo );
            if ( status < 0 ) {
                rodsLog( LOG_NOTICE,
                         "l3DataPutSingleBuf: rsRegDataObj for %s failed, status = %d",
                         myDataObjInfo->objPath, status );
                if ( status != CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME ) {
                    l3Unlink( rsComm, myDataObjInfo );
                }
                return ( status );
            }
            else {
                myDataObjInfo->replNum = status;
            }
        }
        /* myDataObjInfo->dataSize = bytesWritten; update size problem */
        if ( bytesWritten == 0 && myDataObjInfo->dataSize > 0 ) {
            /* overwrite with 0 len file */
            L1desc[l1descInx].bytesWritten = 1;
        }
        else {
            L1desc[l1descInx].bytesWritten = bytesWritten;
        }
    }
    L1desc[l1descInx].dataSize = dataObjInp->dataSize;

    return ( bytesWritten );
}
Esempio n. 3
0
int
_l3DataPutSingleBuf( rsComm_t *rsComm, int l1descInx, dataObjInp_t *dataObjInp,
                     bytesBuf_t *dataObjInpBBuf ) {
    int status = 0;
    dataObjInfo_t *myDataObjInfo = L1desc[l1descInx].dataObjInfo;

    int bytesWritten = l3FilePutSingleBuf( rsComm, l1descInx, dataObjInpBBuf );
    if ( bytesWritten >= 0 ) {
        if ( L1desc[l1descInx].replStatus == NEWLY_CREATED_COPY &&
                myDataObjInfo->specColl == NULL &&
                L1desc[l1descInx].remoteZoneHost == NULL ) {

            /* the check for remoteZoneHost host is not needed because
             * the put would have done in the remote zone. But it make
             * the code easier to read (similar ro copy).
             */
            status = svrRegDataObj( rsComm, myDataObjInfo );
            if ( status < 0 ) {
                rodsLog( LOG_NOTICE,
                         "l3DataPutSingleBuf: rsRegDataObj for %s failed, status = %d",
                         myDataObjInfo->objPath, status );
                if ( status != CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME ) {
                    l3Unlink( rsComm, myDataObjInfo );
                }
                return status;
            }
            else {
                myDataObjInfo->replNum = status;
            }

        }
        /* myDataObjInfo->dataSize = bytesWritten; update size problem */
        if ( bytesWritten == 0 && myDataObjInfo->dataSize > 0 ) {
            /* overwrite with 0 len file */
            L1desc[l1descInx].bytesWritten = 1;
        }
        else {
            L1desc[l1descInx].bytesWritten = bytesWritten;
        }

        // special case of zero length files, trigger the fileModified
        // operation for execution of coordinating resource logic
        if ( 0 == dataObjInp->dataSize ) {
            irods::file_object_ptr file_obj(
                new irods::file_object(
                    rsComm,
                    myDataObjInfo ) );

            char* pdmo_kw = getValByKey( &myDataObjInfo->condInput, IN_PDMO_KW );
            if ( pdmo_kw != NULL ) {
                file_obj->in_pdmo( pdmo_kw );
            }
            irods::error ret = fileModified( rsComm, file_obj );
            if ( !ret.ok() ) {
                std::stringstream msg;
                msg << "fileModified failed for [";
                msg << myDataObjInfo->objPath;
                msg << "]";
                ret = PASSMSG( msg.str(), ret );
                irods::log( ret );
                status = ret.code();
            }
        }
    }

    L1desc[l1descInx].dataSize = dataObjInp->dataSize;

    return bytesWritten;
}
Esempio n. 4
0
int
createPhyBundleDataObj( rsComm_t *rsComm, char *collection,
                        const std::string& _resc_name, const char* rescHier, dataObjInp_t *dataObjInp, // should be able to only use rescHier
                        char* dataType ) { // JMC - backport 4658
    int l1descInx;
    int status;

    /* XXXXXX We do bundle only with UNIX_FILE_TYPE for now */
    if ( _resc_name.empty() ) {
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }

    std::string type;
    irods::error err = irods::get_resource_property< std::string >(
                           _resc_name,
                           irods::RESOURCE_TYPE,
                           type );
    if ( !err.ok() ) {
        irods::log( PASS( err ) );
    }

    do {
        int loopCnt = 0;
        bzero( dataObjInp, sizeof( dataObjInp_t ) );
        while ( 1 ) {
            status = rsMkBundlePath( rsComm, collection, dataObjInp->objPath,
                                     getRandomInt() );
            if ( status < 0 ) {
                rodsLog( LOG_ERROR,
                         "createPhyBundleFile: getPhyBundlePath err for %s.stat = %d",
                         collection, status );
                return status;
            }
            /* check if BundlePath already existed */
            if ( isData( rsComm, dataObjInp->objPath, NULL ) >= 0 ) {
                if ( loopCnt >= 100 ) {
                    break;
                }
                else {
                    loopCnt++;
                    continue;
                }
            }
            else {
                break;
            }
        }

        if ( dataType != NULL && strstr( dataType, BUNDLE_STR ) != NULL ) { // JMC - backport 4658
            addKeyVal( &dataObjInp->condInput, DATA_TYPE_KW, dataType );
        }
        else {
            /* assume it is TAR_BUNDLE_DT_STR */
            addKeyVal( &dataObjInp->condInput, DATA_TYPE_KW, TAR_BUNDLE_DT_STR );
        }

        if ( rescHier != NULL ) {
            addKeyVal( &dataObjInp->condInput, RESC_HIER_STR_KW, rescHier );
        }

        if ( dataType != NULL && strstr( dataType, ZIP_DT_STR ) != NULL ) { // JMC - backport 4664
            /* zipFile type. must end with .zip */
            int len = strlen( dataObjInp->objPath );
            if ( strcmp( &dataObjInp->objPath[len - 4], ".zip" ) != 0 ) {
                strcat( dataObjInp->objPath, ".zip" );
            }
        }

        l1descInx = _rsDataObjCreateWithResc( rsComm, dataObjInp, _resc_name );

        clearKeyVal( &dataObjInp->condInput );
    }
    while ( l1descInx == OVERWRITE_WITHOUT_FORCE_FLAG );

    if ( l1descInx >= 0 ) {
        l3Close( rsComm, l1descInx );
        L1desc[l1descInx].l3descInx = 0;
        if ( dataType != NULL && strstr( dataType, ZIP_DT_STR ) != NULL ) { // JMC - backport 4664
            l3Unlink( rsComm, L1desc[l1descInx].dataObjInfo );
        }
    }

    return l1descInx;
}
int
_rsStructFileBundle (rsComm_t *rsComm,
structFileExtAndRegInp_t *structFileBundleInp)
{
    int status;
    dataObjInp_t dataObjInp;
    openedDataObjInp_t dataObjCloseInp;
    collInp_t collInp;
    collEnt_t *collEnt = NULL;
    int handleInx;
    int collLen;
    char phyBunDir[MAX_NAME_LEN];
    char tmpPath[MAX_NAME_LEN];
    chkObjPermAndStat_t chkObjPermAndStatInp;
    int l1descInx;
    int savedStatus = 0;
    char *dataType;

    /* open the structured file */
    memset (&dataObjInp, 0, sizeof (dataObjInp));
    dataType = getValByKey (&structFileBundleInp->condInput, DATA_TYPE_KW);
    if (dataType != NULL && strstr (dataType, ZIP_DT_STR) != NULL) {
	/* zipFile type. must end with .zip */
	int len = strlen (structFileBundleInp->objPath);
	if (strcmp (&structFileBundleInp->objPath[len - 4], ".zip") != 0) {
	    strcat (structFileBundleInp->objPath, ".zip");
        }
    }
    rstrcpy (dataObjInp.objPath, structFileBundleInp->objPath, 
      MAX_NAME_LEN);
 
    /* replicate the condInput. may have resource input */
    replKeyVal (&structFileBundleInp->condInput, &dataObjInp.condInput);

    dataObjInp.openFlags = O_WRONLY;  

    if ((structFileBundleInp->oprType & ADD_TO_TAR_OPR) != 0) {
        l1descInx = rsDataObjOpen (rsComm, &dataObjInp);
    } else {
        l1descInx = rsDataObjCreate (rsComm, &dataObjInp);
    }
    if (l1descInx < 0) {
        rodsLog (LOG_ERROR,
          "rsStructFileBundle: rsDataObjCreate of %s error. status = %d",
          dataObjInp.objPath, l1descInx);
        return (l1descInx);
    }
    clearKeyVal (&dataObjInp.condInput);
    l3Close (rsComm, l1descInx);
    L1desc[l1descInx].l3descInx = 0;
    /* zip does not like a zero length file as target */
    if ((structFileBundleInp->oprType & ADD_TO_TAR_OPR) == 0)
        l3Unlink (rsComm, L1desc[l1descInx].dataObjInfo);

    memset (&chkObjPermAndStatInp, 0, sizeof (chkObjPermAndStatInp));
    rstrcpy (chkObjPermAndStatInp.objPath, 
      structFileBundleInp->collection, MAX_NAME_LEN); 
    chkObjPermAndStatInp.flags = CHK_COLL_FOR_BUNDLE_OPR;
    addKeyVal (&chkObjPermAndStatInp.condInput, RESC_NAME_KW,
      L1desc[l1descInx].dataObjInfo->rescName);

    status = rsChkObjPermAndStat (rsComm, &chkObjPermAndStatInp);

    clearKeyVal (&chkObjPermAndStatInp.condInput);

    if (status < 0) {
        rodsLog (LOG_ERROR,
          "rsStructFileBundle: rsChkObjPermAndStat of %s error. stat = %d",
          chkObjPermAndStatInp.objPath, status);
        dataObjCloseInp.l1descInx = l1descInx;
        rsDataObjClose (rsComm, &dataObjCloseInp);
        return (status);
    }

    createPhyBundleDir (rsComm, L1desc[l1descInx].dataObjInfo->filePath,
      phyBunDir);

    bzero (&collInp, sizeof (collInp));
    rstrcpy (collInp.collName, structFileBundleInp->collection, MAX_NAME_LEN);
    collInp.flags = RECUR_QUERY_FG | VERY_LONG_METADATA_FG |
      NO_TRIM_REPL_FG | INCLUDE_CONDINPUT_IN_QUERY;
    addKeyVal (&collInp.condInput, RESC_NAME_KW, 
      L1desc[l1descInx].dataObjInfo->rescName);
    handleInx = rsOpenCollection (rsComm, &collInp);
    if (handleInx < 0) {
        rodsLog (LOG_ERROR,
          "rsStructFileBundle: rsOpenCollection of %s error. status = %d",
          collInp.collName, handleInx);
        rmdir (phyBunDir);
        return (handleInx);
    }
    if ((structFileBundleInp->oprType & PRESERVE_COLL_PATH) != 0) {
	/* preserver the last entry of the coll path */
	char *tmpPtr = collInp.collName;
	int tmpLen = 0;
	collLen = 0;
	/* find length to the last '/' */
        while (*tmpPtr != '\0') {
	    if (*tmpPtr == '/') collLen = tmpLen;
	    tmpLen++;
	    tmpPtr++;
	}
    } else {
        collLen = strlen (collInp.collName);
    }
    while ((status = rsReadCollection (rsComm, &handleInx, &collEnt)) >= 0) {
        if (collEnt->objType == DATA_OBJ_T) {
            if (collEnt->collName[collLen] == '\0') {
                snprintf (tmpPath, MAX_NAME_LEN, "%s/%s",
                  phyBunDir, collEnt->dataName);
            } else {
                snprintf (tmpPath, MAX_NAME_LEN, "%s/%s/%s",
                 phyBunDir, collEnt->collName + collLen + 1, collEnt->dataName);               
	        mkDirForFilePath (UNIX_FILE_TYPE, rsComm, phyBunDir, 
	          tmpPath, getDefDirMode ());
            }
            /* add a link */
            status = link (collEnt->phyPath, tmpPath);
            if (status < 0) {
                rodsLog (LOG_ERROR,
                  "rsStructFileBundle: link error %s to %s. errno = %d",
                  collEnt->phyPath, tmpPath, errno);
                rmLinkedFilesInUnixDir (phyBunDir);
                rmdir (phyBunDir);
                return (UNIX_FILE_LINK_ERR - errno);
            }
        } else {        /* a collection */
	    if ((int) strlen (collEnt->collName) + 1 <= collLen) {
		free (collEnt);
		continue;
	    }
            snprintf (tmpPath, MAX_NAME_LEN, "%s/%s",
              phyBunDir, collEnt->collName + collLen);
            mkdirR (phyBunDir, tmpPath, getDefDirMode ());
	}
	if (collEnt != NULL) {
	    free (collEnt);
	    collEnt = NULL;
	}
    }
    clearKeyVal (&collInp.condInput);
    rsCloseCollection (rsComm, &handleInx);

    status = phyBundle (rsComm, L1desc[l1descInx].dataObjInfo, phyBunDir,
      collInp.collName, structFileBundleInp->oprType);
    if (status < 0) {
        rodsLog (LOG_ERROR,
          "rsStructFileBundle: phyBundle of %s error. stat = %d",
          L1desc[l1descInx].dataObjInfo->objPath, status);
	L1desc[l1descInx].bytesWritten = 0;
	savedStatus = status;
    } else {
        /* mark it was written so the size would be adjusted */
        L1desc[l1descInx].bytesWritten = 1;
    }

    rmLinkedFilesInUnixDir (phyBunDir);
    rmdir (phyBunDir);

    dataObjCloseInp.l1descInx = l1descInx;
    status = rsDataObjClose (rsComm, &dataObjCloseInp);

    if (status >= 0)
	return savedStatus;
    else
        return (status);
}
Esempio n. 6
0
    int
    rsNcCreate( rsComm_t *rsComm, ncOpenInp_t *ncCreateInp, int **ncid ) {
        int remoteFlag;
        rodsServerHost_t *rodsServerHost;
        specCollCache_t *specCollCache = NULL;
        int status;
        dataObjInp_t dataObjInp;
        int l1descInx, myncid;

        if ( getValByKey( &ncCreateInp->condInput, NATIVE_NETCDF_CALL_KW ) != NULL ) {
            /* just do nc_open with objPath as file nc file path */
            /* must to be called internally */
            if ( rsComm->proxyUser.authInfo.authFlag < REMOTE_PRIV_USER_AUTH ) {
                return( CAT_INSUFFICIENT_PRIVILEGE_LEVEL );
            }
            status = nc_create( ncCreateInp->objPath, ncCreateInp->mode, &myncid );
            if ( status == NC_NOERR ) {
                *ncid = ( int * ) malloc( sizeof( int ) );
                *( *ncid ) = myncid;
                return 0;
            }
            else {
                rodsLog( LOG_ERROR,
                         "rsNccreate: nc_create %s error, status = %d, %s",
                         ncCreateInp->objPath, status, nc_strerror( status ) );
                return ( NETCDF_OPEN_ERR + status );
            }
        }
        bzero( &dataObjInp, sizeof( dataObjInp ) );
        rstrcpy( dataObjInp.objPath, ncCreateInp->objPath, MAX_NAME_LEN );
        replKeyVal( &ncCreateInp->condInput, &dataObjInp.condInput );
        resolveLinkedPath( rsComm, dataObjInp.objPath, &specCollCache,
                           &dataObjInp.condInput );
        remoteFlag = getAndConnRemoteZone( rsComm, &dataObjInp, &rodsServerHost,
                                           REMOTE_OPEN );

        if ( remoteFlag < 0 ) {
            return ( remoteFlag );
        }
        else if ( remoteFlag == LOCAL_HOST ) {
            addKeyVal( &dataObjInp.condInput, NO_OPEN_FLAG_KW, "" );
            l1descInx = _rsDataObjCreate( rsComm, &dataObjInp );
            clearKeyVal( &dataObjInp.condInput );
            if ( l1descInx < 0 ) {
                return l1descInx;
            }
        
            l1desc_t& my_desc = irods::get_l1desc( l1descInx );
            remoteFlag = resoAndConnHostByDataObjInfo( rsComm,
                         my_desc.dataObjInfo, &rodsServerHost );
            if ( remoteFlag < 0 ) {
                return ( remoteFlag );
            }
            else if ( remoteFlag == LOCAL_HOST ) {
                status = nc_create( my_desc.dataObjInfo->filePath,
                                    ncCreateInp->mode, &myncid );
                if ( status != NC_NOERR ) {
                    rodsLog( LOG_ERROR,
                             "rsNcCreate: nc_open %s error, status = %d, %s",
                             ncCreateInp->objPath, status, nc_strerror( status ) );
                    freeL1desc( l1descInx );
                    return ( NETCDF_CREATE_ERR + status );
                }
            }
            else {
                /* execute it remotely with dataObjInfo->filePath */
                ncOpenInp_t myNcCreateInp;
                bzero( &myNcCreateInp, sizeof( myNcCreateInp ) );
                rstrcpy( myNcCreateInp.objPath,
                         my_desc.dataObjInfo->filePath, MAX_NAME_LEN );
                addKeyVal( &myNcCreateInp.condInput, NATIVE_NETCDF_CALL_KW, "" );
                status = rcNcCreate( rodsServerHost->conn, &myNcCreateInp, &myncid );
                clearKeyVal( &myNcCreateInp.condInput );
                if ( status < 0 ) {
                    rodsLog( LOG_ERROR,
                             "rsNcCreate: _rcNcCreate %s error, status = %d",
                             myNcCreateInp.objPath, status );
                    freeL1desc( l1descInx );
                    return ( status );
                }
            }
            my_desc.l3descInx = myncid;
            /* need to reg here since NO_OPEN_FLAG_KW does not do it */
            if ( my_desc.dataObjInfo->specColl == NULL ) {
                status = svrRegDataObj( rsComm, my_desc.dataObjInfo );
                if ( status < 0 ) {
                    ncCloseInp_t myNcCloseInp;
                    bzero( &myNcCloseInp, sizeof( myNcCloseInp ) );
                    myNcCloseInp.ncid = l1descInx;
                    irods::server_api_call ( NC_CLOSE_AN, rsComm, &myNcCloseInp );
                    l3Unlink( rsComm, my_desc.dataObjInfo );
                    rodsLog( LOG_ERROR,
                             "rsNcCreate: svrRegDataObj for %s failed, status = %d",
                             my_desc.dataObjInfo->objPath, status );
                    freeL1desc( l1descInx );
                    return ( NETCDF_CREATE_ERR + status );
                }
            }
        }
        else {
            addKeyVal( &dataObjInp.condInput, CROSS_ZONE_CREATE_KW, "" );
            status = rcNcCreate( rodsServerHost->conn, ncCreateInp, &myncid );
            /* rm it to avoid confusion */
            rmKeyVal( &dataObjInp.condInput, CROSS_ZONE_CREATE_KW );
            if ( status < 0 ) {
                rodsLog( LOG_ERROR,
                         "rsNcCreate: _rcNcCreate %s error, status = %d",
                         ncCreateInp->objPath, status );
                return ( status );
            }
            l1descInx = allocAndSetL1descForZoneOpr( myncid, &dataObjInp,
                        rodsServerHost, NULL );
        }
        
        l1desc_t& my_desc = irods::get_l1desc( l1descInx );
        my_desc.oprType = NC_CREATE;
        *ncid = ( int * ) malloc( sizeof( int ) );
        *( *ncid ) = l1descInx;

        return 0;
    }
Esempio n. 7
0
int
dataObjUnlinkS (rsComm_t *rsComm, dataObjInp_t *dataObjUnlinkInp,
dataObjInfo_t *dataObjInfo)
{
    int status;
    unregDataObj_t unregDataObjInp;

    if (dataObjInfo->specColl == NULL) {
	if (dataObjUnlinkInp->oprType == UNREG_OPR && 
	  rsComm->clientUser.authInfo.authFlag != LOCAL_PRIV_USER_AUTH) {
	    ruleExecInfo_t rei;

            initReiWithDataObjInp (&rei, rsComm, dataObjUnlinkInp);
            rei.doi = dataObjInfo;
            rei.status = DO_CHK_PATH_PERM;         /* default */
            applyRule ("acSetChkFilePathPerm", NULL, &rei, NO_SAVE_REI);
            if (rei.status != NO_CHK_PATH_PERM) {
                char *outVaultPath;
                rodsServerHost_t *rodsServerHost;
	        status = resolveHostByRescInfo (dataObjInfo->rescInfo, 
	          &rodsServerHost);
	        if (status < 0) return status;
	        /* unregistering but not an admin user */
	        status = matchVaultPath (rsComm, dataObjInfo->filePath, 
	          rodsServerHost, &outVaultPath);
	        if (status != 0) {
		    /* in the vault */
                    rodsLog (LOG_DEBUG,
                      "dataObjUnlinkS: unregistering in vault file %s",
                      dataObjInfo->filePath);
                    return CANT_UNREG_IN_VAULT_FILE;
		}
	    }
#if 0	/* don't need this since we are doing orphan */
	} else if (RescTypeDef[dataObjInfo->rescInfo->rescTypeInx].driverType 
	  == WOS_FILE_TYPE && dataObjUnlinkInp->oprType != UNREG_OPR) {
	    /* WOS_FILE_TYPE, unlink first before unreg because orphan files
	     * cannot be reclaimed */
            status = l3Unlink (rsComm, dataObjInfo);
            if (status < 0) {
                rodsLog (LOG_NOTICE,
                  "dataObjUnlinkS: l3Unlink error for WOS file %s. status = %d",
                  dataObjUnlinkInp->objPath, status);
		return status;
	    }
            unregDataObjInp.dataObjInfo = dataObjInfo;
            unregDataObjInp.condInput = &dataObjUnlinkInp->condInput;
            status = rsUnregDataObj (rsComm, &unregDataObjInp);
            if (status < 0) {
                rodsLog (LOG_NOTICE,
                  "dataObjUnlinkS: rsUnregDataObj error for %s. status = %d",
                  dataObjUnlinkInp->objPath, status);
            }
            return status;
#endif
	}
        unregDataObjInp.dataObjInfo = dataObjInfo;
        unregDataObjInp.condInput = &dataObjUnlinkInp->condInput;
        status = rsUnregDataObj (rsComm, &unregDataObjInp);

        if (status < 0) {
            rodsLog (LOG_NOTICE,
              "dataObjUnlinkS: rsUnregDataObj error for %s. status = %d",
              dataObjUnlinkInp->objPath, status);
	    return status;
        }
    }
    
    if (dataObjUnlinkInp->oprType != UNREG_OPR) {
        status = l3Unlink (rsComm, dataObjInfo);
        if (status < 0) {
	    int myError = getErrno (status);
            rodsLog (LOG_NOTICE,
              "dataObjUnlinkS: l3Unlink error for %s. status = %d",
              dataObjUnlinkInp->objPath, status);
	    /* allow ENOENT to go on and unregister */
	    if (myError != ENOENT && myError != EACCES) {
		char orphanPath[MAX_NAME_LEN];
		int status1 = 0;
                rodsLog (LOG_NOTICE,
                  "dataObjUnlinkS: orphan file %s", dataObjInfo->filePath);
		while (1) { 
		    if (isOrphanPath (dataObjUnlinkInp->objPath) == 
		      NOT_ORPHAN_PATH) {
			/* don't rename orphan path */
		        status1 = rsMkOrphanPath (rsComm, dataObjInfo->objPath,
		          orphanPath);
		        if (status1 < 0) break;
		        /* reg the orphan path */
		        rstrcpy (dataObjInfo->objPath, orphanPath,MAX_NAME_LEN);
		    }
		    status1 = svrRegDataObj (rsComm, dataObjInfo);
		    if (status1 == CAT_NAME_EXISTS_AS_DATAOBJ ||
		      status1 == CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME) {
			continue;
		    } else if (status1 < 0) {
			rodsLogError (LOG_ERROR, status1,
			  "dataObjUnlinkS: svrRegDataObj of orphan %s error",
			  dataObjInfo->objPath);
		    }
		    break;
		}
	        return (status);
	    } else {
	        status = 0;
	    }
	}
    }

    return (status);
}
Esempio n. 8
0
int
dataObjUnlinkS( rsComm_t *rsComm, dataObjInp_t *dataObjUnlinkInp,
                dataObjInfo_t *dataObjInfo ) {
    int status = 0;
    unregDataObj_t unregDataObjInp;

    if ( dataObjInfo->specColl == NULL ) {
        if ( dataObjUnlinkInp->oprType            == UNREG_OPR &&
                rsComm->clientUser.authInfo.authFlag != LOCAL_PRIV_USER_AUTH ) {
            ruleExecInfo_t rei;

            initReiWithDataObjInp( &rei, rsComm, dataObjUnlinkInp );
            rei.doi = dataObjInfo;
            rei.status = DO_CHK_PATH_PERM;         /* default */ // JMC - backport 4758

            // make resource properties available as rule session variables
            rei.condInputData = (keyValPair_t *)malloc(sizeof(keyValPair_t));
            memset(rei.condInputData, 0, sizeof(keyValPair_t));
            irods::get_resc_properties_as_kvp(rei.doi->rescHier, rei.condInputData);

            applyRule( "acSetChkFilePathPerm", NULL, &rei, NO_SAVE_REI );
            if ( rei.status != NO_CHK_PATH_PERM ) {
                // =-=-=-=-=-=-=-
                // extract the host location from the resource hierarchy
                std::string location;
                irods::error ret = irods::get_loc_for_hier_string( dataObjInfo->rescHier, location );
                if ( !ret.ok() ) {
                    irods::log( PASSMSG( "dataObjUnlinkS - failed in get_loc_for_hier_string", ret ) );
                    return ret.code();
                }

                rodsHostAddr_t addr;
                rodsServerHost_t *rodsServerHost = 0;

                memset( &addr, 0, sizeof( addr ) );
                rstrcpy( addr.hostAddr, location.c_str(), NAME_LEN );
                int remoteFlag = resolveHost( &addr, &rodsServerHost );
                if ( remoteFlag < 0 ) {
                    // error condition?
                }

                /* unregistering but not an admin user */
                std::string out_path;
                ret = resc_mgr.validate_vault_path( dataObjInfo->filePath, rodsServerHost, out_path );
                if ( !ret.ok() ) {
                    /* in the vault */
                    std::stringstream msg;
                    msg << "unregistering a data object which is in a vault [";
                    msg << dataObjInfo->filePath << "]";
                    irods::log( PASSMSG( msg.str(), ret ) );
                    return CANT_UNREG_IN_VAULT_FILE;
                }
            }
        }

        unregDataObjInp.dataObjInfo = dataObjInfo;
        unregDataObjInp.condInput = &dataObjUnlinkInp->condInput;
        status = rsUnregDataObj( rsComm, &unregDataObjInp );

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

    if ( dataObjUnlinkInp->oprType != UNREG_OPR ) {

        // Set the in_pdmo flag
        char* in_pdmo = getValByKey( &dataObjUnlinkInp->condInput, IN_PDMO_KW );
        if ( in_pdmo != NULL ) {
            rstrcpy( dataObjInfo->in_pdmo, in_pdmo, MAX_NAME_LEN );
        }
        else {
            dataObjInfo->in_pdmo[0] = '\0';
        }

        status = l3Unlink( rsComm, dataObjInfo );
        if ( status < 0 ) {
            int myError = getErrno( status );
            rodsLog( LOG_NOTICE,
                     "dataObjUnlinkS: l3Unlink error for %s. status = %d",
                     dataObjUnlinkInp->objPath, status );
            /* allow ENOENT to go on and unregister */
            if ( myError != ENOENT && myError != EACCES ) {
                char orphanPath[MAX_NAME_LEN];
                int status1 = 0;
                rodsLog( LOG_NOTICE,
                         "dataObjUnlinkS: orphan file %s", dataObjInfo->filePath );
                while ( 1 ) {
                    if ( isOrphanPath( dataObjUnlinkInp->objPath ) ==
                            NOT_ORPHAN_PATH ) {
                        /* don't rename orphan path */
                        status1 = rsMkOrphanPath( rsComm, dataObjInfo->objPath,
                                                  orphanPath );
                        if ( status1 < 0 ) {
                            break;
                        }
                        /* reg the orphan path */
                        rstrcpy( dataObjInfo->objPath, orphanPath, MAX_NAME_LEN );
                    }
                    status1 = svrRegDataObj( rsComm, dataObjInfo );
                    if ( status1 == CAT_NAME_EXISTS_AS_DATAOBJ ||
                            status1 == CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME ) {
                        continue;
                    }
                    else if ( status1 < 0 ) {
                        rodsLogError( LOG_ERROR, status1,
                                      "dataObjUnlinkS: svrRegDataObj of orphan %s error",
                                      dataObjInfo->objPath );
                    }
                    break;
                }
                return status;
            }
            else {
                status = 0;
            }
        }
    }

    return status;
}