// =-=-=-=-=-=-=- // local function to handle call to mkdir via resource plugin int _rsFileMkdir( rsComm_t* _comm, fileMkdirInp_t* _mkdir_inp ) { // =-=-=-=-=-=-=- // make call to mkdir via resource plugin irods::collection_object_ptr coll_obj( new irods::collection_object( _mkdir_inp->dirName, _mkdir_inp->rescHier, _mkdir_inp->mode, 0 ) ); // =-=-=-=-=-=-=- // pass condInput coll_obj->cond_input( _mkdir_inp->condInput ); irods::error mkdir_err = fileMkdir( _comm, coll_obj ); // =-=-=-=-=-=-=- // log error if necessary if ( !mkdir_err.ok() ) { if ( getErrno( mkdir_err.code() ) != EEXIST ) { std::stringstream msg; msg << "fileMkdir failed for "; msg << _mkdir_inp->dirName; msg << "]"; irods::error ret_err = PASSMSG( msg.str(), mkdir_err ); irods::log( ret_err ); } } return ( mkdir_err.code() ); } // _rsFileMkdir
int _rsFileMkdir (rsComm_t *rsComm, fileMkdirInp_t *fileMkdirInp) { int status; status = fileMkdir (fileMkdirInp->fileType, rsComm, fileMkdirInp->dirName, fileMkdirInp->mode, &fileMkdirInp->condInput); if (status < 0) { if (getErrno (status) != EEXIST) rodsLog (LOG_NOTICE, "_rsFileMkdir: fileMkdir for %s, status = %d", fileMkdirInp->dirName, status); return (status); } return (status); }
// =-=-=-=-=-=-=- // mk the directory recursively int mkFileDirR( rsComm_t * rsComm, size_t startDirLen, const std::string& destDir, const std::string& hier, int mode ) { std::string physical_directory_prefix; if ( destDir.empty() ) { rodsLog( LOG_ERROR, "mkFileDirR called with empty dest directory" ); return SYS_INVALID_INPUT_PARAM ; } if ( destDir.size() < startDirLen ) { rodsLog( LOG_ERROR, "mkFileDirR called with a destDir: [%s]" "shorter than its startDirLen: [%ju]", destDir.c_str(), ( uintmax_t )startDirLen ); return SYS_INVALID_INPUT_PARAM; } if ( !rsComm ) { rodsLog( LOG_ERROR, "mkFileDirR called with null rsComm" ); return SYS_INVALID_INPUT_PARAM; } if ( isValidFilePath( destDir ) ) { std::string vault_path; irods::error err = irods::get_vault_path_for_hier_string( hier, vault_path ); if ( !err.ok() ) { rodsLog( LOG_ERROR, err.result().c_str() ); return err.code(); } if ( destDir.compare( 0, vault_path.size(), vault_path ) == 0 && ( destDir[ vault_path.size() ] == '/' || destDir.size() == vault_path.size() ) ) { physical_directory_prefix = vault_path; } } std::vector< std::string > directories_to_create; std::string physical_directory = destDir; if ( physical_directory[ physical_directory.size() - 1 ] == '/' ) { physical_directory.erase( physical_directory.size() - 1 ); } while ( physical_directory.size() > startDirLen ) { irods::collection_object_ptr tmp_coll_obj( new irods::collection_object( physical_directory, hier, 0, 0 ) ); struct stat statbuf; irods::error stat_err = fileStat( rsComm, tmp_coll_obj, &statbuf ); if ( stat_err.code() >= 0 ) { if ( statbuf.st_mode & S_IFDIR ) { break; } else { rodsLog( LOG_NOTICE, "mkFileDirR: A local non-directory %s already exists \n", physical_directory.c_str() ); return stat_err.code(); } } else { directories_to_create.push_back( physical_directory.substr( physical_directory_prefix.size() ) ); } /* Go backward */ size_t index_of_last_slash = physical_directory.rfind( '/', physical_directory.size() - 1 ); if ( std::string::npos != index_of_last_slash ) { physical_directory = physical_directory.substr( 0, index_of_last_slash ); } else { break; } } // while std::string irods_directory_prefix = "/"; irods_directory_prefix += getLocalZoneName(); /* Now we go forward and make the required dir */ while ( !directories_to_create.empty() ) { physical_directory = physical_directory_prefix; physical_directory += directories_to_create.back(); std::string irods_directory = irods_directory_prefix; irods_directory += directories_to_create.back(); directories_to_create.pop_back(); irods::collection_object_ptr tmp_coll_obj( new irods::collection_object( physical_directory, hier, mode, 0 ) ); irods::error mkdir_err = fileMkdir( rsComm, tmp_coll_obj ); if ( !mkdir_err.ok() && ( getErrno( mkdir_err.code() ) != EEXIST ) ) { // JMC - backport 4834 std::stringstream msg; msg << "fileMkdir for ["; msg << physical_directory; msg << "]"; irods::error ret_err = PASSMSG( msg.str(), mkdir_err ); irods::log( ret_err ); return mkdir_err.code(); } } return 0; }
int mkFileDirR (int fileType, rsComm_t *rsComm, char *startDir, char *destDir, int mode) { int status; int startLen; int pathLen, tmpLen; char tmpPath[MAX_NAME_LEN]; struct stat statbuf; #ifdef DIRECT_ACCESS_VAULT rodsHostAddr_t addr; rodsServerHost_t *rodsServerHost; char *zoneName; char *outVaultPath; int vp_len; char collName[MAX_NAME_LEN]; keyValPair_t condInput; #endif startLen = strlen (startDir); pathLen = strlen (destDir); rstrcpy (tmpPath, destDir, MAX_NAME_LEN); tmpLen = pathLen; while (tmpLen > startLen) { status = fileStat ( (fileDriverType_t)fileType, rsComm, tmpPath, &statbuf); if (status >= 0) { if (statbuf.st_mode & S_IFDIR) { break; } else { rodsLog (LOG_NOTICE, "mkFileDirR: A local non-directory %s already exists \n", tmpPath); return (status); } } /* Go backward */ while (tmpLen && tmpPath[tmpLen] != '/') tmpLen --; tmpPath[tmpLen] = '\0'; } #ifdef DIRECT_ACCESS_VAULT if (fileType == DIRECT_ACCESS_FILE_TYPE) { zoneName = getLocalZoneName(); addr.hostAddr[0] = '\0'; resolveHost(&addr, &rodsServerHost); vp_len = matchVaultPath(rsComm, destDir, rodsServerHost, &outVaultPath); if (vp_len == 0) { outVaultPath = NULL; } } #endif /* Now we go forward and make the required dir */ while (tmpLen < pathLen) { /* Put back the '/' */ tmpPath[tmpLen] = '/'; #ifdef DIRECT_ACCESS_VAULT memset(&condInput, 0, sizeof(condInput)); if (fileType == DIRECT_ACCESS_FILE_TYPE) { snprintf(collName, MAX_NAME_LEN, "/%s%s", zoneName, tmpPath + vp_len); status = rsQueryDirectoryMeta(rsComm, collName, &condInput); } status = fileMkdir ((fileDriverType_t)fileType, rsComm, tmpPath, mode, &condInput); #else status = fileMkdir ((fileDriverType_t)fileType, rsComm, tmpPath, mode, NULL); #endif if (status < 0 && (getErrno (status) != EEXIST)) { rodsLog (LOG_NOTICE, "mkFileDirR: mkdir failed for %s, status =%d", tmpPath, status); return status; } #if 0 /* a fix from AndyS */ while (tmpLen && tmpPath[tmpLen] != '\0') #endif while (tmpPath[tmpLen] != '\0') tmpLen ++; } return 0; }