28 #include <boost/function.hpp>
29 #include <boost/any.hpp>
30 #include <boost/filesystem/operations.hpp>
31 #include <boost/filesystem/path.hpp>
38 #include <sys/types.h>
40 #include <openssl/md5.h>
41 #if defined(osx_platform)
42 #include <sys/malloc.h>
48 #include <sys/param.h>
53 #if defined(solaris_platform)
54 #include <sys/statvfs.h>
56 #if defined(linux_platform)
72 const std::string& _phy_path,
73 std::string& _ret_string ) {
76 std::string vault_path;
80 if ( ( result =
ASSERT_PASS( ret,
"Resource has no vault path." ) ).ok() ) {
82 if ( _phy_path.compare( 0, 1,
"/" ) != 0 &&
83 _phy_path.compare( 0, vault_path.size(), vault_path ) != 0 ) {
84 _ret_string = vault_path;
86 _ret_string += _phy_path;
90 _ret_string = _phy_path;
108 std::string full_path;
110 data_obj->physical_path(),
112 if ( ( result =
ASSERT_PASS( ret,
"Failed generating full path for object." ) ).ok() ) {
114 data_obj->physical_path( full_path );
120 catch (
const std::bad_cast& ) {
129 template<
typename DEST_TYPE >
138 ret = _ctx.
valid< DEST_TYPE >();
139 if ( ( result =
ASSERT_PASS( ret,
"Resource context is invalid." ) ).ok() ) {
151 const std::string& path,
157 while ( !done && result.
ok() ) {
158 pos = path.find_first_of(
'/', pos + 1 );
160 subdir = path.substr( 0, pos );
166 subdir.c_str(), strerror( errno ),
status );
168 if ( pos == std::string::npos ) {
180 const std::string& _path,
181 std::string& _hashed ) {
190 strncpy( md5Buf, _path.c_str(), _path.size() );
191 MD5_Init( &context );
192 MD5_Update( &context, (
unsigned char* )md5Buf, _path.size() );
193 MD5_Final( (
unsigned char* )hash, &context );
195 std::stringstream ins;
196 for (
int i = 0; i < 16; ++i ) {
197 ins << std::setfill(
'0' ) << std::setw( 2 ) << std::hex << (
int )hash[i];
204 if ( ( result =
ASSERT_PASS( ret,
"Failed to get vault path for resource." ) ).ok() ) {
240 if ( ( result =
ASSERT_PASS( ret,
"resource context is invalid." ) ).ok() ) {
248 mode_t myMask = umask( ( mode_t ) 0000 );
249 int status = mkdir( fco->physical_path().c_str(), fco->mode() );
253 umask( ( mode_t ) myMask );
259 if ( ( result =
ASSERT_ERROR(
status >= 0, err_status,
"mkdir error for [%s], errno = [%s], status = %d.",
260 fco->physical_path().c_str(), strerror( errno ), err_status ) ).ok() ) {
270 struct stat* _statbuf ) {
275 _statbuf->st_mode = S_IFREG;
276 _statbuf->st_nlink = 1;
277 _statbuf->st_uid = getuid();
278 _statbuf->st_gid = getgid();
279 _statbuf->st_atime = _statbuf->st_mtime = _statbuf->st_ctime = time( 0 );
289 const char* _new_file_name ) {
293 irods::error ret = unix_check_params_and_path< irods::data_object >( _ctx );
294 if ( ( result =
ASSERT_PASS( ret,
"Invalid parameters or physical path." ) ).ok() ) {
298 std::string new_full_path;
300 if ( ( result =
ASSERT_PASS( ret,
"Unable to generate full path for destination file: \"%s\".",
301 _new_file_name ) ).ok() ) {
308 std::string new_hash;
313 if ( ( result =
ASSERT_PASS( ret,
"Failed to gen hashed path" ) ).ok() ) {
316 int status =
rename( fco->physical_path().c_str(), new_hash.c_str() );
321 if ( ( result =
ASSERT_ERROR(
status >= 0, err_status,
"Rename error for \"%s\" to \"%s\", errno = \"%s\", status = %d.",
322 fco->physical_path().c_str(), new_hash.c_str(), strerror( errno ), err_status ) ).ok() ) {
323 fco->physical_path( new_hash );
341 irods::error ret = unix_check_params_and_path< irods::file_object >( _ctx );
342 if ( ( result =
ASSERT_PASS( ret,
"Invalid plugin context." ) ).ok() ) {
350 int status = truncate( fco->physical_path().c_str(), fco->size() );
355 result =
ASSERT_ERROR(
status >= 0, err_status,
"Truncate error for: \"%s\", errno = \"%s\", status = %d.",
356 fco->physical_path().c_str(), strerror( errno ), err_status );
370 irods::error ret = unix_check_params_and_path< irods::file_object >( _ctx );
371 if ( ( result =
ASSERT_PASS( ret,
"Invalid plugin context." ) ).ok() ) {
379 int status = unlink( fco->physical_path().c_str() );
384 result =
ASSERT_ERROR(
status >= 0, err_status,
"Unlink error for: \"%s\", errno = \"%s\", status = %d.",
385 fco->physical_path().c_str(), strerror( errno ), err_status );
395 const char* srcFileName,
396 const char* destFileName ) {
398 size_t trans_buff_size;
407 std::vector<char> myBuf( trans_buff_size );
415 inFd = open( srcFileName, O_RDONLY, 0 );
416 status = stat( srcFileName, &statbuf );
420 "mockArchiveCopyPlugin: open error for srcFileName %s, status = %d",
427 "mockArchiveCopyPlugin: stat of %s error, status = %d",
432 else if ( ( statbuf.st_mode & S_IFREG ) == 0 ) {
434 "mockArchiveCopyPlugin: open error for srcFileName %s, status = %d",
440 outFd = open( destFileName, O_WRONLY | O_CREAT | O_TRUNC,
mode );
444 "mockArchiveCopyPlugin: open error for destFileName %s, status = %d",
450 while ( ( bytesRead = read( inFd, (
void * ) myBuf.data(), trans_buff_size ) ) > 0 ) {
451 bytesWritten = write( outFd, (
void * ) myBuf.data(), bytesRead );
452 if ( bytesWritten <= 0 ) {
455 "mockArchiveCopyPlugin: write error for srcFileName %s, status = %d",
461 bytesCopied += bytesWritten;
467 if ( bytesCopied != statbuf.st_size ) {
469 "mockArchiveCopyPlugin: Copied size %lld does not match source \
471 bytesCopied, statbuf.st_size, srcFileName );
486 const char* _cache_file_name ) {
491 irods::error ret = unix_check_params_and_path< irods::file_object >( _ctx );
492 if ( ( result =
ASSERT_PASS( ret,
"Invalid plugin context." ) ).ok() ) {
502 if ( ( result =
ASSERT_PASS( ret,
"Failed to retrieve vault path for resource." ) ).ok() ) {
507 path += fco->physical_path().c_str();
511 fco->physical_path().c_str(), _cache_file_name );
524 const char* _cache_file_name ) {
529 irods::error ret = unix_check_params_and_path< irods::file_object >( _ctx );
530 if ( ( result =
ASSERT_PASS( ret,
"Invalid plugin context." ) ).ok() ) {
540 fco->physical_path(),
542 if ( ( result =
ASSERT_PASS( ret,
"Failed to gen hashed path" ) ).ok() ) {
548 fco->physical_path().c_str(), path.c_str() );
552 std::string new_path = path;
553 std::size_t last_slash = new_path.find_last_of(
'/' );
554 new_path.erase( last_slash );
556 if ( ( result =
ASSERT_PASS( ret,
"Mkdir error for \"%s\".", new_path.c_str() ) ).ok() ) {
563 fco->physical_path( path );
581 const std::string& _resc_name,
582 const std::string& _curr_host,
594 if ( ( result =
ASSERT_PASS( get_ret,
"Failed to get \"status\" property." ) ).ok() ) {
602 std::string host_name;
604 if ( ( result =
ASSERT_PASS( get_ret,
"Failed to get \"location\" property." ) ).ok() ) {
608 bool curr_host = ( _curr_host == host_name );
612 bool need_repl = ( _file_obj->repl_requested() > -1 );
617 std::vector< irods::physical_object > objs = _file_obj->replicas();
618 std::vector< irods::physical_object >::iterator itr = objs.begin();
622 for ( ; !found && itr != objs.end(); ++itr ) {
627 std::string last_resc;
629 parser.set_string( itr->resc_hier() );
630 parser.last_resc( last_resc );
634 bool repl_us = ( _file_obj->repl_requested() == itr->repl_num() );
635 bool resc_us = ( _resc_name == last_resc );
641 if ( !need_repl || ( need_repl && repl_us ) ) {
667 const std::string* _opr,
668 const std::string* _curr_host,
676 if ( ( result =
ASSERT_PASS( ret,
"Invalid plugin context." ) ).ok() ) {
679 "Invalid input parameters." ) ).ok() ) {
687 std::string resc_name;
689 if ( ( result =
ASSERT_PASS( ret,
"Failed to get property for resource name." ) ).ok() ) {
755 rodsLog(
LOG_NOTICE,
"mockarchive_resource::post_disconnect_maintenance_operation - [%s]",
767 const std::string& _context ) :
782 return ERROR( -1,
"nop" );
805 using namespace irods;
815 function<error(plugin_context&, const char*)>(
820 function<error(plugin_context&, const char*)>(
830 function<error(plugin_context&, const char*)>(
835 function<error(plugin_context&, struct stat*)>(
845 function<error(plugin_context&,const std::string*, const std::string*, irods::hierarchy_parser*, float*)>(