IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 30, 2007, 1:43:49 PM (18 years ago)
Author:
Paul Price
Message:

There were some problems on a Mac (case insensitive HFS) where a
directory named "register" was attempting to be read for the
"REGISTER" metadata substitution. Added an additional flag,
"-recipe-file" to read a recipe from a file. This avoids the
problem completely.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/config/pmConfigRecipes.c

    r15513 r15727  
    66#include <string.h>
    77#include <strings.h>            /* for strn?casecmp */
    8 #include <unistd.h>
    9 #include <libgen.h>
    108#include <assert.h>
    11 #include <sys/types.h>
    12 #include <sys/stat.h>
    13 #include <glob.h>
    149#include <pslib.h>
    1510#include "pmConfig.h"
     
    227222
    228223    // Go through the command-line arguments
    229     int argNum; // Argument number for "-recipe"
     224    int argNum;                         // Argument number
     225
     226    // -recipe-file: read recipe from file
     227    while ((argNum = psArgumentGet(*argc, argv, "-recipe-file")) > 0) {
     228        psArgumentRemove(argNum, argc, argv);
     229        if (argNum + 1 >= *argc) {
     230            psError(PS_ERR_IO, false,
     231                    "-recipe command-line switch provided without the required recipe and filename\n");
     232            return false;
     233        }
     234
     235        psString recipeName = psStringCopy(argv[argNum]); // Name of the recipe
     236        psArgumentRemove(argNum, argc, argv);
     237        psString filename = psStringCopy(argv[argNum]); // Filename for the recipe
     238        psArgumentRemove(argNum, argc, argv);
     239
     240        psMetadata *recipe = NULL;      // Recipe from file
     241        if (!pmConfigFileRead(&recipe, filename, "recipe")) {
     242            psError(PS_ERR_IO, "Error reading config file %s\n", filename);
     243            psFree(recipeName);
     244            psFree(filename);
     245            return false;
     246        }
     247
     248        psString comment = NULL;
     249        psStringAppend(&comment, "Recipe added at command line from file %s", filename);
     250        psMetadataAdd(recipes, PS_LIST_TAIL, recipeName, PS_DATA_METADATA | PS_META_REPLACE,
     251                      comment, recipe);
     252        psFree(comment);
     253        psFree(recipe);                 // Drop reference
     254        psFree(recipeName);
     255        psFree(filename);
     256    }
     257
     258    // -recipe: read recipe from symbolic link
    230259    while ((argNum = psArgumentGet(*argc, argv, "-recipe")) > 0) {
    231260        psArgumentRemove(argNum, argc, argv);
    232261        if (argNum + 1 >= *argc) {
    233             psError(PS_ERR_IO, false, "-recipe command-line switch provided without the required recipe and source\n");
     262            psError(PS_ERR_IO, false,
     263                    "-recipe command-line switch provided without the required recipe and source\n");
    234264            return false;
    235265        }
     
    240270        psArgumentRemove(argNum, argc, argv);
    241271
    242         if (access(recipeSource, R_OK) == 0) {
    243             // The source is a file: load onto config->arguments
    244             // save the recipes onto config->arguments:RECIPES
    245 
    246             psMetadata *recipe = NULL;      // Recipe from file
    247             if (pmConfigFileRead(&recipe, recipeSource, "recipe")) {
    248                 psString comment = psStringCopy("Recipe added at command line from ");
    249                 psStringAppend(&comment, "%s", recipeSource);
    250                 psMetadataAdd(recipes, PS_LIST_TAIL, recipeName, PS_DATA_METADATA | PS_META_REPLACE,
    251                               comment, recipe);
    252                 psFree(comment);
    253                 psFree(recipe);                 // Drop reference
    254             } else {
    255                 psAbort("error reading config file %s\n", recipeSource);
    256             }
    257         } else {
    258             // Assume it's a symbolic reference to something that's not yet read in.
    259             // it will be loaded later by pmConfigReadRecipes with option CL
    260             psMetadataAddStr(config->recipeSymbols, PS_LIST_TAIL, recipeName, PS_META_REPLACE, "",
    261                              recipeSource);
    262         }
     272        // Assume it's a symbolic reference to something that's not yet read in.
     273        // it will be loaded later by pmConfigReadRecipes with option CL
     274        psMetadataAddStr(config->recipeSymbols, PS_LIST_TAIL, recipeName, PS_META_REPLACE, NULL,
     275                         recipeSource);
     276
    263277        psTrace ("psModules.config", 3, "read recipe %s from %s", recipeName, recipeSource);
    264278        psFree(recipeName);
    265279        psFree(recipeSource);
    266     } // Iterating through the command-line arguments
     280    }
    267281
    268282    return true;
Note: See TracChangeset for help on using the changeset viewer.