예제 #1
0
int
closeAllL1desc( rsComm_t *rsComm ) {
    int i;

    if ( rsComm == NULL ) {
        return 0;
    }
    for ( i = 3; i < NUM_L1_DESC; i++ ) {
        if ( L1desc[i].inuseFlag == FD_INUSE &&
                L1desc[i].l3descInx > 2 ) {
            l3Close( rsComm, i );
        }
    }
    return 0;
}
예제 #2
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;
}
예제 #3
0
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);
}