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)  

rsFileRmdir.cpp
Go to the documentation of this file.
1 
3 /* This is script-generated code (for the most part). */
4 /* See fileRmdir.h for a description of this API call.*/
5 
6 #include "fileRmdir.h"
7 #include "fileOpendir.h"
8 #include "fileReaddir.h"
9 #include "fileClosedir.h"
10 #include "miscServerFunct.hpp"
11 #include "fileDriver.hpp"
12 #include "rsFileRmdir.hpp"
13 
14 // =-=-=-=-=-=-=-
15 #include "irods_log.hpp"
17 
18 #define CACHE_DIR_STR "cacheDir" // FIXME JMC - need a better place for this. also used in tar plugin
19 
20 int
21 rsFileRmdir( rsComm_t *rsComm, fileRmdirInp_t *fileRmdirInp ) {
23  int remoteFlag;
24  int status;
25 
26  remoteFlag = resolveHost( &fileRmdirInp->addr, &rodsServerHost );
27  if ( remoteFlag == LOCAL_HOST ) {
28  status = _rsFileRmdir( rsComm, fileRmdirInp );
29  }
30  else if ( remoteFlag == REMOTE_HOST ) {
31  status = remoteFileRmdir( rsComm, fileRmdirInp, rodsServerHost );
32  }
33  else {
34  if ( remoteFlag < 0 ) {
35  return remoteFlag;
36  }
37  else {
39  "rsFileRmdir: resolveHost returned unrecognized value %d",
40  remoteFlag );
42  }
43  }
44 
45  /* Manually insert call-specific code here */
46 
47  return status;
48 }
49 
50 int
51 remoteFileRmdir( rsComm_t *rsComm, fileRmdirInp_t *fileRmdirInp,
53  int status;
54 
55  if ( rodsServerHost == NULL ) {
57  "remoteFileRmdir: Invalid rodsServerHost" );
59  }
60 
61  if ( ( status = svrToSvrConnect( rsComm, rodsServerHost ) ) < 0 ) {
62  return status;
63  }
64 
65 
66  status = rcFileRmdir( rodsServerHost->conn, fileRmdirInp );
67 
68  if ( status < 0 ) {
70  "remoteFileOpen: rcFileRmdir failed for %s",
71  fileRmdirInp->dirName );
72  }
73 
74  return status;
75 }
76 
77 // =-=-=-=-=-=-=-
78 // local function which handles removing directories via the resource plugin
80  rsComm_t* _comm,
81  fileRmdirInp_t* _rmdir_inp ) {
82 
85  _rmdir_inp->dirName,
86  _rmdir_inp->rescHier,
87  0, 0 ) );
88 
89  if ( ( _rmdir_inp->flags & RMDIR_RECUR ) != 0 ) {
90  // FIXME :: revisit this after moving to First class Objects
91  // recursive. This is a very dangerous operation. curently
92  // it is only used to remove cache directory of structured
93  // files
94  struct rodsDirent* myFileDirent = 0;
95 
96  // if it is not a cache dir, return an error as we only do this
97  // for cache dirs at the moment.
98  if ( strstr( _rmdir_inp->dirName, CACHE_DIR_STR ) == NULL ) {
99  rodsLog( LOG_ERROR, "_rsFileRmdir: recursive rm of non cachedir path %s",
100  _rmdir_inp->dirName );
101  return SYS_INVALID_FILE_PATH;
102  }
103 
104  // call opendir via resource plugin
105  irods::error opendir_err = fileOpendir( _comm, coll_obj );
106 
107  // log an error, if any
108  if ( !opendir_err.ok() ) {
109  std::stringstream msg;
110  msg << "fileOpendir failed for [";
111  msg << _rmdir_inp->dirName;
112  msg << "]";
113  irods::error err = PASSMSG( msg.str(), opendir_err );
114  irods::log( err );
115  return opendir_err.code();
116  }
117 
118  // read the directory via resource plugin and either handle files or recurse into another directory
119  irods::error readdir_err = fileReaddir( _comm, coll_obj, &myFileDirent );
120  while ( readdir_err.ok() && 0 == readdir_err.code() ) {
121  struct stat statbuf;
122  char myPath[MAX_NAME_LEN];
123 
124  // handle relative paths
125  if ( strcmp( myFileDirent->d_name, "." ) == 0 ||
126  strcmp( myFileDirent->d_name, ".." ) == 0 ) {
127  readdir_err = fileReaddir( _comm, coll_obj, &myFileDirent );
128  continue;
129  }
130 
131  // cache path name
132  snprintf( myPath, MAX_NAME_LEN, "%s/%s", &_rmdir_inp->dirName[0], &myFileDirent->d_name[0] );
133 
134  // =-=-=-=-=-=-=-
135  // call stat via resource plugin, handle errors
136  irods::collection_object_ptr myPath_obj(
138  myPath,
139  _rmdir_inp->rescHier,
140  0, 0 ) );
141  irods::error stat_err = fileStat( _comm, myPath_obj, &statbuf );
142  if ( !stat_err.ok() ) {
143  std::stringstream msg;
144  msg << "fileStat failed for [";
145  msg << myPath;
146  msg << "]";
147  irods::error log_err = PASSMSG( msg.str(), stat_err );
148  irods::log( log_err );
149 
150  // call closedir via resource plugin, handle errors
151  irods::error closedir_err = fileClosedir( _comm, myPath_obj );
152  if ( !closedir_err.ok() ) {
153  std::stringstream msg;
154  msg << "fileClosedir for [";
155  msg << myPath;
156  msg << "]";
157  irods::error log_err = PASSMSG( msg.str(), closedir_err );
158  irods::log( log_err );
159  }
160 
161  return stat_err.code();
162 
163  } // if !stat_err.ok()
164 
165  // filter based on stat results: file, dir, or error
166  int status = 0;
167  if ( ( statbuf.st_mode & S_IFREG ) != 0 ) {
168  // handle case where file is found
169  irods::error unlink_err = fileUnlink( _comm, myPath_obj );
170  status = unlink_err.code();
171  if ( !unlink_err.ok() ) {
172  irods::error log_err = PASSMSG( "error during unlink.", unlink_err );
173  irods::log( log_err );
174  }
175  }
176  else if ( ( statbuf.st_mode & S_IFDIR ) != 0 ) {
177  // handle case where directory is found
178  fileRmdirInp_t myRmdirInp;
179  memset( &myRmdirInp, 0, sizeof( myRmdirInp ) );
180 
181  myRmdirInp.flags = _rmdir_inp->flags;
182  rstrcpy( myRmdirInp.dirName, myPath, MAX_NAME_LEN );
183  rstrcpy( myRmdirInp.rescHier, _rmdir_inp->rescHier, MAX_NAME_LEN );
184 
185  // RECURSE - call _rsFileRmdir on this new found directory
186  status = _rsFileRmdir( _comm, &myRmdirInp );
187 
188  }
189  else {
191  rodsLog( LOG_NOTICE, "_rsFileRmdir: for %s, status = %d", myPath, status );
192  }
193 
194  // handle error condition on the above three cases
195  if ( status < 0 ) {
196  rodsLog( LOG_NOTICE, "_rsFileRmdir: rm of %s failed, status = %d", myPath, status );
197 
198  // call closedir via resource plugin, handle errors
199  irods::error closedir_err = fileClosedir( _comm, myPath_obj );
200  if ( !closedir_err.ok() ) {
201  std::stringstream msg;
202  msg << "fileClosedir failed for [";
203  msg << myPath;
204  msg << "]";
205  irods::error log_err = PASSMSG( msg.str(), closedir_err );
206  irods::log( log_err );
207  }
208 
209  return status;
210 
211  } // if status < 0
212 
213  // =-=-=-=-=-=-=-
214  // continue readdir via resource plugin
215  readdir_err = fileReaddir( _comm, coll_obj, &myFileDirent );
216 
217  } // while
218 
219  // =-=-=-=-=-=-=-
220  // call closedir via resource plugin, handle errors
221  irods::error closedir_err = fileClosedir( _comm, coll_obj );
222  if ( !closedir_err.ok() ) {
223  std::stringstream msg;
224  msg << "fileClosedir failed for [";
225  msg << _rmdir_inp->dirName;
226  msg << "]";
227  irods::error log_err = PASSMSG( msg.str(), closedir_err );
228  irods::log( log_err );
229  }
230 
231  } // if RMDIR_RECUR ( recursive delete )
232 
233  // =-=-=-=-=-=-=-
234  // make the call to rmdir via the resource plugin
235  irods::error rmdir_err = fileRmdir( _comm, coll_obj );
236  if ( !rmdir_err.ok() ) {
237  std::stringstream msg;
238  msg << "fileRmdir failed for [";
239  msg << _rmdir_inp->dirName;
240  msg << "]";
241  irods::error err = PASSMSG( msg.str(), rmdir_err );
242  irods::log( err );
243  }
244 
245  return rmdir_err.code();
246 
247 } // _rsFileRmdir
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
NULL
#define NULL
Definition: rodsDef.h:70
fileRmdir.h
rsComm_t
Definition: rcConnect.h:145
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
fileRmdirInp_t::addr
rodsHostAddr_t addr
Definition: fileRmdir.h:12
SYS_UNRECOGNIZED_REMOTE_FLAG
@ SYS_UNRECOGNIZED_REMOTE_FLAG
Definition: rodsErrorTable.h:88
fileUnlink
irods::error fileUnlink(rsComm_t *, irods::first_class_object_ptr)
Definition: fileDriver.cpp:177
rodsDirent::d_name
char d_name[256]
Definition: rodsType.h:75
fileReaddir.h
irods_collection_object.hpp
_rsFileRmdir
int _rsFileRmdir(rsComm_t *_comm, fileRmdirInp_t *_rmdir_inp)
Definition: rsFileRmdir.cpp:79
rcFileRmdir
int rcFileRmdir(rcComm_t *conn, fileRmdirInp_t *fileRmdirInp)
Definition: rcFileRmdir.cpp:23
REMOTE_HOST
#define REMOTE_HOST
Definition: rodsConnect.h:45
irods::collection_object_ptr
boost::shared_ptr< collection_object > collection_object_ptr
Definition: irods_collection_object.hpp:85
LOCAL_HOST
#define LOCAL_HOST
Definition: rodsConnect.h:44
PASSMSG
#define PASSMSG(message_, prev_error_)
Definition: irods_error.hpp:119
fileRmdirInp_t::rescHier
char rescHier[(1024+64)]
Definition: fileRmdir.h:14
fileDriver.hpp
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
fileClosedir.h
rsFileRmdir
int rsFileRmdir(rsComm_t *rsComm, fileRmdirInp_t *fileRmdirInp)
Definition: rsFileRmdir.cpp:21
irods::error::code
long long code() const
Definition: irods_error.cpp:194
fileOpendir
irods::error fileOpendir(rsComm_t *, irods::first_class_object_ptr)
Definition: fileDriver.cpp:362
fileRmdirInp_t::dirName
char dirName[(1024+64)]
Definition: fileRmdir.h:13
RMDIR_RECUR
#define RMDIR_RECUR
Definition: fileRmdir.h:8
fileOpendir.h
fileRmdirInp_t::flags
int flags
Definition: fileRmdir.h:11
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
fileRmdir
irods::error fileRmdir(rsComm_t *, irods::first_class_object_ptr)
Definition: fileDriver.cpp:332
SYS_INVALID_SERVER_HOST
@ SYS_INVALID_SERVER_HOST
Definition: rodsErrorTable.h:89
svrToSvrConnect
int svrToSvrConnect(rsComm_t *rsComm, rodsServerHost_t *rodsServerHost)
Definition: miscServerFunct.cpp:106
irods::collection_object
Definition: irods_collection_object.hpp:14
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
irods::log
void log(const error &)
Definition: irods_log.cpp:13
rodsDirent
Definition: rodsType.h:70
fileRmdirInp_t
Definition: fileRmdir.h:10
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
remoteFileRmdir
int remoteFileRmdir(rsComm_t *rsComm, fileRmdirInp_t *fileRmdirInp, rodsServerHost_t *rodsServerHost)
Definition: rsFileRmdir.cpp:51
irods::error
Definition: irods_error.hpp:23
miscServerFunct.hpp
SYS_INVALID_FILE_PATH
@ SYS_INVALID_FILE_PATH
Definition: rodsErrorTable.h:99
fileStat
irods::error fileStat(rsComm_t *, irods::first_class_object_ptr, struct stat *)
Definition: fileDriver.cpp:207
fileClosedir
irods::error fileClosedir(rsComm_t *, irods::first_class_object_ptr)
Definition: fileDriver.cpp:392
CACHE_DIR_STR
#define CACHE_DIR_STR
Definition: rsFileRmdir.cpp:18
rodsServerHost
Definition: rodsConnect.h:62
rsFileRmdir.hpp
fileReaddir
irods::error fileReaddir(rsComm_t *, irods::first_class_object_ptr, struct rodsDirent **)
Definition: fileDriver.cpp:422
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
irods_log.hpp
resolveHost
int resolveHost(rodsHostAddr_t *addr, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:375