dsync-cdimage.cc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: dsync-cdimage.cc,v 1.2 1999/12/26 06:59:00 jgg Exp $
  4. /* ######################################################################
  5. DSync CD Image - CD Image transfer program
  6. This implements the DSync CD transfer method. This method is optimized
  7. to reconstruct a CD from a mirror of the CD's contents and the original
  8. ISO image.
  9. ##################################################################### */
  10. /*}}}*/
  11. // Include files /*{{{*/
  12. #include <dsync/cmndline.h>
  13. #include <dsync/configuration.h>
  14. #include <dsync/error.h>
  15. #include <dsync/filelistdb.h>
  16. #include <dsync/rsync-algo.h>
  17. #include <config.h>
  18. #include <iostream>
  19. #include <fstream>
  20. #include <signal.h>
  21. using namespace std;
  22. /*}}}*/
  23. // Externs /*{{{*/
  24. ostream c0out(cout.rdbuf());
  25. ostream c1out(cout.rdbuf());
  26. ostream c2out(cout.rdbuf());
  27. ofstream devnull("/dev/null");
  28. unsigned int ScreenWidth = 80;
  29. /*}}}*/
  30. // DoGenerate - Generate the checksum list /*{{{*/
  31. // ---------------------------------------------------------------------
  32. /* */
  33. bool DoGenerate(CommandLine &CmdL)
  34. {
  35. return true;
  36. }
  37. /*}}}*/
  38. // DoAggregate - Generate aggregated file records /*{{{*/
  39. // ---------------------------------------------------------------------
  40. /* This takes a file list with already generated rsync checksums and builds
  41. aggregated file lists for each checksum record */
  42. bool DoAggregate(CommandLine &CmdL)
  43. {
  44. if (CmdL.FileList[1] == 0)
  45. return _error->Error("You must specify a file name");
  46. // Open the file
  47. dsMMapIO IO(CmdL.FileList[1]);
  48. if (_error->PendingError() == true)
  49. return false;
  50. dsFList List;
  51. if (List.Step(IO) == false || List.Tag != dsFList::tHeader)
  52. return _error->Error("Unable to read header");
  53. string Dir;
  54. string File;
  55. while (List.Step(IO) == true)
  56. {
  57. if (List.Tag == dsFList::tDirStart)
  58. {
  59. Dir = List.Dir.Name;
  60. continue;
  61. }
  62. if (List.Entity != 0)
  63. {
  64. File = List.Entity->Name;
  65. continue;
  66. }
  67. if (List.Tag == dsFList::tRSyncChecksum)
  68. {
  69. RSyncMatch Match(List.RChk);
  70. }
  71. if (List.Tag == dsFList::tTrailer)
  72. break;
  73. }
  74. return true;
  75. }
  76. /*}}}*/
  77. // ShowHelp - Show the help screen /*{{{*/
  78. // ---------------------------------------------------------------------
  79. /* */
  80. bool ShowHelp(CommandLine &CmdL)
  81. {
  82. cout << PACKAGE << ' ' << VERSION << " for " << ARCHITECTURE <<
  83. " compiled on " << __DATE__ << " " << __TIME__ << endl;
  84. cout <<
  85. "Usage: dsync-cdimage [options] command [file]\n"
  86. "\n"
  87. "dsync-cdimage is a tool for replicating CD images from a mirror of\n"
  88. "their contents.\n"
  89. "\n"
  90. "Commands:\n"
  91. " generate - Build a file+checksum index\n"
  92. " help - This help text\n"
  93. " verify - Compare the index against files in the current directory\n"
  94. "\n"
  95. "Options:\n"
  96. " -h This help text.\n"
  97. " -q Loggable output - no progress indicator\n"
  98. " -qq No output except for errors\n"
  99. " -c=? Read this configuration file\n"
  100. " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp\n"
  101. "See the dsync-cdimage(1) and dsync.conf(5) manual\n"
  102. "pages for more information." << endl;
  103. return 100;
  104. }
  105. /*}}}*/
  106. int main(int argc, const char *argv[])
  107. {
  108. CommandLine::Args Args[] = {
  109. {'h',"help","help",0},
  110. {'q',"quiet","quiet",CommandLine::IntLevel},
  111. {'q',"silent","quiet",CommandLine::IntLevel},
  112. {'v',"verbose","verbose",CommandLine::IntLevel},
  113. {'c',"config-file",0,CommandLine::ConfigFile},
  114. {'o',"option",0,CommandLine::ArbItem},
  115. {0,0,0,0}};
  116. CommandLine::Dispatch Cmds[] = {{"generate",&DoGenerate},
  117. {"help",&ShowHelp},
  118. {"aggregate",&DoAggregate},
  119. {0,0}};
  120. CommandLine CmdL(Args,_config);
  121. if (CmdL.Parse(argc,argv) == false)
  122. {
  123. _error->DumpErrors();
  124. return 100;
  125. }
  126. // See if the help should be shown
  127. if (_config->FindB("help") == true ||
  128. CmdL.FileSize() == 0)
  129. return ShowHelp(CmdL);
  130. // Setup the output streams
  131. c0out.rdbuf(cout.rdbuf());
  132. c1out.rdbuf(cout.rdbuf());
  133. c2out.rdbuf(cout.rdbuf());
  134. if (_config->FindI("quiet",0) > 0)
  135. c0out.rdbuf(devnull.rdbuf());
  136. if (_config->FindI("quiet",0) > 1)
  137. c1out.rdbuf(devnull.rdbuf());
  138. // Setup the signals
  139. /* signal(SIGWINCH,SigWinch);
  140. SigWinch(0);*/
  141. // Match the operation
  142. CmdL.DispatchArg(Cmds);
  143. // Print any errors or warnings found during parsing
  144. if (_error->empty() == false)
  145. {
  146. bool Errors = _error->PendingError();
  147. _error->DumpErrors();
  148. return Errors == true?100:0;
  149. }
  150. return 0;
  151. }