diff -p -up partimage-0.6.7/src/client/main.cpp.save_rest_file partimage-0.6.7/src/client/main.cpp --- partimage-0.6.7/src/client/main.cpp.save_rest_file 2008-06-10 11:31:54.000000000 +0200 +++ partimage-0.6.7/src/client/main.cpp 2008-06-10 11:31:54.000000000 +0200 @@ -527,6 +527,10 @@ int main(int argc, char *argv[]) nChoice = OPERATION_SAVE_ALL; else if (strcmp(argv[optind], "rest_all")==0) nChoice = OPERATION_REST_ALL; + else if (strcmp(argv[optind], "save_file")==0) + nChoice = OPERATION_SAVE_FILE; + else if (strcmp(argv[optind], "rest_file")==0) + nChoice = OPERATION_REST_FILE; strncpy(nChoice == OPERATION_REST_ALL || nChoice == OPERATION_SAVE_ALL ? szImageDir : szImageFile, argv[optind+1], MAXPATHLEN); } @@ -649,6 +653,34 @@ int main(int argc, char *argv[]) nRes = -1; } break; + + case OPERATION_SAVE_FILE: + showDebug(1, "action=SAVE_FILE\n"); + try { save_file(szImageFile, &options); } + catch (CExceptions *excep) + { + showDebug(1, "save_file caught exception: %d\n", excep->GetExcept()); + + if (options.bBatchMode) ensure_interface_is_non_interactive(); + g_interface -> Error(excep, szImageFile, ""); + + nRes = -1; + } + break; + + case OPERATION_REST_FILE: + showDebug(1, "action=REST_FILE\n"); + try { rest_file(szImageFile, &options); } + catch (CExceptions *excep) + { + showDebug(1, "rest_file caught exception: %d\n", excep->GetExcept()); + + if (options.bBatchMode) ensure_interface_is_non_interactive(); + g_interface -> Error(excep, szImageFile, ""); + + nRes = -1; + } + break; case OPERATION_IMGINFO: showDebug(1, "action=IMGINFO\n"); diff -p -up partimage-0.6.7/src/client/misc.cpp.save_rest_file partimage-0.6.7/src/client/misc.cpp --- partimage-0.6.7/src/client/misc.cpp.save_rest_file 2008-02-03 22:58:00.000000000 +0100 +++ partimage-0.6.7/src/client/misc.cpp 2008-06-10 11:32:51.000000000 +0200 @@ -2581,3 +2581,52 @@ void rest_all(char *szImageDir, COptions RETURN; } + +void save_file(char *szImageFile, COptions *options) +{ + BEGIN; + int in_offset = 0; + char *in = (char *) malloc(MAXPATHLEN); + + CImage image(options); + image.set_szImageFilename(szImageFile); + image.openWriting(); + + while (1) { + int len = fread(in + in_offset, 1, MAXPATHLEN, stdin); + showDebug(1, "read %d chars on stdin\n", len); + if (!len) break; + in = (char *) realloc(in, MAXPATHLEN + (in_offset += len)); + } + showDebug(1, "writing %d chars in %s\n", in_offset, szImageFile); + write_unsigned(&image, in_offset); + image.write((void *) in, in_offset, true); + free(in); + + closeFilesSave(false, *options, &image, NULL); + + RETURN; +} + +void rest_file(char *szImageFile, COptions *options) +{ + BEGIN; + + CImage image(options); + + { + image.set_szImageFilename(szImageFile); + image.openReading(); + + unsigned int len = read_unsigned(&image); + char *s = (char *) malloc(len + 1); + image.read(s, len, true); + fwrite(s, 1, len, stdout); + free(s); + + // since sfdisk.lst is not really nice to the library, we can't close the thread from procReadBufferFromImage which has already exited + image.closeReading(false); + } + + RETURN; +} diff -p -up partimage-0.6.7/src/client/misc.h.save_rest_file partimage-0.6.7/src/client/misc.h --- partimage-0.6.7/src/client/misc.h.save_rest_file 2008-02-03 22:58:00.000000000 +0100 +++ partimage-0.6.7/src/client/misc.h 2008-06-10 11:31:54.000000000 +0200 @@ -49,6 +49,8 @@ void restorePartition(char *szDevice, ch void restoreMbr(char *szImageFile, COptions *options); void save_all(char *szImageDir, COptions *options); void rest_all(char *szImageDir, COptions *options); +void save_file(char *szImageFile, COptions *options); +void rest_file(char *szImageFile, COptions *options); // ======================================================= void closeFilesSave(bool on_error, COptions options, CImage *image, FILE *fDeviceFile); diff -p -up partimage-0.6.7/src/client/partimage.h.save_rest_file partimage-0.6.7/src/client/partimage.h --- partimage-0.6.7/src/client/partimage.h.save_rest_file 2008-02-03 22:58:00.000000000 +0100 +++ partimage-0.6.7/src/client/partimage.h 2008-06-10 11:31:54.000000000 +0200 @@ -97,6 +97,8 @@ extern bool g_bSigKill; #define OPERATION_EXIT 5 #define OPERATION_SAVE_ALL 6 #define OPERATION_REST_ALL 7 +#define OPERATION_SAVE_FILE 8 +#define OPERATION_REST_FILE 9 // returned by CExceptionsGUI::windowError // user canceled the job