00001
00002
00003 #include "structFileDriver.h"
00004 #include "structFileExtract.h"
00005 #include "miscServerFunct.h"
00006 #include "syncMountedColl.h"
00007
00008 #include "dataObjOpr.h"
00009 #include "rsGlobalExtern.h"
00010 #include "objMetaOpr.h"
00011 #include "resource.h"
00012 #include "physPath.h"
00013
00014
00015 int
00016 rsStructFileExtract (rsComm_t *rsComm, structFileOprInp_t *structFileOprInp)
00017 {
00018 rodsServerHost_t *rodsServerHost;
00019 int remoteFlag;
00020 int status;
00021
00022 remoteFlag = resolveHost (&structFileOprInp->addr, &rodsServerHost);
00023
00024 if (remoteFlag == LOCAL_HOST) {
00025 status = _rsStructFileExtract (rsComm, structFileOprInp);
00026 } else if (remoteFlag == REMOTE_HOST) {
00027 status =
00028 remoteStructFileExtract (rsComm, structFileOprInp, rodsServerHost);
00029 } else {
00030 if (remoteFlag < 0) {
00031 return (remoteFlag);
00032 } else {
00033 rodsLog (LOG_NOTICE,
00034 "rsStructFileExtract: resolveHost returned unrecognized value %d",
00035 remoteFlag);
00036 return (SYS_UNRECOGNIZED_REMOTE_FLAG);
00037 }
00038 }
00039
00040 return (status);
00041 }
00042
00043 int
00044 remoteStructFileExtract (rsComm_t *rsComm,
00045 structFileOprInp_t *structFileOprInp, rodsServerHost_t *rodsServerHost)
00046 {
00047 int status;
00048
00049 if (rodsServerHost == NULL) {
00050 rodsLog (LOG_NOTICE,
00051 "remoteStructFileExtract: Invalid rodsServerHost");
00052 return SYS_INVALID_SERVER_HOST;
00053 }
00054
00055 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00056 return status;
00057 }
00058
00059 status = rcStructFileExtract (rodsServerHost->conn, structFileOprInp);
00060
00061 if (status < 0) {
00062 rodsLog (LOG_NOTICE,
00063 "remoteStructFileExtract: rcStructFileExtract failed for %s, status = %d",
00064 structFileOprInp->specColl->collection, status);
00065 }
00066
00067 return status;
00068 }
00069
00070 int
00071 _rsStructFileExtract (rsComm_t *rsComm, structFileOprInp_t *structFileOprInp)
00072 {
00073 int status;
00074 specColl_t *specColl;
00075
00076
00077 if (rsComm == NULL || structFileOprInp == NULL ||
00078 structFileOprInp->specColl == NULL) {
00079 rodsLog (LOG_ERROR,
00080 "_rsStructFileExtract: NULL input");
00081 return (SYS_INTERNAL_NULL_INPUT_ERR);
00082 }
00083
00084 specColl = structFileOprInp->specColl;
00085
00086 status = procCacheDir (rsComm, specColl->cacheDir, specColl->resource, structFileOprInp->oprType);
00087 if (status < 0) return status;
00088
00089 status = structFileExtract (rsComm, structFileOprInp);
00090
00091 return (status);
00092 }
00093
00094 int
00095 procCacheDir (rsComm_t *rsComm, char *cacheDir, char *resource, int oprType)
00096 {
00097 int status;
00098 int fileType;
00099 rescInfo_t *rescInfo;
00100
00101 status = resolveResc (resource, &rescInfo);
00102
00103 if (status < 0) {
00104 rodsLog (LOG_ERROR,
00105 "procCacheDir: resolveResc error for %s, status = %d",
00106 resource, status);
00107 return (status);
00108 }
00109
00110 fileType = RescTypeDef[rescInfo->rescTypeInx].driverType;
00111
00112 if ((oprType & PRESERVE_DIR_CONT) == 0) {
00113 status = chkEmptyDir (fileType, rsComm, cacheDir);
00114
00115 if (status == SYS_DIR_IN_VAULT_NOT_EMPTY) {
00116 rodsLog (LOG_ERROR,
00117 "procCacheDir: chkEmptyDir error for %s in resc %s, status = %d",
00118 cacheDir, resource, status);
00119 return (status);
00120 }
00121
00122 }
00123
00124 mkFileDirR (fileType, rsComm, "/", cacheDir, getDefDirMode ());
00125
00126 return (status);
00127 }
00128