irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

rsDataObjTruncate.cpp
Go to the documentation of this file.
1 
3 /* This is script-generated code (for the most part). */
4 /* See dataObjTruncate.h for a description of this API call.*/
5 
6 #include "rcMisc.h"
7 #include "dataObjTruncate.h"
8 #include "rodsLog.h"
9 #include "icatDefines.h"
10 #include "fileTruncate.h"
11 #include "unregDataObj.h"
12 #include "objMetaOpr.hpp"
13 #include "dataObjOpr.hpp"
14 #include "rsGlobalExtern.hpp"
15 #include "rcGlobalExtern.h"
16 #include "rsDataObjTruncate.hpp"
17 #include "rmColl.h"
18 #include "modDataObjMeta.h"
19 #include "subStructFileTruncate.h"
20 #include "getRemoteZoneResc.h"
21 #include "phyBundleColl.h"
22 #include "rsModDataObjMeta.hpp"
24 #include "rsFileTruncate.hpp"
25 
27 
28 
29 
30 int
31 rsDataObjTruncate( rsComm_t *rsComm, dataObjInp_t *dataObjTruncateInp ) {
32  int status;
33  dataObjInfo_t *dataObjInfoHead = NULL;
34  int remoteFlag;
36 
37  remoteFlag = getAndConnRemoteZone( rsComm, dataObjTruncateInp,
39 
40  if ( remoteFlag < 0 ) {
41  return remoteFlag;
42  }
43  else if ( remoteFlag == REMOTE_HOST ) {
44  status = rcDataObjTruncate( rodsServerHost->conn, dataObjTruncateInp );
45  return status;
46  }
47 
48  dataObjTruncateInp->openFlags = O_WRONLY; /* set the permission checking */
49  status = getDataObjInfoIncSpecColl( rsComm, dataObjTruncateInp,
50  &dataObjInfoHead );
51 
52  if ( status < 0 ) {
53  return status;
54  }
55 
56  status = _rsDataObjTruncate( rsComm, dataObjTruncateInp, dataObjInfoHead );
57 
58  return status;
59 
60 }
61 
62 int
63 _rsDataObjTruncate( rsComm_t *rsComm, dataObjInp_t *dataObjTruncateInp,
64  dataObjInfo_t *dataObjInfoHead ) {
65  int status;
66  int retVal = 0;
67  dataObjInfo_t *tmpDataObjInfo;
68 
69  tmpDataObjInfo = dataObjInfoHead;
70  while ( tmpDataObjInfo != NULL ) {
71  status = dataObjTruncateS( rsComm, dataObjTruncateInp, tmpDataObjInfo );
72  if ( status < 0 ) {
73  if ( retVal == 0 ) {
74  retVal = status;
75  }
76  }
77  if ( dataObjTruncateInp->specColl != NULL ) { /* do only one */
78  break;
79  }
80  tmpDataObjInfo = tmpDataObjInfo->next;
81  }
82 
83  freeAllDataObjInfo( dataObjInfoHead );
84 
85  return retVal;
86 }
87 
88 int dataObjTruncateS( rsComm_t *rsComm, dataObjInp_t *dataObjTruncateInp,
89  dataObjInfo_t *dataObjInfo ) {
90  int status;
91  keyValPair_t regParam;
92  modDataObjMeta_t modDataObjMetaInp;
93  char tmpStr[MAX_NAME_LEN];
94 
95  if ( dataObjInfo->dataSize == dataObjTruncateInp->dataSize ) {
96  return 0;
97  }
98 
99  /* don't do anything for BUNDLE_RESC for now */
100  if ( strcmp( dataObjInfo->rescName, BUNDLE_RESC ) == 0 ) {
101  return 0;
102  }
103 
104  status = l3Truncate( rsComm, dataObjTruncateInp, dataObjInfo );
105 
106  if ( status < 0 ) {
107  int myError = getErrno( status );
109  "dataObjTruncateS: l3Truncate error for %s. status = %d",
110  dataObjTruncateInp->objPath, status );
111  /* allow ENOENT to go on and unregister */
112  if ( myError != ENOENT && myError != EACCES ) {
113  return status;
114  }
115  }
116 
117  if ( dataObjInfo->specColl == NULL ) {
118  /* reigister the new size */
119 
120  memset( &regParam, 0, sizeof( regParam ) );
121  memset( &modDataObjMetaInp, 0, sizeof( modDataObjMetaInp ) );
122 
123  snprintf( tmpStr, MAX_NAME_LEN, "%lld", dataObjTruncateInp->dataSize );
124  addKeyVal( &regParam, DATA_SIZE_KW, tmpStr );
125  addKeyVal( &regParam, CHKSUM_KW, "" );
126 
127  modDataObjMetaInp.dataObjInfo = dataObjInfo;
128  modDataObjMetaInp.regParam = &regParam;
129  status = rsModDataObjMeta( rsComm, &modDataObjMetaInp );
130  clearKeyVal( &regParam );
131  if ( status < 0 ) {
133  "dataObjTruncateS: rsModDataObjMeta error for %s. status = %d",
134  dataObjTruncateInp->objPath, status );
135  }
136  }
137  return status;
138 }
139 
140 int
141 l3Truncate( rsComm_t *rsComm, dataObjInp_t *dataObjTruncateInp,
142  dataObjInfo_t *dataObjInfo ) {
143  fileOpenInp_t fileTruncateInp;
144  int status;
145 
146  // =-=-=-=-=-=-=-
147  // extract the host location from the resource hierarchy
148  std::string location;
149  irods::error ret = irods::get_loc_for_hier_string( dataObjInfo->rescHier, location );
150  if ( !ret.ok() ) {
151  irods::log( PASSMSG( "l3Truncate - failed in get_loc_for_hier_string", ret ) );
152  return -1;
153  }
154 
155 
156  if ( getStructFileType( dataObjInfo->specColl ) >= 0 ) {
157  subFile_t subFile;
158  memset( &subFile, 0, sizeof( subFile ) );
159  rstrcpy( subFile.subFilePath, dataObjInfo->subPath, MAX_NAME_LEN );
160  rstrcpy( subFile.addr.hostAddr, location.c_str(), NAME_LEN );
161  subFile.specColl = dataObjInfo->specColl;
162  subFile.offset = dataObjTruncateInp->dataSize;
163  status = rsSubStructFileTruncate( rsComm, &subFile );
164  }
165  else {
166  memset( &fileTruncateInp, 0, sizeof( fileTruncateInp ) );
167  rstrcpy( fileTruncateInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN );
168  rstrcpy( fileTruncateInp.resc_hier_, dataObjInfo->rescHier, MAX_NAME_LEN );
169  rstrcpy( fileTruncateInp.addr.hostAddr, location.c_str(), NAME_LEN );
170  fileTruncateInp.dataSize = dataObjTruncateInp->dataSize;
171  status = rsFileTruncate( rsComm, &fileTruncateInp );
172  }
173  return status;
174 }
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
DataObjInp::objPath
char objPath[(1024+64)]
Definition: dataObjInpOut.h:66
NULL
#define NULL
Definition: rodsDef.h:70
rsComm_t
Definition: rcConnect.h:145
addKeyVal
int addKeyVal(keyValPair_t *condInput, const char *keyWord, const char *value)
Definition: rcMisc.cpp:789
getRemoteZoneResc.h
Subfile::offset
rodsLong_t offset
Definition: objInfo.h:321
DataObjInp::openFlags
int openFlags
Definition: dataObjInpOut.h:68
modDataObjMeta.h
_rsDataObjTruncate
int _rsDataObjTruncate(rsComm_t *rsComm, dataObjInp_t *dataObjTruncateInp, dataObjInfo_t *dataObjInfoHead)
Definition: rsDataObjTruncate.cpp:63
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
DataObjInp::specColl
specColl_t * specColl
Definition: dataObjInpOut.h:73
Subfile
Definition: objInfo.h:316
Subfile::subFilePath
char subFilePath[(1024+64)]
Definition: objInfo.h:318
DataObjInp::dataSize
rodsLong_t dataSize
Definition: dataObjInpOut.h:70
CHKSUM_KW
#define CHKSUM_KW
Definition: rodsKeyWdDef.h:25
rsFileTruncate
int rsFileTruncate(rsComm_t *rsComm, fileOpenInp_t *fileTruncateInp)
Definition: rsFileTruncate.cpp:17
REMOTE_HOST
#define REMOTE_HOST
Definition: rodsConnect.h:45
REMOTE_OPEN
#define REMOTE_OPEN
Definition: getRemoteZoneResc.h:5
rcMisc.h
BUNDLE_RESC
#define BUNDLE_RESC
Definition: phyBundleColl.h:11
getStructFileType
int getStructFileType(specColl_t *specColl)
Definition: objMetaOpr.cpp:386
DataObjInfo::rescHier
char rescHier[(1024+64)]
Definition: objInfo.h:132
rsFileTruncate.hpp
dataObjTruncate.h
irods_resource_backport.hpp
Subfile::specColl
specColl_t * specColl
Definition: objInfo.h:322
fileOpenInp_t::resc_hier_
char resc_hier_[(1024+64)]
Definition: fileOpen.h:16
PASSMSG
#define PASSMSG(message_, prev_error_)
Definition: irods_error.hpp:119
rmColl.h
rcGlobalExtern.h
DataObjInfo::filePath
char filePath[(1024+64)]
Definition: objInfo.h:137
DATA_SIZE_KW
#define DATA_SIZE_KW
Definition: rodsKeyWdDef.h:24
fileOpenInp_t::fileName
char fileName[(1024+64)]
Definition: fileOpen.h:20
DataObjInfo::next
struct DataObjInfo * next
Definition: objInfo.h:163
DataObjInfo::specColl
specColl_t * specColl
Definition: objInfo.h:158
rsDataObjTruncate
int rsDataObjTruncate(rsComm_t *rsComm, dataObjInp_t *dataObjTruncateInp)
Definition: rsDataObjTruncate.cpp:31
rsGlobalExtern.hpp
fileOpenInp_t::addr
rodsHostAddr_t addr
Definition: fileOpen.h:19
rsSubStructFileTruncate
int rsSubStructFileTruncate(rsComm_t *rsComm, subFile_t *subStructFileTruncateInp)
Definition: rsSubStructFileTruncate.cpp:12
freeAllDataObjInfo
int freeAllDataObjInfo(dataObjInfo_t *dataObjInfoHead)
Definition: rcMisc.cpp:561
getDataObjInfoIncSpecColl
int getDataObjInfoIncSpecColl(rsComm_t *rsComm, dataObjInp_t *dataObjInp, dataObjInfo_t **dataObjInfo)
Definition: dataObjOpr.cpp:1767
rsSubStructFileTruncate.hpp
dataObjTruncateS
int dataObjTruncateS(rsComm_t *rsComm, dataObjInp_t *dataObjTruncateInp, dataObjInfo_t *dataObjInfo)
Definition: rsDataObjTruncate.cpp:88
fileTruncate.h
rcDataObjTruncate
int rcDataObjTruncate(rcComm_t *conn, dataObjInp_t *dataObjInp)
Definition: rcDataObjTruncate.cpp:56
DataObjInp
Definition: dataObjInpOut.h:65
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
getErrno
int getErrno(int errCode)
Definition: rcMisc.cpp:3261
Subfile::addr
rodsHostAddr_t addr
Definition: objInfo.h:317
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
rodsLog.h
irods::log
void log(const error &)
Definition: irods_log.cpp:13
modDataObjMeta_t::regParam
keyValPair_t * regParam
Definition: modDataObjMeta.h:9
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
rsDataObjTruncate.hpp
icatDefines.h
irods::error
Definition: irods_error.hpp:23
modDataObjMeta_t::dataObjInfo
dataObjInfo_t * dataObjInfo
Definition: modDataObjMeta.h:8
l3Truncate
int l3Truncate(rsComm_t *rsComm, dataObjInp_t *dataObjTruncateInp, dataObjInfo_t *dataObjInfo)
Definition: rsDataObjTruncate.cpp:141
fileOpenInp_t
Definition: fileOpen.h:14
fileOpenInp_t::dataSize
rodsLong_t dataSize
Definition: fileOpen.h:23
rodsServerHost
Definition: rodsConnect.h:62
DataObjInfo::rescName
char rescName[64]
Definition: objInfo.h:131
rodsHostAddr_t::hostAddr
char hostAddr[256]
Definition: rodsDef.h:297
rsModDataObjMeta
int rsModDataObjMeta(rsComm_t *rsComm, modDataObjMeta_t *modDataObjMetaInp)
Definition: rsModDataObjMeta.cpp:23
getAndConnRemoteZone
int getAndConnRemoteZone(rsComm_t *rsComm, dataObjInp_t *dataObjInp, rodsServerHost_t **rodsServerHost, char *remotZoneOpr)
Definition: rodsConnect.cpp:784
rsModDataObjMeta.hpp
phyBundleColl.h
subStructFileTruncate.h
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
dataObjOpr.hpp
modDataObjMeta_t
Definition: modDataObjMeta.h:7
irods::get_loc_for_hier_string
error get_loc_for_hier_string(const std::string &_hier, std::string &_loc)
Definition: irods_resource_backport.cpp:633
NAME_LEN
#define NAME_LEN
Definition: rodsDef.h:55
KeyValPair
Definition: objInfo.h:120
clearKeyVal
int clearKeyVal(keyValPair_t *condInput)
Definition: rcMisc.cpp:1047
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
DataObjInfo
Definition: objInfo.h:129
DataObjInfo::dataSize
rodsLong_t dataSize
Definition: objInfo.h:134
unregDataObj.h
objMetaOpr.hpp
DataObjInfo::subPath
char subPath[(1024+64)]
Definition: objInfo.h:157