/* filePathTypeInResc - the status of a filePath in a resource. * return LOCAL_FILE_T, LOCAL_DIR_T, UNKNOWN_OBJ_T or error (-ive) */ int filePathTypeInResc (rsComm_t *rsComm, char *fileName, rescInfo_t *rescInfo) { int rescTypeInx; fileStatInp_t fileStatInp; rodsStat_t *myStat = NULL; int status; memset (&fileStatInp, 0, sizeof (fileStatInp)); rstrcpy (fileStatInp.fileName, fileName, MAX_NAME_LEN); rescTypeInx = rescInfo->rescTypeInx; fileStatInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType; rstrcpy (fileStatInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN); status = rsFileStat (rsComm, &fileStatInp, &myStat); if (status < 0 || !myStat) return status; // cppcheck - Possible null pointer dereference: myStat if (myStat->st_mode & S_IFREG) { free (myStat); return LOCAL_FILE_T; } else if (myStat->st_mode & S_IFDIR) { free (myStat); return LOCAL_DIR_T; } else { free (myStat); return UNKNOWN_OBJ_T; } }
/* filePathTypeInResc - the status of a filePath in a resource. * return LOCAL_FILE_T, LOCAL_DIR_T, UNKNOWN_OBJ_T or error (-ive) */ int filePathTypeInResc( rsComm_t* rsComm, const std::string& objPath, const std::string& fileName, const std::string& rescHier ) { fileStatInp_t fileStatInp; rodsStat_t *myStat = NULL; int status; // =-=-=-=-=-=-=- // get location of leaf in hier string std::string location; irods::error ret = irods::get_loc_for_hier_string( rescHier, location ); if ( !ret.ok() ) { irods::log( PASSMSG( "failed in get_loc_for_hier_string", ret ) ); return -1; } memset( &fileStatInp, 0, sizeof( fileStatInp ) ); rstrcpy( fileStatInp.fileName, fileName.c_str(), MAX_NAME_LEN ); rstrcpy( fileStatInp.rescHier, rescHier.c_str(), MAX_NAME_LEN ); rstrcpy( fileStatInp.objPath, objPath.c_str(), MAX_NAME_LEN ); rstrcpy( fileStatInp.addr.hostAddr, location.c_str(), NAME_LEN ); status = rsFileStat( rsComm, &fileStatInp, &myStat ); if ( status < 0 || NULL == myStat ) { return status; // JMC cppcheck - nullptr } if ( myStat->st_mode & S_IFREG ) { free( myStat ); return LOCAL_FILE_T; } else if ( myStat->st_mode & S_IFDIR ) { free( myStat ); return LOCAL_DIR_T; } else { free( myStat ); return UNKNOWN_OBJ_T; } }
int mountFileDir (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp, char *filePath, rescInfo_t *rescInfo) { collInp_t collCreateInp; int rescTypeInx; int status; fileStatInp_t fileStatInp; rodsStat_t *myStat = NULL; rodsObjStat_t *rodsObjStatOut = NULL; if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL); status = collStat (rsComm, phyPathRegInp, &rodsObjStatOut); if (status < 0) return status; if (rodsObjStatOut->specColl != NULL) { freeRodsObjStat (rodsObjStatOut); rodsLog (LOG_ERROR, "mountFileDir: %s already mounted", phyPathRegInp->objPath); return (SYS_MOUNT_MOUNTED_COLL_ERR); } freeRodsObjStat (rodsObjStatOut); if (isCollEmpty (rsComm, phyPathRegInp->objPath) == False) { rodsLog (LOG_ERROR, "mountFileDir: collection %s not empty", phyPathRegInp->objPath); return (SYS_COLLECTION_NOT_EMPTY); } memset (&fileStatInp, 0, sizeof (fileStatInp)); rstrcpy (fileStatInp.fileName, filePath, MAX_NAME_LEN); rescTypeInx = rescInfo->rescTypeInx; fileStatInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType; rstrcpy (fileStatInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN); status = rsFileStat (rsComm, &fileStatInp, &myStat); if (status < 0) { fileMkdirInp_t fileMkdirInp; rodsLog (LOG_NOTICE, "mountFileDir: rsFileStat failed for %s, status = %d, create it", fileStatInp.fileName, status); memset (&fileMkdirInp, 0, sizeof (fileMkdirInp)); rstrcpy (fileMkdirInp.dirName, filePath, MAX_NAME_LEN); fileMkdirInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType; fileMkdirInp.mode = getDefDirMode (); rstrcpy (fileMkdirInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN); status = rsFileMkdir (rsComm, &fileMkdirInp); if (status < 0) { return (status); } } else if ((myStat->st_mode & S_IFDIR) == 0) { rodsLog (LOG_ERROR, "mountFileDir: phyPath %s is not a directory", fileStatInp.fileName); free (myStat); return (USER_FILE_DOES_NOT_EXIST); } free (myStat); /* mk the collection */ memset (&collCreateInp, 0, sizeof (collCreateInp)); rstrcpy (collCreateInp.collName, phyPathRegInp->objPath, MAX_NAME_LEN); addKeyVal (&collCreateInp.condInput, COLLECTION_TYPE_KW, MOUNT_POINT_STR); addKeyVal (&collCreateInp.condInput, COLLECTION_INFO1_KW, filePath); addKeyVal (&collCreateInp.condInput, COLLECTION_INFO2_KW, rescInfo->rescName); /* try to mod the coll first */ status = rsModColl (rsComm, &collCreateInp); if (status < 0) { /* try to create it */ status = rsRegColl (rsComm, &collCreateInp); } if (status >= 0) { char outLogPath[MAX_NAME_LEN]; int status1; /* see if the phyPath is mapped into a real collection */ if (getLogPathFromPhyPath (filePath, rescInfo, outLogPath) >= 0 && strcmp (outLogPath, phyPathRegInp->objPath) != 0) { /* log path not the same as input objPath */ if (isColl (rsComm, outLogPath, NULL) >= 0) { modAccessControlInp_t modAccessControl; /* it is a real collection. better set the collection * to read-only mode because any modification to files * through this mounted collection can be trouble */ bzero (&modAccessControl, sizeof (modAccessControl)); modAccessControl.accessLevel = "read"; modAccessControl.userName = rsComm->clientUser.userName; modAccessControl.zone = rsComm->clientUser.rodsZone; modAccessControl.path = phyPathRegInp->objPath; status1 = rsModAccessControl(rsComm, &modAccessControl); if (status1 < 0) { rodsLog (LOG_NOTICE, "mountFileDir: rsModAccessControl err for %s, stat = %d", phyPathRegInp->objPath, status1); } } } } return (status); }
int dirPathReg (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp, char *filePath, rescInfo_t *rescInfo) { collInp_t collCreateInp; fileOpendirInp_t fileOpendirInp; fileClosedirInp_t fileClosedirInp; int rescTypeInx; int status; int dirFd; dataObjInp_t subPhyPathRegInp; fileReaddirInp_t fileReaddirInp; rodsDirent_t *rodsDirent = NULL; rodsObjStat_t *rodsObjStatOut = NULL; int forceFlag; fileStatInp_t fileStatInp; rodsStat_t *myStat = NULL; rescTypeInx = rescInfo->rescTypeInx; status = collStat (rsComm, phyPathRegInp, &rodsObjStatOut); if (status < 0) { memset (&collCreateInp, 0, sizeof (collCreateInp)); rstrcpy (collCreateInp.collName, phyPathRegInp->objPath, MAX_NAME_LEN); /* no need to resolve sym link */ addKeyVal (&collCreateInp.condInput, TRANSLATED_PATH_KW, ""); #ifdef FILESYSTEM_META /* stat the source directory to track the */ /* original directory meta-data */ memset (&fileStatInp, 0, sizeof (fileStatInp)); rstrcpy (fileStatInp.fileName, filePath, MAX_NAME_LEN); fileStatInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType; rstrcpy (fileStatInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN); status = rsFileStat (rsComm, &fileStatInp, &myStat); if (status != 0) { rodsLog (LOG_ERROR, "dirPathReg: rsFileStat failed for %s, status = %d", filePath, status); return (status); } getFileMetaFromStat (myStat, &collCreateInp.condInput); addKeyVal(&collCreateInp.condInput, FILE_SOURCE_PATH_KW, filePath); free (myStat); #endif /* FILESYSTEM_META */ /* create the coll just in case it does not exist */ status = rsCollCreate (rsComm, &collCreateInp); clearKeyVal (&collCreateInp.condInput); if (status < 0) return status; } else if (rodsObjStatOut->specColl != NULL) { freeRodsObjStat (rodsObjStatOut); rodsLog (LOG_ERROR, "mountFileDir: %s already mounted", phyPathRegInp->objPath); return (SYS_MOUNT_MOUNTED_COLL_ERR); } freeRodsObjStat (rodsObjStatOut); memset (&fileOpendirInp, 0, sizeof (fileOpendirInp)); rstrcpy (fileOpendirInp.dirName, filePath, MAX_NAME_LEN); fileOpendirInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType; rstrcpy (fileOpendirInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN); dirFd = rsFileOpendir (rsComm, &fileOpendirInp); if (dirFd < 0) { rodsLog (LOG_ERROR, "dirPathReg: rsFileOpendir for %s error, status = %d", filePath, dirFd); return (dirFd); } fileReaddirInp.fileInx = dirFd; if (getValByKey (&phyPathRegInp->condInput, FORCE_FLAG_KW) != NULL) { forceFlag = 1; } else { forceFlag = 0; } while ((status = rsFileReaddir (rsComm, &fileReaddirInp, &rodsDirent)) >= 0) { if (strcmp (rodsDirent->d_name, ".") == 0 || strcmp (rodsDirent->d_name, "..") == 0) { free (rodsDirent); continue; } memset (&fileStatInp, 0, sizeof (fileStatInp)); snprintf (fileStatInp.fileName, MAX_NAME_LEN, "%s/%s", filePath, rodsDirent->d_name); fileStatInp.fileType = fileOpendirInp.fileType; fileStatInp.addr = fileOpendirInp.addr; myStat = NULL; status = rsFileStat (rsComm, &fileStatInp, &myStat); if (status != 0) { rodsLog (LOG_ERROR, "dirPathReg: rsFileStat failed for %s, status = %d", fileStatInp.fileName, status); free (rodsDirent); return (status); } subPhyPathRegInp = *phyPathRegInp; snprintf (subPhyPathRegInp.objPath, MAX_NAME_LEN, "%s/%s", phyPathRegInp->objPath, rodsDirent->d_name); if ((myStat->st_mode & S_IFREG) != 0) { /* a file */ if (forceFlag > 0) { /* check if it already exists */ if (isData (rsComm, subPhyPathRegInp.objPath, NULL) >= 0) { free (myStat); free (rodsDirent); continue; } } subPhyPathRegInp.dataSize = myStat->st_size; if (getValByKey (&phyPathRegInp->condInput, REG_REPL_KW) != NULL) { status = filePathRegRepl (rsComm, &subPhyPathRegInp, fileStatInp.fileName, rescInfo); } else { addKeyVal (&subPhyPathRegInp.condInput, FILE_PATH_KW, fileStatInp.fileName); status = filePathReg (rsComm, &subPhyPathRegInp, fileStatInp.fileName, rescInfo); } } else if ((myStat->st_mode & S_IFDIR) != 0) { /* a directory */ status = dirPathReg (rsComm, &subPhyPathRegInp, fileStatInp.fileName, rescInfo); } free (myStat); free (rodsDirent); } if (status == -1) { /* just EOF */ status = 0; } fileClosedirInp.fileInx = dirFd; rsFileClosedir (rsComm, &fileClosedirInp); return (status); }
int mountFileDir (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp, char *filePath, rescInfo_t *rescInfo) { collInp_t collCreateInp; int rescTypeInx; int status; fileStatInp_t fileStatInp; rodsStat_t *myStat = NULL; rodsObjStat_t *rodsObjStatOut = NULL; status = collStat (rsComm, phyPathRegInp, &rodsObjStatOut); if (status < 0) return status; if (rodsObjStatOut->specColl != NULL) { free (rodsObjStatOut); rodsLog (LOG_ERROR, "mountFileDir: %s already mounted", phyPathRegInp->objPath); return (SYS_MOUNT_MOUNTED_COLL_ERR); } free (rodsObjStatOut); if (isCollEmpty (rsComm, phyPathRegInp->objPath) == False) { rodsLog (LOG_ERROR, "mountFileDir: collection %s not empty", phyPathRegInp->objPath); return (SYS_COLLECTION_NOT_EMPTY); } memset (&fileStatInp, 0, sizeof (fileStatInp)); rstrcpy (fileStatInp.fileName, filePath, MAX_NAME_LEN); rescTypeInx = rescInfo->rescTypeInx; fileStatInp.fileType = RescTypeDef[rescTypeInx].driverType; rstrcpy (fileStatInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN); status = rsFileStat (rsComm, &fileStatInp, &myStat); if (status < 0) { fileMkdirInp_t fileMkdirInp; rodsLog (LOG_NOTICE, "mountFileDir: rsFileStat failed for %s, status = %d, create it", fileStatInp.fileName, status); memset (&fileMkdirInp, 0, sizeof (fileMkdirInp)); rstrcpy (fileMkdirInp.dirName, filePath, MAX_NAME_LEN); fileMkdirInp.fileType = RescTypeDef[rescTypeInx].driverType; fileMkdirInp.mode = DEFAULT_DIR_MODE; rstrcpy (fileMkdirInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN); status = rsFileMkdir (rsComm, &fileMkdirInp); if (status < 0) { return (status); } } else if ((myStat->st_mode & S_IFDIR) == 0) { rodsLog (LOG_ERROR, "mountFileDir: phyPath %s is not a directory", fileStatInp.fileName); free (myStat); return (USER_FILE_DOES_NOT_EXIST); } free (myStat); /* mk the collection */ memset (&collCreateInp, 0, sizeof (collCreateInp)); rstrcpy (collCreateInp.collName, phyPathRegInp->objPath, MAX_NAME_LEN); addKeyVal (&collCreateInp.condInput, COLLECTION_TYPE_KW, MOUNT_POINT_STR); addKeyVal (&collCreateInp.condInput, COLLECTION_INFO1_KW, filePath); addKeyVal (&collCreateInp.condInput, COLLECTION_INFO2_KW, rescInfo->rescName); /* try to mod the coll first */ status = rsModColl (rsComm, &collCreateInp); if (status < 0) { /* try to create it */ status = rsRegColl (rsComm, &collCreateInp); } return (status); }
int dirPathReg (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp, char *filePath, rescInfo_t *rescInfo) { collInp_t collCreateInp; fileOpendirInp_t fileOpendirInp; fileClosedirInp_t fileClosedirInp; int rescTypeInx; int status; int dirFd; dataObjInp_t subPhyPathRegInp; fileReaddirInp_t fileReaddirInp; rodsDirent_t *rodsDirent = NULL; rodsObjStat_t *rodsObjStatOut = NULL; status = collStat (rsComm, phyPathRegInp, &rodsObjStatOut); if (status < 0) { memset (&collCreateInp, 0, sizeof (collCreateInp)); rstrcpy (collCreateInp.collName, phyPathRegInp->objPath, MAX_NAME_LEN); /* create the coll just in case it does not exist */ status = rsCollCreate (rsComm, &collCreateInp); if (status < 0) return status; } else if (rodsObjStatOut->specColl != NULL) { free (rodsObjStatOut); rodsLog (LOG_ERROR, "mountFileDir: %s already mounted", phyPathRegInp->objPath); return (SYS_MOUNT_MOUNTED_COLL_ERR); } free (rodsObjStatOut); memset (&fileOpendirInp, 0, sizeof (fileOpendirInp)); rescTypeInx = rescInfo->rescTypeInx; rstrcpy (fileOpendirInp.dirName, filePath, MAX_NAME_LEN); fileOpendirInp.fileType = RescTypeDef[rescTypeInx].driverType; rstrcpy (fileOpendirInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN); dirFd = rsFileOpendir (rsComm, &fileOpendirInp); if (dirFd < 0) { rodsLog (LOG_ERROR, "dirPathReg: rsFileOpendir for %s error, status = %d", filePath, dirFd); return (dirFd); } fileReaddirInp.fileInx = dirFd; while ((status = rsFileReaddir (rsComm, &fileReaddirInp, &rodsDirent)) >= 0) { fileStatInp_t fileStatInp; rodsStat_t *myStat = NULL; if (strcmp (rodsDirent->d_name, ".") == 0 || strcmp (rodsDirent->d_name, "..") == 0) { continue; } memset (&fileStatInp, 0, sizeof (fileStatInp)); snprintf (fileStatInp.fileName, MAX_NAME_LEN, "%s/%s", filePath, rodsDirent->d_name); fileStatInp.fileType = fileOpendirInp.fileType; fileStatInp.addr = fileOpendirInp.addr; status = rsFileStat (rsComm, &fileStatInp, &myStat); if (status != 0) { rodsLog (LOG_ERROR, "dirPathReg: rsFileStat failed for %s, status = %d", fileStatInp.fileName, status); return (status); } subPhyPathRegInp = *phyPathRegInp; snprintf (subPhyPathRegInp.objPath, MAX_NAME_LEN, "%s/%s", phyPathRegInp->objPath, rodsDirent->d_name); if ((myStat->st_mode & S_IFREG) != 0) { /* a file */ addKeyVal (&subPhyPathRegInp.condInput, FILE_PATH_KW, fileStatInp.fileName); subPhyPathRegInp.dataSize = myStat->st_size; status = filePathReg (rsComm, &subPhyPathRegInp, fileStatInp.fileName, rescInfo); } else if ((myStat->st_mode & S_IFDIR) != 0) { /* a directory */ status = dirPathReg (rsComm, &subPhyPathRegInp, fileStatInp.fileName, rescInfo); } free (myStat); } if (status == -1) { /* just EOF */ status = 0; } fileClosedirInp.fileInx = dirFd; rsFileClosedir (rsComm, &fileClosedirInp); return (status); }
int dirPathReg (rsComm_t *rsComm, dataObjInp_t *phyPathRegInp, char *filePath, rescInfo_t *rescInfo) { collInp_t collCreateInp; fileOpendirInp_t fileOpendirInp; fileClosedirInp_t fileClosedirInp; int rescTypeInx; int status; int dirFd; dataObjInp_t subPhyPathRegInp; fileReaddirInp_t fileReaddirInp; rodsDirent_t *rodsDirent = NULL; rodsObjStat_t *rodsObjStatOut = NULL; int forceFlag; fileStatInp_t fileStatInp; rodsStat_t *myStat = NULL; char curcoll[MAX_NAME_LEN]; *curcoll = '\0'; rescTypeInx = rescInfo->rescTypeInx; status = collStat (rsComm, phyPathRegInp, &rodsObjStatOut); if (status < 0) { memset (&collCreateInp, 0, sizeof (collCreateInp)); rstrcpy (collCreateInp.collName, phyPathRegInp->objPath, MAX_NAME_LEN); /* no need to resolve sym link */ addKeyVal (&collCreateInp.condInput, TRANSLATED_PATH_KW, ""); #ifdef FILESYSTEM_META /* stat the source directory to track the */ /* original directory meta-data */ memset (&fileStatInp, 0, sizeof (fileStatInp)); rstrcpy (fileStatInp.fileName, filePath, MAX_NAME_LEN); fileStatInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType; rstrcpy (fileStatInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN); status = rsFileStat (rsComm, &fileStatInp, &myStat); if (status != 0) { rodsLog (LOG_ERROR, "dirPathReg: rsFileStat failed for %s, status = %d", filePath, status); return (status); } getFileMetaFromStat (myStat, &collCreateInp.condInput); addKeyVal(&collCreateInp.condInput, FILE_SOURCE_PATH_KW, filePath); free (myStat); #endif /* FILESYSTEM_META */ /* create the coll just in case it does not exist */ status = rsCollCreate (rsComm, &collCreateInp); clearKeyVal (&collCreateInp.condInput); if (status < 0) { rodsLog (LOG_ERROR, "dirPathReg: rsCollCreate %s error. status = %d", phyPathRegInp->objPath, status); return status; } } else if (rodsObjStatOut->specColl != NULL) { freeRodsObjStat (rodsObjStatOut); rodsLog (LOG_ERROR, "dirPathReg: %s already mounted", phyPathRegInp->objPath); return (SYS_MOUNT_MOUNTED_COLL_ERR); } freeRodsObjStat (rodsObjStatOut); memset (&fileOpendirInp, 0, sizeof (fileOpendirInp)); rstrcpy (fileOpendirInp.dirName, filePath, MAX_NAME_LEN); fileOpendirInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType; rstrcpy (fileOpendirInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN); dirFd = rsFileOpendir (rsComm, &fileOpendirInp); if (dirFd < 0) { rodsLog (LOG_ERROR, "dirPathReg: rsFileOpendir for %s error, status = %d", filePath, dirFd); return (dirFd); } fileReaddirInp.fileInx = dirFd; if (getValByKey (&phyPathRegInp->condInput, FORCE_FLAG_KW) != NULL) { forceFlag = 1; } else { forceFlag = 0; } while ((status = rsFileReaddir (rsComm, &fileReaddirInp, &rodsDirent)) >= 0) { int len; if (strlen (rodsDirent->d_name) == 0) break; if (strcmp (rodsDirent->d_name, ".") == 0 || strcmp (rodsDirent->d_name, "..") == 0) { free (rodsDirent); continue; } if (matchPathname(ExcludePatterns, rodsDirent->d_name, filePath)) { continue; } memset (&fileStatInp, 0, sizeof (fileStatInp)); if (RescTypeDef[rescTypeInx].incParentDir == NO_INC_PARENT_DIR) { /* don't include parent path */ snprintf (fileStatInp.fileName, MAX_NAME_LEN, "%s", rodsDirent->d_name); } else if (RescTypeDef[rescTypeInx].incParentDir == PHYPATH_IN_DIR_PTR) { /* we can do this locally because this API is executed at the * resource server */ getPhyPathInOpenedDir (dirFd, rodsDirent->d_ino, fileStatInp.fileName); } else { len = strlen (filePath); if (filePath[len - 1] == '/') { /* already has a '/' */ snprintf (fileStatInp.fileName, MAX_NAME_LEN, "%s%s", filePath, rodsDirent->d_name); } else { snprintf (fileStatInp.fileName, MAX_NAME_LEN, "%s/%s", filePath, rodsDirent->d_name); } } fileStatInp.fileType = fileOpendirInp.fileType; fileStatInp.addr = fileOpendirInp.addr; myStat = NULL; status = rsFileStat (rsComm, &fileStatInp, &myStat); if (status != 0) { rodsLog (LOG_ERROR, "dirPathReg: rsFileStat failed for %s, status = %d", fileStatInp.fileName, status); free (rodsDirent); return (status); } if (RescTypeDef[rescTypeInx].driverType == TDS_FILE_TYPE && strchr (rodsDirent->d_name, '/') != NULL) { /* TDS may contain '/' in the file path */ char *tmpPtr = rodsDirent->d_name; /* replace '/' with '.' */ while (*tmpPtr != '\0') { if (*tmpPtr == '/') *tmpPtr = '.'; tmpPtr ++; } } if (RescTypeDef[rescTypeInx].incParentDir == PHYPATH_IN_DIR_PTR) { /* the st_mode is stored in the opened dir */ myStat->st_mode = getStModeInOpenedDir (dirFd, rodsDirent->d_ino); freePhyPathInOpenedDir (dirFd, rodsDirent->d_ino); } subPhyPathRegInp = *phyPathRegInp; if (RescTypeDef[rescTypeInx].incParentDir == NO_INC_PARENT_DIR) { char myDir[MAX_NAME_LEN], myFile[MAX_NAME_LEN]; /* d_name is a full path, need to split it */ if ((status = splitPathByKey (rodsDirent->d_name, myDir, myFile, '/')) < 0) { rodsLog (LOG_ERROR, "dirPathReg: splitPathByKey error for %s ", rodsDirent->d_name); continue; } snprintf (subPhyPathRegInp.objPath, MAX_NAME_LEN, "%s/%s", phyPathRegInp->objPath, myFile); } else if (RescTypeDef[rescTypeInx].incParentDir == PHYPATH_IN_DIR_PTR) { char curdir[MAX_NAME_LEN]; *curdir = '\0'; getCurDirInOpenedDir (dirFd, curdir); if (strlen (curdir) > 0) { /* see if we have done it already */ int len = strlen (subPhyPathRegInp.objPath); if (*curcoll == '\0' || strcmp (&curcoll[len + 1], curdir) != 0) { snprintf (curcoll, MAX_NAME_LEN, "%s/%s", phyPathRegInp->objPath, curdir); rsMkCollR (rsComm, phyPathRegInp->objPath, curcoll); } snprintf (subPhyPathRegInp.objPath, MAX_NAME_LEN, "%s/%s", curcoll, rodsDirent->d_name); } else { snprintf (subPhyPathRegInp.objPath, MAX_NAME_LEN, "%s/%s", phyPathRegInp->objPath, rodsDirent->d_name); } } else { snprintf (subPhyPathRegInp.objPath, MAX_NAME_LEN, "%s/%s", phyPathRegInp->objPath, rodsDirent->d_name); } if ((myStat->st_mode & S_IFREG) != 0) { /* a file */ if (forceFlag > 0) { /* check if it already exists */ if (isData (rsComm, subPhyPathRegInp.objPath, NULL) >= 0) { free (myStat); free (rodsDirent); continue; } } subPhyPathRegInp.dataSize = myStat->st_size; if (getValByKey (&phyPathRegInp->condInput, REG_REPL_KW) != NULL) { status = filePathRegRepl (rsComm, &subPhyPathRegInp, fileStatInp.fileName, rescInfo); } else { addKeyVal (&subPhyPathRegInp.condInput, FILE_PATH_KW, fileStatInp.fileName); status = filePathReg (rsComm, &subPhyPathRegInp, fileStatInp.fileName, rescInfo); } } else if ((myStat->st_mode & S_IFDIR) != 0) { /* a directory */ len = strlen (subPhyPathRegInp.objPath); if (subPhyPathRegInp.objPath[len - 1] == '/') { /* take out the end '/' for objPath */ subPhyPathRegInp.objPath[len - 1] = '\0'; } status = dirPathReg (rsComm, &subPhyPathRegInp, fileStatInp.fileName, rescInfo); } if (status < 0) return status; free (myStat); free (rodsDirent); } if (status == -1) { /* just EOF */ status = 0; } fileClosedirInp.fileInx = dirFd; rsFileClosedir (rsComm, &fileClosedirInp); return (status); }
pathnamePatterns_t * readPathnamePatternsFromFile(rsComm_t *rsComm, char *filename, rescInfo_t *rescInfo) { int status; rodsStat_t *stbuf; fileStatInp_t fileStatInp; bytesBuf_t fileReadBuf; fileOpenInp_t fileOpenInp; fileReadInp_t fileReadInp; fileCloseInp_t fileCloseInp; int buf_len, fd; pathnamePatterns_t *pp; if (rsComm == NULL || filename == NULL || rescInfo == NULL) { return NULL; } memset(&fileStatInp, 0, sizeof(fileStatInp)); rstrcpy(fileStatInp.fileName, filename, MAX_NAME_LEN); fileStatInp.fileType = (fileDriverType_t)RescTypeDef[rescInfo->rescTypeInx].driverType; rstrcpy(fileStatInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN); status = rsFileStat(rsComm, &fileStatInp, &stbuf); if (status != 0) { if (status != UNIX_FILE_STAT_ERR - ENOENT) { rodsLog(LOG_DEBUG, "readPathnamePatternsFromFile: can't stat %s. status = %d", fileStatInp.fileName, status); } return NULL; } buf_len = stbuf->st_size; free(stbuf); memset(&fileOpenInp, 0, sizeof(fileOpenInp)); rstrcpy(fileOpenInp.fileName, filename, MAX_NAME_LEN); fileOpenInp.fileType = (fileDriverType_t)RescTypeDef[rescInfo->rescTypeInx].driverType; rstrcpy(fileOpenInp.addr.hostAddr, rescInfo->rescLoc, NAME_LEN); fileOpenInp.flags = O_RDONLY; fd = rsFileOpen(rsComm, &fileOpenInp); if (fd < 0) { rodsLog(LOG_NOTICE, "readPathnamePatternsFromFile: can't open %s for reading. status = %d", fileOpenInp.fileName, fd); return NULL; } memset(&fileReadBuf, 0, sizeof(fileReadBuf)); fileReadBuf.buf = malloc(buf_len); if (fileReadBuf.buf == NULL) { rodsLog(LOG_NOTICE, "readPathnamePatternsFromFile: could not malloc buffer"); return NULL; } memset(&fileReadInp, 0, sizeof(fileReadInp)); fileReadInp.fileInx = fd; fileReadInp.len = buf_len; status = rsFileRead(rsComm, &fileReadInp, &fileReadBuf); memset(&fileCloseInp, 0, sizeof(fileCloseInp)); fileCloseInp.fileInx = fd; rsFileClose(rsComm, &fileCloseInp); if (status < 0) { rodsLog(LOG_NOTICE, "readPathnamePatternsFromFile: could not read %s. status = %d", fileOpenInp.fileName, status); free(fileReadBuf.buf); return NULL; } pp = readPathnamePatterns((char*)fileReadBuf.buf, buf_len); return pp; }