"Fossies" - the Fresh Open Source Software Archive

Member "irods-4.2.8/lib/core/src/bunUtil.cpp" (14 May 2020, 6990 Bytes) of package /linux/misc/irods-4.2.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "bunUtil.cpp" see the Fossies "Dox" file reference documentation.

    1 /*** Copyright (c), The BunOprents of the University of California            ***
    2  *** For more information please refer to files in the COPYRIGHT directory ***/
    3 #include "rodsPath.h"
    4 #include "rodsErrorTable.h"
    5 #include "rodsLog.h"
    6 #include "bunUtil.h"
    7 #include "miscUtil.h"
    8 #include "rcGlobalExtern.h"
    9 
   10 int
   11 bunUtil( rcComm_t *conn, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs,
   12          rodsPathInp_t *rodsPathInp ) {
   13     rodsPath_t *collPath, *structFilePath;
   14     structFileExtAndRegInp_t structFileExtAndRegInp;
   15 
   16     if ( rodsPathInp == NULL ) {
   17         return USER__NULL_INPUT_ERR;
   18     }
   19 
   20     int savedStatus = initCondForBunOpr( myRodsEnv, myRodsArgs, &structFileExtAndRegInp );
   21     if ( savedStatus < 0 ) {
   22         return savedStatus;
   23     }
   24 
   25     for ( int i = 0; i < rodsPathInp->numSrc; i++ ) {
   26         collPath = &rodsPathInp->destPath[i];   /* iRODS Collection */
   27         structFilePath = &rodsPathInp->srcPath[i];  /* iRODS StructFile */
   28 
   29         getRodsObjType( conn, collPath );
   30 
   31         rstrcpy( structFileExtAndRegInp.collection, collPath->outPath,
   32                  MAX_NAME_LEN );
   33         rstrcpy( structFileExtAndRegInp.objPath, structFilePath->outPath,
   34                  MAX_NAME_LEN );
   35 
   36         int status = 0;
   37         if ( myRodsArgs->extract == True ) {        /* -x */
   38             if ( myRodsArgs->condition == True ) {
   39                 rodsLog( LOG_ERROR, "bunUtil: cannot use -x and -c at the same time" );
   40                 return -1;
   41             }
   42             status = rcStructFileExtAndReg( conn, &structFileExtAndRegInp );
   43         }
   44         else if ( myRodsArgs->condition == True ) {  /* -c - create */
   45             status = rcStructFileBundle( conn, &structFileExtAndRegInp );
   46         }
   47         else if ( myRodsArgs->add == True ) {  /* add to tar */ // JMC - backport 4643
   48             status = rcStructFileBundle( conn, &structFileExtAndRegInp );
   49         }
   50         else {
   51             rodsLog( LOG_ERROR,
   52                      "bunUtil: -x or -c must be specified" );
   53             return -1;
   54         }
   55 
   56         /* XXXX may need to return a global status */
   57         if ( status < 0 &&
   58                 status != CAT_NO_ROWS_FOUND ) {
   59             if ( status == SYS_CACHE_STRUCT_FILE_RESC_ERR &&
   60                     myRodsArgs->condition == True ) {
   61                 rodsLogError( LOG_ERROR, status,
   62                               "bunUtil: A resc must be entered for non-existing structFile" );
   63             }
   64             else {
   65                 rodsLogError( LOG_ERROR, status,
   66                               "bunUtil: opr error for %s, status = %d",
   67                               collPath->outPath, status );
   68                 savedStatus = status;
   69             }
   70         }
   71     }
   72     return savedStatus;
   73 }
   74 
   75 int
   76 initCondForBunOpr( rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs,
   77                    structFileExtAndRegInp_t *structFileExtAndRegInp ) {
   78     if ( structFileExtAndRegInp == NULL ) {
   79         rodsLog( LOG_ERROR,
   80                  "initCondForBunOpr: NULL structFileExtAndRegInp input" );
   81         return USER__NULL_INPUT_ERR;
   82     }
   83 
   84     memset( structFileExtAndRegInp, 0, sizeof( structFileExtAndRegInp_t ) );
   85 
   86     if ( rodsArgs == NULL ) {
   87         return 0;
   88     }
   89 
   90     if ( rodsArgs->dataType == True ) {
   91         if ( rodsArgs->dataTypeString != NULL ) {
   92             if ( strcmp( rodsArgs->dataTypeString, "t" ) == 0 ||
   93                     strcmp( rodsArgs->dataTypeString, TAR_DT_STR ) == 0 || // JMC - backport 4640
   94                     strcmp( rodsArgs->dataTypeString, "tar" ) == 0 ) {
   95                 addKeyVal( &structFileExtAndRegInp->condInput, DATA_TYPE_KW,
   96                            // =-=-=-=-=-=-=-
   97                            // JMC - backport 4633
   98                            TAR_DT_STR );
   99             }
  100             else if ( strcmp( rodsArgs->dataTypeString, "g" ) == 0 ||
  101                       strcmp( rodsArgs->dataTypeString, GZIP_TAR_DT_STR ) == 0 || // JMC - backport 4640
  102                       strcmp( rodsArgs->dataTypeString, "gzip" ) == 0 ) {
  103                 addKeyVal( &structFileExtAndRegInp->condInput, DATA_TYPE_KW, GZIP_TAR_DT_STR );
  104             }
  105             else if ( strcmp( rodsArgs->dataTypeString, "b" ) == 0 ||
  106                       strcmp( rodsArgs->dataTypeString, BZIP2_TAR_DT_STR ) == 0 || // JMC - backport 4640
  107                       strcmp( rodsArgs->dataTypeString, "bzip2" ) == 0 ) { // JMC - backport 4648
  108                 addKeyVal( &structFileExtAndRegInp->condInput, DATA_TYPE_KW, BZIP2_TAR_DT_STR );
  109             }
  110             else if ( strcmp( rodsArgs->dataTypeString, "z" ) == 0 ||
  111                       strcmp( rodsArgs->dataTypeString, ZIP_DT_STR ) == 0 || // JMC - backport 4640
  112                       strcmp( rodsArgs->dataTypeString, "zip" ) == 0 ) {
  113                 addKeyVal( &structFileExtAndRegInp->condInput, DATA_TYPE_KW, ZIP_DT_STR );
  114                 // =-=-=-=-=-=-=-
  115             }
  116             else {
  117                 rodsLog( LOG_ERROR, "bunUtil: Unknown dataType %s for ibun", // JMC - backport 4648
  118                          rodsArgs->dataTypeString );
  119                 return SYS_ZIP_FORMAT_NOT_SUPPORTED;
  120             }
  121 
  122         }
  123     }
  124     else if ( rodsArgs->condition == True ) {   /* -c */
  125         addKeyVal( &structFileExtAndRegInp->condInput, DATA_TYPE_KW,
  126                    "tar file" );
  127 
  128     }
  129 
  130     if ( rodsArgs->resource == True ) {
  131         if ( rodsArgs->resourceString == NULL ) {
  132             rodsLog( LOG_ERROR,
  133                      "initCondForBunOpr: NULL resourceString error" );
  134             return USER__NULL_INPUT_ERR;
  135         }
  136         else {
  137             addKeyVal( &structFileExtAndRegInp->condInput,
  138                        DEST_RESC_NAME_KW, rodsArgs->resourceString );
  139             /* RESC_NAME_KW is need for unbundle. DEST_RESC_NAME_KW or
  140              * DEF_RESC_NAME_KW are neede for bundle */
  141             addKeyVal( &structFileExtAndRegInp->condInput, RESC_NAME_KW,
  142                        rodsArgs->resourceString );
  143         }
  144     }
  145     else if ( myRodsEnv != NULL && strlen( myRodsEnv->rodsDefResource ) > 0 ) {
  146         /* use rodsDefResource but set the DEF_RESC_NAME_KW instead.
  147          * Used by dataObjCreate. Will only make a new replica only if
  148          * DEST_RESC_NAME_KW is set */
  149         addKeyVal( &structFileExtAndRegInp->condInput, DEF_RESC_NAME_KW,
  150                    myRodsEnv->rodsDefResource );
  151     }
  152 
  153     if ( rodsArgs->force == True ) {
  154         addKeyVal( &structFileExtAndRegInp->condInput, FORCE_FLAG_KW, "" );
  155     }
  156 
  157     if ( rodsArgs->condition == True ) {  /* -c - create */ // JMC - backport 4644
  158         structFileExtAndRegInp->oprType = PRESERVE_COLL_PATH;
  159     }
  160 
  161     if ( rodsArgs->add == True ) {  /* add to tar */ // JMC - backport 4643
  162         structFileExtAndRegInp->oprType = ADD_TO_TAR_OPR | PRESERVE_COLL_PATH; // JMC - backport 4644
  163         addKeyVal( &structFileExtAndRegInp->condInput, FORCE_FLAG_KW, "" );
  164     }
  165 
  166     if ( rodsArgs->bulk == True ) {
  167         addKeyVal( &structFileExtAndRegInp->condInput, BULK_OPR_KW, "" );
  168     }
  169 
  170     return 0;
  171 }
  172