rred.cc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. // Includes /*{{{*/
  2. #include <config.h>
  3. #include <apt-pkg/fileutl.h>
  4. #include <apt-pkg/mmap.h>
  5. #include <apt-pkg/error.h>
  6. #include <apt-pkg/acquire-method.h>
  7. #include <apt-pkg/strutl.h>
  8. #include <apt-pkg/hashes.h>
  9. #include <apt-pkg/configuration.h>
  10. #include <sys/stat.h>
  11. #include <sys/uio.h>
  12. #include <sys/types.h>
  13. #include <fcntl.h>
  14. #include <unistd.h>
  15. #include <utime.h>
  16. #include <stdio.h>
  17. #include <errno.h>
  18. #include <apti18n.h>
  19. /*}}}*/
  20. /** \brief RredMethod - ed-style incremential patch method {{{
  21. *
  22. * This method implements a patch functionality similar to "patch --ed" that is
  23. * used by the "tiffany" incremental packages download stuff. It differs from
  24. * "ed" insofar that it is way more restricted (and therefore secure).
  25. * The currently supported ed commands are "<em>c</em>hange", "<em>a</em>dd" and
  26. * "<em>d</em>elete" (diff doesn't output any other).
  27. * Additionally the records must be reverse sorted by line number and
  28. * may not overlap (diff *seems* to produce this kind of output).
  29. * */
  30. class RredMethod : public pkgAcqMethod {
  31. bool Debug;
  32. // the size of this doesn't really matter (except for performance)
  33. const static int BUF_SIZE = 1024;
  34. // the supported ed commands
  35. enum Mode {MODE_CHANGED='c', MODE_DELETED='d', MODE_ADDED='a'};
  36. // return values
  37. enum State {ED_OK, ED_ORDERING, ED_PARSER, ED_FAILURE, MMAP_FAILED};
  38. State applyFile(FileFd &ed_cmds, FileFd &in_file, FileFd &out_file,
  39. unsigned long &line, char *buffer, Hashes *hash) const;
  40. void ignoreLineInFile(FileFd &fin, char *buffer) const;
  41. void copyLinesFromFileToFile(FileFd &fin, FileFd &fout, unsigned int lines,
  42. Hashes *hash, char *buffer) const;
  43. State patchFile(FileFd &Patch, FileFd &From, FileFd &out_file, Hashes *hash) const;
  44. State patchMMap(FileFd &Patch, FileFd &From, FileFd &out_file, Hashes *hash) const;
  45. protected:
  46. // the methods main method
  47. virtual bool Fetch(FetchItem *Itm);
  48. public:
  49. RredMethod() : pkgAcqMethod("1.1",SingleInstance | SendConfig), Debug(false) {};
  50. };
  51. /*}}}*/
  52. /** \brief applyFile - in reverse order with a tail recursion {{{
  53. *
  54. * As it is expected that the commands are in reversed order in the patch file
  55. * we check in the first half if the command is valid, but doesn't execute it
  56. * and move a step deeper. After reaching the end of the file we apply the
  57. * patches in the correct order: last found command first.
  58. *
  59. * \param ed_cmds patch file to apply
  60. * \param in_file base file we want to patch
  61. * \param out_file file to write the patched result to
  62. * \param line of command operation
  63. * \param buffer internal used read/write buffer
  64. * \param hash the created file for correctness
  65. * \return the success State of the ed command executor
  66. */
  67. RredMethod::State RredMethod::applyFile(FileFd &ed_cmds, FileFd &in_file, FileFd &out_file,
  68. unsigned long &line, char *buffer, Hashes *hash) const {
  69. // get the current command and parse it
  70. if (ed_cmds.ReadLine(buffer, BUF_SIZE) == NULL) {
  71. if (Debug == true)
  72. std::clog << "rred: encounter end of file - we can start patching now." << std::endl;
  73. line = 0;
  74. return ED_OK;
  75. }
  76. // parse in the effected linenumbers
  77. char* idx;
  78. errno=0;
  79. unsigned long const startline = strtol(buffer, &idx, 10);
  80. if (errno == ERANGE || errno == EINVAL) {
  81. _error->Errno("rred", "startline is an invalid number");
  82. return ED_PARSER;
  83. }
  84. if (startline > line) {
  85. _error->Error("rred: The start line (%lu) of the next command is higher than the last line (%lu). This is not allowed.", startline, line);
  86. return ED_ORDERING;
  87. }
  88. unsigned long stopline;
  89. if (*idx == ',') {
  90. idx++;
  91. errno=0;
  92. stopline = strtol(idx, &idx, 10);
  93. if (errno == ERANGE || errno == EINVAL) {
  94. _error->Errno("rred", "stopline is an invalid number");
  95. return ED_PARSER;
  96. }
  97. }
  98. else {
  99. stopline = startline;
  100. }
  101. line = startline;
  102. // which command to execute on this line(s)?
  103. switch (*idx) {
  104. case MODE_CHANGED:
  105. if (Debug == true)
  106. std::clog << "Change from line " << startline << " to " << stopline << std::endl;
  107. break;
  108. case MODE_ADDED:
  109. if (Debug == true)
  110. std::clog << "Insert after line " << startline << std::endl;
  111. break;
  112. case MODE_DELETED:
  113. if (Debug == true)
  114. std::clog << "Delete from line " << startline << " to " << stopline << std::endl;
  115. break;
  116. default:
  117. _error->Error("rred: Unknown ed command '%c'. Abort.", *idx);
  118. return ED_PARSER;
  119. }
  120. unsigned char mode = *idx;
  121. // save the current position
  122. unsigned const long long pos = ed_cmds.Tell();
  123. // if this is add or change then go to the next full stop
  124. unsigned int data_length = 0;
  125. if (mode == MODE_CHANGED || mode == MODE_ADDED) {
  126. do {
  127. ignoreLineInFile(ed_cmds, buffer);
  128. data_length++;
  129. }
  130. while (strncmp(buffer, ".", 1) != 0);
  131. data_length--; // the dot should not be copied
  132. }
  133. // do the recursive call - the last command is the one we need to execute at first
  134. const State child = applyFile(ed_cmds, in_file, out_file, line, buffer, hash);
  135. if (child != ED_OK) {
  136. return child;
  137. }
  138. // change and delete are working on "line" - add is done after "line"
  139. if (mode != MODE_ADDED)
  140. line++;
  141. // first wind to the current position and copy over all unchanged lines
  142. if (line < startline) {
  143. copyLinesFromFileToFile(in_file, out_file, (startline - line), hash, buffer);
  144. line = startline;
  145. }
  146. if (mode != MODE_ADDED)
  147. line--;
  148. // include data from ed script
  149. if (mode == MODE_CHANGED || mode == MODE_ADDED) {
  150. ed_cmds.Seek(pos);
  151. copyLinesFromFileToFile(ed_cmds, out_file, data_length, hash, buffer);
  152. }
  153. // ignore the corresponding number of lines from input
  154. if (mode == MODE_CHANGED || mode == MODE_DELETED) {
  155. while (line < stopline) {
  156. ignoreLineInFile(in_file, buffer);
  157. line++;
  158. }
  159. }
  160. return ED_OK;
  161. }
  162. /*}}}*/
  163. void RredMethod::copyLinesFromFileToFile(FileFd &fin, FileFd &fout, unsigned int lines,/*{{{*/
  164. Hashes *hash, char *buffer) const {
  165. while (0 < lines--) {
  166. do {
  167. fin.ReadLine(buffer, BUF_SIZE);
  168. unsigned long long const towrite = strlen(buffer);
  169. fout.Write(buffer, towrite);
  170. hash->Add((unsigned char*)buffer, towrite);
  171. } while (strlen(buffer) == (BUF_SIZE - 1) &&
  172. buffer[BUF_SIZE - 2] != '\n');
  173. }
  174. }
  175. /*}}}*/
  176. void RredMethod::ignoreLineInFile(FileFd &fin, char *buffer) const { /*{{{*/
  177. fin.ReadLine(buffer, BUF_SIZE);
  178. while (strlen(buffer) == (BUF_SIZE - 1) &&
  179. buffer[BUF_SIZE - 2] != '\n') {
  180. fin.ReadLine(buffer, BUF_SIZE);
  181. buffer[0] = ' ';
  182. }
  183. }
  184. /*}}}*/
  185. RredMethod::State RredMethod::patchFile(FileFd &Patch, FileFd &From, /*{{{*/
  186. FileFd &out_file, Hashes *hash) const {
  187. char buffer[BUF_SIZE];
  188. /* we do a tail recursion to read the commands in the right order */
  189. unsigned long line = -1; // assign highest possible value
  190. State const result = applyFile(Patch, From, out_file, line, buffer, hash);
  191. /* read the rest from infile */
  192. if (result == ED_OK) {
  193. while (From.ReadLine(buffer, BUF_SIZE) != NULL) {
  194. unsigned long long const towrite = strlen(buffer);
  195. out_file.Write(buffer, towrite);
  196. hash->Add((unsigned char*)buffer, towrite);
  197. }
  198. }
  199. return result;
  200. }
  201. /*}}}*/
  202. /* struct EdCommand {{{*/
  203. #ifdef _POSIX_MAPPED_FILES
  204. struct EdCommand {
  205. size_t data_start;
  206. size_t data_end;
  207. size_t data_lines;
  208. size_t first_line;
  209. size_t last_line;
  210. char type;
  211. };
  212. #define IOV_COUNT 1024 /* Don't really want IOV_MAX since it can be arbitrarily large */
  213. static ssize_t retry_writev(int fd, const struct iovec *iov, int iovcnt) {
  214. ssize_t Res;
  215. errno = 0;
  216. ssize_t i = 0;
  217. do {
  218. Res = writev(fd, iov + i, iovcnt);
  219. if (Res < 0 && errno == EINTR)
  220. continue;
  221. if (Res < 0)
  222. return _error->Errno("writev",_("Write error"));
  223. iovcnt -= Res;
  224. i += Res;
  225. } while (Res > 0 && iovcnt > 0);
  226. return i;
  227. }
  228. #endif
  229. /*}}}*/
  230. RredMethod::State RredMethod::patchMMap(FileFd &Patch, FileFd &From, /*{{{*/
  231. FileFd &out_file, Hashes *hash) const {
  232. #ifdef _POSIX_MAPPED_FILES
  233. MMap ed_cmds(Patch, MMap::ReadOnly);
  234. MMap in_file(From, MMap::ReadOnly);
  235. unsigned long long const ed_size = ed_cmds.Size();
  236. unsigned long long const in_size = in_file.Size();
  237. if (ed_size == 0 || in_size == 0)
  238. return MMAP_FAILED;
  239. EdCommand* commands = 0;
  240. size_t command_count = 0;
  241. size_t command_alloc = 0;
  242. const char* begin = (char*) ed_cmds.Data();
  243. const char* end = begin;
  244. const char* ed_end = (char*) ed_cmds.Data() + ed_size;
  245. const char* input = (char*) in_file.Data();
  246. const char* input_end = (char*) in_file.Data() + in_size;
  247. size_t i;
  248. /* 1. Parse entire script. It is executed in reverse order, so we cather it
  249. * in the `commands' buffer first
  250. */
  251. for(;;) {
  252. EdCommand cmd;
  253. cmd.data_start = 0;
  254. cmd.data_end = 0;
  255. while(begin != ed_end && *begin == '\n')
  256. ++begin;
  257. while(end != ed_end && *end != '\n')
  258. ++end;
  259. if(end == ed_end && begin == end)
  260. break;
  261. /* Determine command range */
  262. const char* tmp = begin;
  263. for(;;) {
  264. /* atoll is safe despite lacking NUL-termination; we know there's an
  265. * alphabetic character at end[-1]
  266. */
  267. if(tmp == end) {
  268. cmd.first_line = atol(begin);
  269. cmd.last_line = cmd.first_line;
  270. break;
  271. }
  272. if(*tmp == ',') {
  273. cmd.first_line = atol(begin);
  274. cmd.last_line = atol(tmp + 1);
  275. break;
  276. }
  277. ++tmp;
  278. }
  279. // which command to execute on this line(s)?
  280. switch (end[-1]) {
  281. case MODE_CHANGED:
  282. if (Debug == true)
  283. std::clog << "Change from line " << cmd.first_line << " to " << cmd.last_line << std::endl;
  284. break;
  285. case MODE_ADDED:
  286. if (Debug == true)
  287. std::clog << "Insert after line " << cmd.first_line << std::endl;
  288. break;
  289. case MODE_DELETED:
  290. if (Debug == true)
  291. std::clog << "Delete from line " << cmd.first_line << " to " << cmd.last_line << std::endl;
  292. break;
  293. default:
  294. _error->Error("rred: Unknown ed command '%c'. Abort.", end[-1]);
  295. free(commands);
  296. return ED_PARSER;
  297. }
  298. cmd.type = end[-1];
  299. /* Determine the size of the inserted text, so we don't have to scan this
  300. * text again later.
  301. */
  302. begin = end + 1;
  303. end = begin;
  304. cmd.data_lines = 0;
  305. if(cmd.type == MODE_ADDED || cmd.type == MODE_CHANGED) {
  306. cmd.data_start = begin - (char*) ed_cmds.Data();
  307. while(end != ed_end) {
  308. if(*end == '\n') {
  309. if(end[-1] == '.' && end[-2] == '\n')
  310. break;
  311. ++cmd.data_lines;
  312. }
  313. ++end;
  314. }
  315. cmd.data_end = end - (char*) ed_cmds.Data() - 1;
  316. begin = end + 1;
  317. end = begin;
  318. }
  319. if(command_count == command_alloc) {
  320. command_alloc = (command_alloc + 64) * 3 / 2;
  321. EdCommand* newCommands = (EdCommand*) realloc(commands, command_alloc * sizeof(EdCommand));
  322. if (newCommands == NULL) {
  323. free(commands);
  324. return MMAP_FAILED;
  325. }
  326. commands = newCommands;
  327. }
  328. commands[command_count++] = cmd;
  329. }
  330. struct iovec* iov = new struct iovec[IOV_COUNT];
  331. size_t iov_size = 0;
  332. size_t amount, remaining;
  333. size_t line = 1;
  334. EdCommand* cmd;
  335. /* 2. Execute script. We gather writes in a `struct iov' array, and flush
  336. * using writev to minimize the number of system calls. Data is read
  337. * directly from the memory mappings of the input file and the script.
  338. */
  339. for(i = command_count; i-- > 0; ) {
  340. cmd = &commands[i];
  341. if(cmd->type == MODE_ADDED)
  342. amount = cmd->first_line + 1;
  343. else
  344. amount = cmd->first_line;
  345. if(line < amount) {
  346. begin = input;
  347. while(line != amount) {
  348. input = (const char*) memchr(input, '\n', input_end - input);
  349. if(!input)
  350. break;
  351. ++line;
  352. ++input;
  353. }
  354. iov[iov_size].iov_base = (void*) begin;
  355. iov[iov_size].iov_len = input - begin;
  356. hash->Add((const unsigned char*) begin, input - begin);
  357. if(++iov_size == IOV_COUNT) {
  358. retry_writev(out_file.Fd(), iov, IOV_COUNT);
  359. iov_size = 0;
  360. }
  361. }
  362. if(cmd->type == MODE_DELETED || cmd->type == MODE_CHANGED) {
  363. remaining = (cmd->last_line - cmd->first_line) + 1;
  364. line += remaining;
  365. while(remaining) {
  366. input = (const char*) memchr(input, '\n', input_end - input);
  367. if(!input)
  368. break;
  369. --remaining;
  370. ++input;
  371. }
  372. }
  373. if(cmd->type == MODE_CHANGED || cmd->type == MODE_ADDED) {
  374. if(cmd->data_end != cmd->data_start) {
  375. iov[iov_size].iov_base = (void*) ((char*)ed_cmds.Data() + cmd->data_start);
  376. iov[iov_size].iov_len = cmd->data_end - cmd->data_start;
  377. hash->Add((const unsigned char*) ((char*)ed_cmds.Data() + cmd->data_start),
  378. iov[iov_size].iov_len);
  379. if(++iov_size == IOV_COUNT) {
  380. retry_writev(out_file.Fd(), iov, IOV_COUNT);
  381. iov_size = 0;
  382. }
  383. }
  384. }
  385. }
  386. if(input != input_end) {
  387. iov[iov_size].iov_base = (void*) input;
  388. iov[iov_size].iov_len = input_end - input;
  389. hash->Add((const unsigned char*) input, input_end - input);
  390. ++iov_size;
  391. }
  392. if(iov_size) {
  393. retry_writev(out_file.Fd(), iov, iov_size);
  394. iov_size = 0;
  395. }
  396. for(i = 0; i < iov_size; i += IOV_COUNT) {
  397. if(iov_size - i < IOV_COUNT)
  398. retry_writev(out_file.Fd(), iov + i, iov_size - i);
  399. else
  400. retry_writev(out_file.Fd(), iov + i, IOV_COUNT);
  401. }
  402. delete [] iov;
  403. free(commands);
  404. return ED_OK;
  405. #else
  406. return MMAP_FAILED;
  407. #endif
  408. }
  409. /*}}}*/
  410. bool RredMethod::Fetch(FetchItem *Itm) /*{{{*/
  411. {
  412. Debug = _config->FindB("Debug::pkgAcquire::RRed", false);
  413. URI Get = Itm->Uri;
  414. std::string Path = Get.Host + Get.Path; // To account for relative paths
  415. FetchResult Res;
  416. Res.Filename = Itm->DestFile;
  417. if (Itm->Uri.empty() == true) {
  418. Path = Itm->DestFile;
  419. Itm->DestFile.append(".result");
  420. } else
  421. URIStart(Res);
  422. std::string lastPatchName;
  423. Hashes Hash;
  424. // check for a single ed file
  425. if (FileExists(Path+".ed") == true)
  426. {
  427. if (Debug == true)
  428. std::clog << "Patching " << Path << " with " << Path
  429. << ".ed and putting result into " << Itm->DestFile << std::endl;
  430. // Open the source and destination files
  431. lastPatchName = Path + ".ed";
  432. FileFd From(Path,FileFd::ReadOnly);
  433. FileFd To(Itm->DestFile,FileFd::WriteAtomic);
  434. To.EraseOnFailure();
  435. FileFd Patch(lastPatchName, FileFd::ReadOnly, FileFd::Gzip);
  436. if (_error->PendingError() == true)
  437. return false;
  438. // now do the actual patching
  439. State const result = patchMMap(Patch, From, To, &Hash);
  440. if (result == MMAP_FAILED) {
  441. // retry with patchFile
  442. Patch.Seek(0);
  443. From.Seek(0);
  444. To.Open(Itm->DestFile,FileFd::WriteAtomic);
  445. if (_error->PendingError() == true)
  446. return false;
  447. if (patchFile(Patch, From, To, &Hash) != ED_OK) {
  448. return _error->WarningE("rred", _("Could not patch %s with mmap and with file operation usage - the patch seems to be corrupt."), Path.c_str());
  449. } else if (Debug == true) {
  450. std::clog << "rred: finished file patching of " << Path << " after mmap failed." << std::endl;
  451. }
  452. } else if (result != ED_OK) {
  453. return _error->Errno("rred", _("Could not patch %s with mmap (but no mmap specific fail) - the patch seems to be corrupt."), Path.c_str());
  454. } else if (Debug == true) {
  455. std::clog << "rred: finished mmap patching of " << Path << std::endl;
  456. }
  457. // write out the result
  458. From.Close();
  459. Patch.Close();
  460. To.Close();
  461. }
  462. else
  463. {
  464. if (Debug == true)
  465. std::clog << "Patching " << Path << " with all " << Path << ".ed.*.gz files and "
  466. << "putting result into " << Itm->DestFile << std::endl;
  467. int From = open(Path.c_str(), O_RDONLY);
  468. unlink(Itm->DestFile.c_str());
  469. int To = open(Itm->DestFile.c_str(), O_WRONLY | O_CREAT | O_EXCL, 0644);
  470. SetCloseExec(From, false);
  471. SetCloseExec(To, false);
  472. _error->PushToStack();
  473. std::vector<std::string> patches = GetListOfFilesInDir(flNotFile(Path), "gz", true, false);
  474. _error->RevertToStack();
  475. std::string externalrred = _config->Find("Dir::Bin::rred", "/usr/bin/diffindex-rred");
  476. std::vector<const char *> Args;
  477. Args.reserve(22);
  478. Args.push_back(externalrred.c_str());
  479. std::string const baseName = Path + ".ed.";
  480. for (std::vector<std::string>::const_iterator p = patches.begin();
  481. p != patches.end(); ++p)
  482. if (p->compare(0, baseName.length(), baseName) == 0)
  483. Args.push_back(p->c_str());
  484. Args.push_back(NULL);
  485. pid_t Patcher = ExecFork();
  486. if (Patcher == 0) {
  487. dup2(From, STDIN_FILENO);
  488. dup2(To, STDOUT_FILENO);
  489. execvp(Args[0], (char **) &Args[0]);
  490. std::cerr << "Failed to execute patcher " << Args[0] << "!" << std::endl;
  491. _exit(100);
  492. }
  493. // last is NULL, so the one before is the last patch
  494. lastPatchName = Args[Args.size() - 2];
  495. if (ExecWait(Patcher, "rred") == false)
  496. return _error->Errno("rred", "Patching via external rred failed");
  497. close(From);
  498. close(To);
  499. struct stat Buf;
  500. if (stat(Itm->DestFile.c_str(), &Buf) != 0)
  501. return _error->Errno("stat",_("Failed to stat"));
  502. To = open(Path.c_str(), O_RDONLY);
  503. Hash.AddFD(To, Buf.st_size);
  504. close(To);
  505. }
  506. /* Transfer the modification times from the patch file
  507. to be able to see in which state the file should be
  508. and use the access time from the "old" file */
  509. struct stat BufBase, BufPatch;
  510. if (stat(Path.c_str(),&BufBase) != 0 ||
  511. stat(lastPatchName.c_str(), &BufPatch) != 0)
  512. return _error->Errno("stat",_("Failed to stat"));
  513. struct utimbuf TimeBuf;
  514. TimeBuf.actime = BufBase.st_atime;
  515. TimeBuf.modtime = BufPatch.st_mtime;
  516. if (utime(Itm->DestFile.c_str(),&TimeBuf) != 0)
  517. return _error->Errno("utime",_("Failed to set modification time"));
  518. if (stat(Itm->DestFile.c_str(),&BufBase) != 0)
  519. return _error->Errno("stat",_("Failed to stat"));
  520. // return done
  521. Res.LastModified = BufBase.st_mtime;
  522. Res.Size = BufBase.st_size;
  523. Res.TakeHashes(Hash);
  524. URIDone(Res);
  525. return true;
  526. }
  527. /*}}}*/
  528. /** \brief Wrapper class for testing rred */ /*{{{*/
  529. class TestRredMethod : public RredMethod {
  530. public:
  531. /** \brief Run rred in debug test mode
  532. *
  533. * This method can be used to run the rred method outside
  534. * of the "normal" acquire environment for easier testing.
  535. *
  536. * \param base basename of all files involved in this rred test
  537. */
  538. bool Run(char const *base) {
  539. _config->CndSet("Debug::pkgAcquire::RRed", "true");
  540. FetchItem *test = new FetchItem;
  541. test->DestFile = base;
  542. return Fetch(test);
  543. }
  544. };
  545. /*}}}*/
  546. /** \brief Starter for the rred method (or its test method) {{{
  547. *
  548. * Used without parameters is the normal behavior for methods for
  549. * the APT acquire system. While this works great for the acquire system
  550. * it is very hard to test the method and therefore the method also
  551. * accepts one parameter which will switch it directly to debug test mode:
  552. * The test mode expects that if "Testfile" is given as parameter
  553. * the file "Testfile" should be ed-style patched with "Testfile.ed"
  554. * and will write the result to "Testfile.result".
  555. */
  556. int main(int argc, char *argv[]) {
  557. if (argc <= 1) {
  558. RredMethod Mth;
  559. return Mth.Run();
  560. } else {
  561. TestRredMethod Mth;
  562. bool result = Mth.Run(argv[1]);
  563. _error->DumpErrors();
  564. return result;
  565. }
  566. }
  567. /*}}}*/