Changeset 24556
- Timestamp:
- Jun 25, 2009, 1:53:26 PM (17 years ago)
- Location:
- trunk/magic/remove/src
- Files:
-
- 1 added
- 7 edited
-
Makefile.simple (modified) (4 diffs)
-
isdestreaked.c (added)
-
streaksio.c (modified) (9 diffs)
-
streaksio.h (modified) (1 diff)
-
streaksremove.c (modified) (7 diffs)
-
streaksremove.h (modified) (2 diffs)
-
streaksreplace.c (modified) (1 diff)
-
streaksutil.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/magic/remove/src/Makefile.simple
r24286 r24556 28 28 streaksrelease.o 29 29 30 ISDESTREAKED_OBJECTS= \ 31 ${COMMON_OBJECTS} \ 32 isdestreaked.o 33 34 35 HEADERS= Line.h streaksastrom.h streaksextern.h streaksio.h streaksremove.h 36 30 37 STREAKSFLAGS=-DSTREAKS_COMPRESS_OUTPUT=1 31 38 OPTFLAGS= -g -O2 … … 35 42 LDFLAGS=`psmodules-config --libs` 36 43 37 PROGRAMS= streaksremove streaksreplace streakscompare streaksrelease 44 PROGRAMS= streaksremove streaksreplace streakscompare streaksrelease isdestreaked 45 HEADERS=Line.h streaksastrom.h streaksextern.h streaksio.h streaksremove.h 38 46 39 47 all: ${PROGRAMS} 40 48 49 ${REMOVE_OBJECTS}: ${HEADERS} 41 50 streaksremove: ${REMOVE_OBJECTS} 42 51 … … 47 56 streaksrelease: ${RELEASE_OBJECTS} 48 57 58 isdestreaked: ${ISDESTREAKED_OBJECTS} 59 60 49 61 install: ${PROGRAMS} 50 62 install -t $(PSCONFDIR)/$(PSCONFIG)/bin streaksremove … … 52 64 install -t $(PSCONFDIR)/$(PSCONFIG)/bin streakscompare 53 65 install -t $(PSCONFDIR)/$(PSCONFIG)/bin streaksrelease 66 install -t $(PSCONFDIR)/$(PSCONFIG)/bin isdestreaked 54 67 55 68 clean: -
trunk/magic/remove/src/streaksio.c
r24383 r24556 19 19 psMemSetDeallocator(sf, (psFreeFunc) streakFilesFree); 20 20 memset(sf, 0, sizeof(*sf)); 21 22 if (remove) { 23 // remember pointer so that streaksExit can delete temps 24 setStreakFiles(sf); 25 } 21 26 22 27 sf->config = config; … … 160 165 } 161 166 167 // figure out if a nebulous instance is a non-destreaked file 168 static bool 169 nebFileIsDestreaked(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 162 196 static psString 163 197 resolveFilename(pmConfig *config, sFile *sfile, bool create) … … 171 205 // delete the existing file, since there may be more than one 172 206 // 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; 174 214 nebDelete(server, sfile->name); 175 215 } … … 193 233 // all of the keywords in the raw image files written to the output destreaked files 194 234 195 if (! CHIP_LEVEL_INPUT(stage) && !strcmp(fileSelect, "INPUT")) {235 if (!outputFilename && !CHIP_LEVEL_INPUT(stage) && !strcmp(fileSelect, "INPUT")) { 196 236 // stage is warp or diff AND fileSelect eq "INPUT" 197 237 // get data from pmFPAfile. … … 250 290 } 251 291 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_) 253 293 // and outputFilename is the basename name of the file (or nebulous key) 254 294 // and the file is to be opened for writing … … 834 874 835 875 bool 836 replicate(sFile * sfile, void *xattr)837 { 838 if (! sfile->inNebulous) {876 replicate(sFile *outFile, sFile *inFile) 877 { 878 if (!outFile->inNebulous) { 839 879 return true; 840 880 } 841 881 nebServer *server = getNebServer(NULL); 842 882 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)); 846 891 return false; 847 892 } 848 if (!nebReplicate(server, sfile->name, NULL, NULL)) {849 psError(PM_ERR_UNKNOWN, true, "neb SetXattr 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)); 850 895 return false; 896 } 897 if (free_user_copies) { 898 nebFree(user_copies); 851 899 } 852 900 return true; … … 861 909 bool status = false; 862 910 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)) { 870 912 psError(PM_ERR_SYS, false, "failed to replicate outImage."); 871 913 return false; 872 914 } 873 915 874 #ifdef notyet875 // XXX: don't replicate mask and weight images until we can look up876 // the input's xattr. There may be a perl program that can getXattr877 916 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)) { 880 918 psError(PM_ERR_SYS, false, "failed to replicate outImage."); 881 919 return false; 882 920 } 883 921 } 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)) { 887 924 psError(PM_ERR_SYS, false, "failed to replicate outImage."); 888 925 return false; 889 926 } 890 927 } 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) 894 936 // perhaps whether we do that or not should be configurable. 895 937 // Sounds like we need a recipe … … 954 996 } 955 997 } 998 956 999 if (!swapOutputToInput(sfiles->inImage, sfiles->outImage)) { 957 1000 psError(PM_ERR_SYS, false, "failed to swap instances for Image."); … … 986 1029 { 987 1030 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); 992 1036 } 993 1037 994 1038 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); 1004 1044 } 1005 1045 -
trunk/magic/remove/src/streaksio.h
r24286 r24556 20 20 void writeImage(sFile *sfile, psString extname, int extnum); 21 21 void writeImageCube(sFile *sfile, psArray *imagecube, psString extname, int extnum); 22 bool replicate(sFile * sfile, void *xattr);22 bool replicate(sFile *outFile, sFile *inFile); 23 23 void readImageFrom_pmFile(streakFiles *sf); 24 24 -
trunk/magic/remove/src/streaksremove.c
r24286 r24556 41 41 Streaks *streaks = readStreaksFile(streaksFileName); 42 42 if (!streaks) { 43 psError StackPrint(stderr, "failed to read streaks file: %s", streaksFileName);43 psError(PS_ERR_UNKNOWN, "failed to read streaks file: %s", streaksFileName); 44 44 streaksExit("", PS_EXIT_PROG_ERROR); 45 45 } … … 209 209 if (!replicateOutputs(sfiles)) { 210 210 psError(PS_ERR_UNKNOWN, false, "failed to replicate output files"); 211 deleteTemps(sfiles); 211 212 psErrorStackPrint(stderr, ""); 212 213 exit(PS_EXIT_UNKNOWN_ERROR); … … 215 216 // NOTE: from here on we can't just quit if something goes wrong. 216 217 // especially if we're working at the raw stage 218 // turn off automatic deletion of output files by streaksExit 219 setStreakFiles(NULL); 217 220 218 221 if (psMetadataLookupBool(&status, config->arguments, "REPLACE")) { … … 220 223 // Note this is a nebulous database operation. No file I/O is performed 221 224 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"); 228 230 229 231 // XXX: pick a specific error code for this failure 230 232 exit(PS_EXIT_UNKNOWN_ERROR); 231 233 } 232 233 #ifdef notdef234 // XXX: we've decided to not do the remove step here235 // Instead we leave the backup images (the original images) in place and remove them236 // later on237 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't242 // repeat the operation.243 244 // Returning error status here is problematic. The inputs have been streak removed245 // but they're still lying around246 // Maybe just print an error message and247 // let other system tools clean up248 psErrorStackPrint(stderr, "");249 exit(PS_EXIT_UNKNOWN_ERROR);250 }251 }252 #endif253 254 234 } 255 235 // all done. Clean up to look for memory leaks. … … 446 426 usage(); 447 427 } 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]); 452 430 psArgumentRemove(argnum, &argc, argv); 453 431 } else { … … 458 436 if ((argnum = psArgumentGet(argc, argv, "-recovery"))) { 459 437 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]); 464 440 psArgumentRemove(argnum, &argc, argv); 465 441 } else if ((stage == IPP_STAGE_RAW) && gotReplace) { … … 467 443 usage(); 468 444 } 469 470 #ifdef notdef471 // This parameter is no longer supported472 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 #endif482 445 483 446 if (argc != 1) { -
trunk/magic/remove/src/streaksremove.h
r23963 r24556 88 88 extern ippStage parseStage(psString); 89 89 extern psString pathToDirectory(char *path); 90 extern void setStreakFiles( streakFiles *); 90 91 91 92 #define CHIP_LEVEL_INPUT(_stage) ((_stage == IPP_STAGE_RAW) || (_stage == IPP_STAGE_CHIP)) … … 95 96 #define IN_NEBULOUS(_filename) (!strncasecmp(_filename, "neb://", strlen("neb://"))) 96 97 98 97 99 #endif // STREAKS_H -
trunk/magic/remove/src/streaksreplace.c
r24286 r24556 97 97 } 98 98 99 #ifdef NOTYET100 if (psMetadataLookupBool(&status, config->arguments, "REPLACE")) {101 // swap the instances for the input and output102 // Note this is a database operation. No file I/O is performed103 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 that107 // it has done and give a detailed report of what happened108 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't118 // repeat the operation.119 120 // Returning error status here is problematic. The inputs have been streak removed121 // but they're still lying around122 // Maybe just print an error message and123 // let other system tools clean up124 psErrorStackPrint(stderr, "");125 exit(PS_EXIT_UNKNOWN_ERROR);126 }127 }128 }129 #endif // REPLACE, REMOVE130 99 // nebServerFree(ourNebServer); 131 100 psFree(config); -
trunk/magic/remove/src/streaksutil.c
r20816 r24556 33 33 } 34 34 35 streakFiles *ourStreakFiles = NULL; 36 37 void 38 setStreakFiles(streakFiles *sfiles) 39 { 40 ourStreakFiles = sfiles; 41 } 42 35 43 // to enhance clarity in these programs we don't propagate errors up the stack 36 44 // we just bail out 37 45 void streaksExit(psString str, int exitCode) { 38 46 psErrorStackPrint(stderr, str); 47 if (ourStreakFiles) { 48 deleteTemps(ourStreakFiles); 49 } 39 50 exit(exitCode); 40 51 }
Note:
See TracChangeset
for help on using the changeset viewer.
