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)  

fsckUtil.cpp
Go to the documentation of this file.
1 
3 /* Written by Jean-Yves Nief of CCIN2P3 and copyright assigned to Data Intensive Cyberinfrastructure Foundation */
4 
5 #include "rodsPath.h"
6 #include "rodsErrorTable.h"
7 #include "rodsLog.h"
8 #include "fsckUtil.h"
9 #include "miscUtil.h"
10 #include "scanUtil.h"
11 #include "checksum.hpp"
12 #include "rcGlobalExtern.h"
13 
14 #include <boost/filesystem/operations.hpp>
15 #include <boost/filesystem/convenience.hpp>
16 
17 #include <iostream>
18 #include <string>
19 
20 using namespace boost::filesystem;
21 
22 int
24  rodsArguments_t *myRodsArgs,
25  rodsPathInp_t *rodsPathInp,
26  SetGenQueryInpFromPhysicalPath strategy, const char* argument_for_SetGenQueryInpFromPhysicalPath) {
27 
28  if ( rodsPathInp->numSrc != 1 ) {
29  rodsLog( LOG_ERROR, "fsckObj: gave %i input source path, "
30  "should give one and only one", rodsPathInp->numSrc );
31  return USER_INPUT_PATH_ERR;
32  }
33 
34  char * inpPathO = rodsPathInp->srcPath[0].outPath;
35  path p( inpPathO );
36  if ( !exists( p ) ) {
37  rodsLog( LOG_ERROR, "fsckObj: %s does not exist", inpPathO );
38  return USER_INPUT_PATH_ERR;
39  }
40 
41  if ( is_symlink( p ) ) {
42  return 0;
43  }
44 
45  int lenInpPath = strlen( inpPathO );
46  if ( lenInpPath > 0 && '/' == inpPathO[ lenInpPath - 1 ] ) {
47  lenInpPath--;
48  }
49  if ( lenInpPath >= MAX_PATH_ALLOWED ) {
50  rodsLog( LOG_ERROR, "Path %s is longer than %ju characters in fsckObj",
51  inpPathO, ( intmax_t ) MAX_PATH_ALLOWED );
52  return USER_STRLEN_TOOLONG;
53  }
54 
55  char inpPath[ MAX_PATH_ALLOWED ];
56  strncpy( inpPath, inpPathO, lenInpPath );
57  inpPath[ lenInpPath ] = '\0';
58  // if it is part of a mounted collection, abort
59  if ( is_directory( p ) ) {
60  if ( int status = checkIsMount( conn, inpPath ) ) {
61  rodsLog( LOG_ERROR, "The directory %s or one of its "
62  "subdirectories to be checked is declared as being "
63  "used for a mounted collection: abort!", inpPath );
64  return status;
65  }
66  }
67  return fsckObjDir( conn, myRodsArgs, inpPath, strategy, argument_for_SetGenQueryInpFromPhysicalPath );
68 }
69 
70 int
71 fsckObjDir( rcComm_t *conn, rodsArguments_t *myRodsArgs, char *inpPath, SetGenQueryInpFromPhysicalPath strategy, const char* argument_for_SetGenQueryInpFromPhysicalPath) {
72  int status = 0;
73  char fullPath[MAX_PATH_ALLOWED] = "\0";
74 
75  path srcDirPath( inpPath );
76  if ( is_symlink( srcDirPath ) ) {
77  return 0;
78  } else if ( is_directory( srcDirPath ) ) {
79  } else {
80  status = chkObjConsistency( conn, myRodsArgs, inpPath, strategy, argument_for_SetGenQueryInpFromPhysicalPath );
81  return status;
82  }
83  directory_iterator end_itr; // default construction yields past-the-end
84  for ( directory_iterator itr( srcDirPath ); itr != end_itr; ++itr ) {
85  path cp = itr->path();
86  snprintf( fullPath, MAX_PATH_ALLOWED, "%s",
87  cp.c_str() );
88  if ( is_symlink( cp ) ) {
89  /* don't do anything if it is symlink */
90  continue;
91  }
92  else if ( is_directory( cp ) ) {
93  if ( myRodsArgs->recursive == True ) {
94  const int tmp_status = fsckObjDir( conn, myRodsArgs, fullPath, strategy, argument_for_SetGenQueryInpFromPhysicalPath );
95  if (status == 0) {
96  status = tmp_status;
97  }
98  }
99  }
100  else {
101  const int tmp_status = chkObjConsistency( conn, myRodsArgs, fullPath, strategy, argument_for_SetGenQueryInpFromPhysicalPath );
102  if (status == 0) {
103  status = tmp_status;
104  }
105  }
106  }
107  return status;
108 
109 }
110 
111 int
112 chkObjConsistency( rcComm_t *conn, rodsArguments_t *myRodsArgs, char *inpPath, SetGenQueryInpFromPhysicalPath strategy, const char* argument_for_SetGenQueryInpFromPhysicalPath ) {
113  const path p(inpPath);
114  if ( is_symlink( p ) ) {
115  return 0;
116  }
117  const intmax_t srcSize = file_size(p);
118  genQueryInp_t genQueryInp;
119  strategy(&genQueryInp, inpPath, argument_for_SetGenQueryInpFromPhysicalPath);
120 
121  genQueryOut_t *genQueryOut = NULL;
122  int status = rcGenQuery( conn, &genQueryInp, &genQueryOut );
123 
124  if ( status == 0 && NULL != genQueryOut ) {
125  const char *objName = genQueryOut->sqlResult[0].value;
126  const char *objPath = genQueryOut->sqlResult[1].value;
127 
128  intmax_t objSize = 0;
129 
130  try {
131  objSize = std::stoll(genQueryOut->sqlResult[2].value);
132  }
133  catch (const std::invalid_argument& e) {
134  std::cerr << "ERROR: could not parse object size into integer [exception => " << e.what() << ", path => " << inpPath << "].\n";
135  return SYS_INTERNAL_ERR;
136  }
137  catch (const std::out_of_range& e) {
138  std::cerr << "ERROR: could not parse object size into integer [exception => " << e.what() << ", path => " << inpPath << "].\n";
139  return SYS_INTERNAL_ERR;
140  }
141 
142  const char *objChksum = genQueryOut->sqlResult[3].value;
143  if ( srcSize == objSize ) {
144  if ( myRodsArgs->verifyChecksum == True ) {
145  if ( strcmp( objChksum, "" ) != 0 ) {
146  status = verifyChksumLocFile( inpPath, objChksum, NULL );
147  if ( status == USER_CHKSUM_MISMATCH ) {
148  printf( "CORRUPTION: local file [%s] checksum not consistent with iRODS object [%s/%s] checksum.\n", inpPath, objPath, objName );
149  } else if (status != 0) {
150  printf("ERROR chkObjConsistency: verifyChksumLocFile failed: status [%d] file [%s] objPath [%s] objName [%s] objChksum [%s]\n", status, inpPath, objPath, objName, objChksum);
151  }
152  } else {
153  printf( "WARNING: checksum not available for iRODS object [%s/%s], no checksum comparison possible with local file [%s] .\n", objPath, objName, inpPath );
154  }
155  }
156  } else {
157  printf( "CORRUPTION: local file [%s] size [%ji] not consistent with iRODS object [%s/%s] size [%ji].\n", inpPath, srcSize, objPath, objName, objSize );
159  }
160  } else {
161  printf("ERROR chkObjConsistency: rcGenQuery failed: status [%d] genQueryOut [%p] file [%s]\n", status, genQueryOut, inpPath);
162  }
163 
164  clearGenQueryInp( &genQueryInp );
165  freeGenQueryOut( &genQueryOut );
166 
167  return status;
168 
169 }
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
rcComm_t
Definition: rcConnect.h:95
NULL
#define NULL
Definition: rodsDef.h:70
True
#define True
Definition: parseCommandLine.h:11
rodsPath.h
fsckObjDir
int fsckObjDir(rcComm_t *conn, rodsArguments_t *myRodsArgs, char *inpPath, SetGenQueryInpFromPhysicalPath strategy, const char *argument_for_SetGenQueryInpFromPhysicalPath)
Definition: fsckUtil.cpp:71
rodsArguments_t
Definition: parseCommandLine.h:14
checkIsMount
int checkIsMount(rcComm_t *conn, const char *inpPath)
Definition: scanUtil.cpp:290
RodsPathInp
Definition: rodsPath.h:33
GenQueryInp
Definition: rodsGenQuery.h:24
irods::experimental::administration::client::v1::exists
auto exists(rcComm_t &conn, const user &user) -> bool
Definition: user_administration.cpp:359
pid_age.p
p
Definition: pid_age.py:13
checksum.hpp
rcGlobalExtern.h
RodsPathInp::srcPath
rodsPath_t * srcPath
Definition: rodsPath.h:35
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
GenQueryOut::sqlResult
sqlResult_t sqlResult[50]
Definition: rodsGenQuery.h:72
SYS_INTERNAL_ERR
@ SYS_INTERNAL_ERR
Definition: rodsErrorTable.h:211
fsckUtil.h
verifyChksumLocFile
int verifyChksumLocFile(char *fileName, const char *myChksum, char *chksumStr)
Definition: checksum.cpp:178
rodsArguments_t::verifyChecksum
int verifyChecksum
Definition: parseCommandLine.h:53
MAX_PATH_ALLOWED
#define MAX_PATH_ALLOWED
Definition: rodsDef.h:58
rcGenQuery
int rcGenQuery(rcComm_t *conn, genQueryInp_t *genQueryInp, genQueryOut_t **genQueryOut)
Definition: rcGenQuery.cpp:89
terminate_irods_processes.e
e
Definition: terminate_irods_processes.py:19
GenQueryOut
Definition: rodsGenQuery.h:67
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
rodsLog.h
scanUtil.h
SetGenQueryInpFromPhysicalPath
int(* SetGenQueryInpFromPhysicalPath)(genQueryInp_t *out, const char *physical_path, const char *generic_function_argument)
Definition: fsckUtil.h:16
RodsPath::outPath
char outPath[(1024+64)]
Definition: rodsPath.h:24
SqlResult::value
char * value
Definition: rodsGenQuery.h:64
rodsArguments_t::recursive
int recursive
Definition: parseCommandLine.h:85
USER_STRLEN_TOOLONG
@ USER_STRLEN_TOOLONG
Definition: rodsErrorTable.h:237
RodsPathInp::numSrc
int numSrc
Definition: rodsPath.h:34
chkObjConsistency
int chkObjConsistency(rcComm_t *conn, rodsArguments_t *myRodsArgs, char *inpPath, SetGenQueryInpFromPhysicalPath strategy, const char *argument_for_SetGenQueryInpFromPhysicalPath)
Definition: fsckUtil.cpp:112
fsckObj
int fsckObj(rcComm_t *conn, rodsArguments_t *myRodsArgs, rodsPathInp_t *rodsPathInp, SetGenQueryInpFromPhysicalPath strategy, const char *argument_for_SetGenQueryInpFromPhysicalPath)
Definition: fsckUtil.cpp:23
rodsErrorTable.h
miscUtil.h
freeGenQueryOut
int freeGenQueryOut(genQueryOut_t **genQueryOut)
Definition: rcMisc.cpp:1133
USER_INPUT_PATH_ERR
@ USER_INPUT_PATH_ERR
Definition: rodsErrorTable.h:248
clearGenQueryInp
void clearGenQueryInp(void *voidInp)
Definition: rcMisc.cpp:1118
USER_CHKSUM_MISMATCH
@ USER_CHKSUM_MISMATCH
Definition: rodsErrorTable.h:245