IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24556


Ignore:
Timestamp:
Jun 25, 2009, 1:53:26 PM (17 years ago)
Author:
bills
Message:

various changes to insure that we don't delete non-destreked files by mistake

Location:
trunk/magic/remove/src
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/magic/remove/src/Makefile.simple

    r24286 r24556  
    2828    streaksrelease.o
    2929
     30ISDESTREAKED_OBJECTS=      \
     31    ${COMMON_OBJECTS} \
     32    isdestreaked.o
     33
     34
     35HEADERS= Line.h  streaksastrom.h  streaksextern.h  streaksio.h  streaksremove.h
     36
    3037STREAKSFLAGS=-DSTREAKS_COMPRESS_OUTPUT=1
    3138OPTFLAGS= -g -O2
     
    3542LDFLAGS=`psmodules-config --libs`
    3643
    37 PROGRAMS= streaksremove streaksreplace streakscompare streaksrelease
     44PROGRAMS= streaksremove streaksreplace streakscompare streaksrelease isdestreaked
     45HEADERS=Line.h streaksastrom.h streaksextern.h streaksio.h streaksremove.h
    3846
    3947all:    ${PROGRAMS}
    4048
     49${REMOVE_OBJECTS}:      ${HEADERS}
    4150streaksremove:  ${REMOVE_OBJECTS}
    4251
     
    4756streaksrelease:  ${RELEASE_OBJECTS}
    4857
     58isdestreaked:   ${ISDESTREAKED_OBJECTS}
     59
     60
    4961install:        ${PROGRAMS}
    5062        install -t  $(PSCONFDIR)/$(PSCONFIG)/bin streaksremove
     
    5264        install -t  $(PSCONFDIR)/$(PSCONFIG)/bin streakscompare
    5365        install -t  $(PSCONFDIR)/$(PSCONFIG)/bin streaksrelease
     66        install -t  $(PSCONFDIR)/$(PSCONFIG)/bin isdestreaked
    5467
    5568clean:
  • trunk/magic/remove/src/streaksio.c

    r24383 r24556  
    1919    psMemSetDeallocator(sf, (psFreeFunc) streakFilesFree);
    2020    memset(sf, 0, sizeof(*sf));
     21
     22    if (remove) {
     23        // remember pointer so that streaksExit can delete temps
     24        setStreakFiles(sf);
     25    }
    2126
    2227    sf->config = config;
     
    160165}
    161166
     167// figure out if a nebulous instance is a non-destreaked file
     168static bool
     169nebFileIsDestreaked(sFile *sfile)
     170{
     171    if (!sfile->resolved_name) {
     172        psError(PS_ERR_PROGRAMMING, true, "resolved name is null");
     173        return false;
     174    }
     175    psFits *fits = psFitsOpen(sfile->resolved_name, "r");
     176    if (!fits) {
     177        psError(PS_ERR_IO, true, "failed open %s", sfile->name);
     178        // can't tell if it is a destreaked file
     179        return false;
     180    }
     181    psMetadata *header = psFitsReadHeader(NULL, fits);
     182    if (!header) {
     183        psError(PS_ERR_IO, true, "failed to read header for: %s", sfile->name);
     184        return false;
     185    }
     186    bool mdok;
     187    bool isDestreaked = psMetadataLookupBool(&mdok, header, "PSDESTRK");
     188    if (mdok && isDestreaked) {
     189        return true;
     190    } else {
     191        psError(PS_ERR_IO, false, "output file already exists and may not be de-streaked: %s", sfile->name);
     192        return false;
     193    }
     194}
     195
    162196static psString
    163197resolveFilename(pmConfig *config, sFile *sfile, bool create)
     
    171205            // delete the existing file, since there may be more than one
    172206            // instance. It will get created below in pmConfigConvertFilename
    173             if (nebFind(server, sfile->name)) {
     207            if ((sfile->resolved_name = nebFind(server, sfile->name)) != NULL) {
     208                if (!nebFileIsDestreaked(sfile)) {
     209                    psError(PS_ERR_IO, false, "attempting to delete file that has not been destreaked %s", sfile->name);
     210                    return NULL;
     211                }
     212                nebFree(sfile->resolved_name);
     213                sfile->resolved_name = NULL;
    174214                nebDelete(server, sfile->name);
    175215            }
     
    193233    // all of the keywords in the raw image files written to the output destreaked files
    194234
    195     if (!CHIP_LEVEL_INPUT(stage) && !strcmp(fileSelect, "INPUT")) {
     235    if (!outputFilename && !CHIP_LEVEL_INPUT(stage) && !strcmp(fileSelect, "INPUT")) {
    196236        // stage is warp or diff AND fileSelect eq "INPUT"
    197237        // get data from pmFPAfile.
     
    250290    }
    251291
    252     // if outputFilename is not null name it contains the "directory"
     292    // if outputFilename is not null name it contains the "directory" (perhaps with a prefix like SR_)
    253293    // and outputFilename is the basename name of the file (or nebulous key)
    254294    // and the file is to be opened for writing
     
    834874
    835875bool
    836 replicate(sFile *sfile, void *xattr)
    837 {
    838     if (!sfile->inNebulous) {
     876replicate(sFile *outFile, sFile *inFile)
     877{
     878    if (!outFile->inNebulous) {
    839879        return true;
    840880    }
    841881    nebServer *server = getNebServer(NULL);
    842882
    843     // for now just set "user.copies" to 2
    844     if (!nebSetXattr(server, sfile->name, "user.copies", "2",  NEB_REPLACE)) {
    845         psError(PM_ERR_UNKNOWN, true, "nebSetXattr failed for %s\n%s", sfile->name, nebErr(server));
     883    char *user_copies = nebGetXattr(server, inFile->name, "user.copies");
     884    bool free_user_copies = true;
     885    if (user_copies == NULL) {
     886        user_copies = "2";
     887        free_user_copies = false;
     888    }
     889    if (!nebSetXattr(server, outFile->name, "user.copies", user_copies,  NEB_REPLACE)) {
     890        psError(PM_ERR_UNKNOWN, true, "nebSetXattr failed for %s\n%s", outFile->name, nebErr(server));
    846891        return false;
    847892    }
    848     if (!nebReplicate(server, sfile->name, NULL, NULL)) {
    849         psError(PM_ERR_UNKNOWN, true, "nebSetXattr failed for %s\n%s", sfile->name, nebErr(server));
     893    if (!nebReplicate(server, outFile->name, "any", NULL)) {
     894        psError(PM_ERR_UNKNOWN, true, "nebReplicate failed for %s\n%s", outFile->name, nebErr(server));
    850895        return false;
     896    }
     897    if (free_user_copies) {
     898        nebFree(user_copies);
    851899    }
    852900    return true;
     
    861909    bool status = false;
    862910
    863     // XXX: TODO: need a nebGetXatrr function, but there isn't one
    864     // another option would be to take the number of copies to be
    865     // created as an option. That way the system could decide
    866     // whether to replicate anything other than raw Image files
    867     void *xattr = NULL;
    868 
    869     if (!replicate(sfiles->outImage, xattr)) {
     911    if (!replicate(sfiles->outImage, sfiles->inImage)) {
    870912        psError(PM_ERR_SYS, false, "failed to replicate outImage.");
    871913        return false;
    872914    }
    873915
    874 #ifdef notyet
    875     // XXX: don't replicate mask and weight images until we can look up
    876     // the input's xattr. There may be a perl program that can getXattr
    877916    if (sfiles->outMask) {
    878         // get xattr from input to see if we need to replicate
    879         if (!replicate(sfiles->outMask, xattr)) {
     917        if (!replicate(sfiles->outMask, sfiles->inMask)) {
    880918            psError(PM_ERR_SYS, false, "failed to replicate outImage.");
    881919            return false;
    882920        }
    883921    }
    884     if (sfiles->outWeight) {
    885         // get xattr from input to see if we need to replicate
    886         if (!replicate(sfiles->outWeight, xattr)) {
     922    if (sfiles->outChMask) {
     923        if (!replicate(sfiles->outChMask, sfiles->inChMask)) {
    887924            psError(PM_ERR_SYS, false, "failed to replicate outImage.");
    888925            return false;
    889926        }
    890927    }
    891 #endif
    892 
    893 //      replicate the recovery images (if in nebulous)
     928    if (sfiles->outWeight) {
     929        if (!replicate(sfiles->outWeight, sfiles->inWeight)) {
     930            psError(PM_ERR_SYS, false, "failed to replicate outImage.");
     931            return false;
     932        }
     933    }
     934
     935//      XXX: replicate the recovery images (if in nebulous)
    894936//      perhaps whether we do that or not should be configurable.
    895937//      Sounds like we need a recipe
     
    954996        }
    955997    }
     998
    956999    if (!swapOutputToInput(sfiles->inImage, sfiles->outImage)) {
    9571000        psError(PM_ERR_SYS, false, "failed to swap instances for Image.");
     
    9861029{
    9871030    if (sfiles->outMask) {
    988         if (!deleteFile(sfiles->outMask)) {
    989             psError(PM_ERR_SYS, false, "failed to delete Mask.");
    990             return false;
    991         }
     1031        deleteFile(sfiles->outMask);
     1032    }
     1033
     1034    if (sfiles->outChMask) {
     1035        deleteFile(sfiles->outChMask);
    9921036    }
    9931037
    9941038    if (sfiles->outWeight) {
    995         if (!deleteFile(sfiles->outWeight)) {
    996             psError(PM_ERR_SYS, false, "failed to delete Weight.");
    997             return false;
    998         }
    999     }
    1000 
    1001     if (!deleteFile(sfiles->outImage)) {
    1002         psError(PM_ERR_SYS, false, "failed to delete Image.");
    1003         return false;
     1039        deleteFile(sfiles->outWeight);
     1040    }
     1041
     1042    if (sfiles->outImage) {
     1043        deleteFile(sfiles->outImage);
    10041044    }
    10051045
  • trunk/magic/remove/src/streaksio.h

    r24286 r24556  
    2020void writeImage(sFile *sfile, psString extname, int extnum);
    2121void writeImageCube(sFile *sfile, psArray *imagecube, psString extname, int extnum);
    22 bool replicate(sFile *sfile, void *xattr);
     22bool replicate(sFile *outFile, sFile *inFile);
    2323void readImageFrom_pmFile(streakFiles *sf);
    2424
  • trunk/magic/remove/src/streaksremove.c

    r24286 r24556  
    4141    Streaks *streaks = readStreaksFile(streaksFileName);
    4242    if (!streaks) {
    43         psErrorStackPrint(stderr, "failed to read streaks file: %s", streaksFileName);
     43        psError(PS_ERR_UNKNOWN, "failed to read streaks file: %s", streaksFileName);
    4444        streaksExit("", PS_EXIT_PROG_ERROR);
    4545    }
     
    209209    if (!replicateOutputs(sfiles)) {
    210210        psError(PS_ERR_UNKNOWN, false, "failed to replicate output files");
     211        deleteTemps(sfiles);
    211212        psErrorStackPrint(stderr, "");
    212213        exit(PS_EXIT_UNKNOWN_ERROR);
     
    215216    // NOTE: from here on we can't just quit if something goes wrong.
    216217    // especially if we're working at the raw stage
     218    // turn off automatic deletion of output files by streaksExit
     219    setStreakFiles(NULL);
    217220
    218221    if (psMetadataLookupBool(&status, config->arguments, "REPLACE")) {
     
    220223        //     Note this is a nebulous database operation. No file I/O is performed
    221224        if (!swapOutputsToInputs(sfiles)) {
    222             psError(PS_ERR_UNKNOWN, false, "failed to swap files");
    223 
    224             // XXX: Now what? I guess swapOutputsToInputs will need to undo anything that
    225             // it has done and give a detailed report of what happened
    226 
    227             psErrorStackPrint(stderr, "");
     225            // XXX: Now what?
     226            // It is up to the program that reverts failed destreak runs to insure that
     227            // any input files that have been swapped are restored
     228
     229            psErrorStackPrint(stderr, "failed to swap files");
    228230
    229231            // XXX: pick a specific error code for this failure
    230232            exit(PS_EXIT_UNKNOWN_ERROR);
    231233        }
    232 
    233 #ifdef notdef
    234         // XXX: we've decided to not do the remove step here
    235         // Instead we leave the backup images (the original images) in place and remove them
    236         // later on
    237         if (psMetadataLookupBool(&status, config->arguments, "REMOVE")) {
    238             //      delete the temporary storage objects (which now points to the original image(s)
    239             if (!deleteTemps(sfiles)) {
    240                 psError(PS_ERR_UNKNOWN, false, "failed to delete temporary files");
    241                 // XXX: Now what? At this point the output files have been swapped, so we can't
    242                 // repeat the operation.
    243 
    244                 // Returning error status here is problematic. The inputs have been streak removed
    245                 // but they're still lying around
    246                 // Maybe just print an error message and
    247                 // let other system tools clean up
    248                 psErrorStackPrint(stderr, "");
    249                 exit(PS_EXIT_UNKNOWN_ERROR);
    250             }
    251         }
    252 #endif
    253 
    254234    }
    255235    // all done. Clean up to look for memory leaks.
     
    446426            usage();
    447427        }
    448         psString dir = pathToDirectory(argv[argnum]);
    449         psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "directory for temporary files",
    450             dir);
    451         psFree(dir);
     428        psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "path for (temporary if replae) output files",
     429            argv[argnum]);
    452430        psArgumentRemove(argnum, &argc, argv);
    453431    } else {
     
    458436    if ((argnum = psArgumentGet(argc, argv, "-recovery"))) {
    459437        psArgumentRemove(argnum, &argc, argv);
    460         psString dir = pathToDirectory(argv[argnum]);
    461         psMetadataAddStr(config->arguments, PS_LIST_TAIL, "RECOVERY", 0, "directory for recovery files",
    462             dir);
    463         psFree(dir);
     438        psMetadataAddStr(config->arguments, PS_LIST_TAIL, "RECOVERY", 0, "path for recovery files",
     439            argv[argnum]);
    464440        psArgumentRemove(argnum, &argc, argv);
    465441    } else if ((stage == IPP_STAGE_RAW) && gotReplace) {
     
    467443        usage();
    468444    }
    469 
    470 #ifdef notdef
    471     // This parameter is no longer supported
    472     if ((argnum = psArgumentGet(argc, argv, "-remove"))) {
    473         if (!gotReplace) {
    474             psError(PS_ERR_UNKNOWN, true, "-replace is required with -remove\n");
    475             usage();
    476         }
    477         psArgumentRemove(argnum, &argc, argv);
    478         psMetadataAddBool(config->arguments, PS_LIST_TAIL, "REMOVE", 0, "remove original files",
    479             true);
    480     }
    481 #endif
    482445
    483446    if (argc != 1) {
  • trunk/magic/remove/src/streaksremove.h

    r23963 r24556  
    8888extern ippStage parseStage(psString);
    8989extern psString pathToDirectory(char *path);
     90extern void setStreakFiles( streakFiles *);
    9091
    9192#define CHIP_LEVEL_INPUT(_stage) ((_stage == IPP_STAGE_RAW) || (_stage == IPP_STAGE_CHIP))
     
    9596#define IN_NEBULOUS(_filename) (!strncasecmp(_filename, "neb://", strlen("neb://")))
    9697
     98
    9799#endif // STREAKS_H
  • trunk/magic/remove/src/streaksreplace.c

    r24286 r24556  
    9797    }
    9898
    99 #ifdef NOTYET
    100     if (psMetadataLookupBool(&status, config->arguments, "REPLACE")) {
    101         //     swap the instances for the input and output
    102         //     Note this is a database operation. No file I/O is performed
    103         if (!swapOutputsToInputs(sfiles)) {
    104             psError(PS_ERR_UNKNOWN, false, "failed to swap files");
    105 
    106             // XXX: Now what? I guess swapOutputsToInputs will need to undo anything that
    107             // it has done and give a detailed report of what happened
    108 
    109             psErrorStackPrint(stderr, "");
    110             exit(PS_EXIT_UNKNOWN_ERROR);
    111         }
    112 
    113         if (psMetadataLookupBool(&status, config->arguments, "REMOVE")) {
    114             //      delete the temporary storage objects (which now points to the original image(s)
    115             if (!deleteTemps(sfiles)) {
    116                 psError(PS_ERR_UNKNOWN, false, "failed to delete temporary files");
    117                 // XXX: Now what? At this point the output files have been swapped, so we can't
    118                 // repeat the operation.
    119 
    120                 // Returning error status here is problematic. The inputs have been streak removed
    121                 // but they're still lying around
    122                 // Maybe just print an error message and
    123                 // let other system tools clean up
    124                 psErrorStackPrint(stderr, "");
    125                 exit(PS_EXIT_UNKNOWN_ERROR);
    126             }
    127         }
    128     }
    129 #endif  // REPLACE, REMOVE
    13099//    nebServerFree(ourNebServer);
    131100    psFree(config);
  • trunk/magic/remove/src/streaksutil.c

    r20816 r24556  
    3333}
    3434
     35streakFiles *ourStreakFiles = NULL;
     36
     37void
     38setStreakFiles(streakFiles *sfiles)
     39{
     40    ourStreakFiles = sfiles;
     41}
     42
    3543// to enhance clarity in these programs we don't propagate errors up the stack
    3644// we just bail out
    3745void streaksExit(psString str, int exitCode) {
    3846    psErrorStackPrint(stderr, str);
     47    if (ourStreakFiles) {
     48        deleteTemps(ourStreakFiles);
     49    }
    3950    exit(exitCode);
    4051}
Note: See TracChangeset for help on using the changeset viewer.