r108384 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108383‎ | r108384 | r108385 >
Date:08:36, 9 January 2012
Author:ariel
Status:deferred
Tags:
Comment:
catch the case where the page id requested is less than first page id in file
Modified paths:
  • /branches/ariel/xmldumps-backup/mwbzutils/findpageidinbz2xml.c (modified) (history)

Diff [purge]

Index: branches/ariel/xmldumps-backup/mwbzutils/findpageidinbz2xml.c
@@ -41,7 +41,7 @@
4242 return(0);
4343 }
4444 else {
45 - fprintf(stderr,"failed to find the next frigging block marker\n");
 45+ fprintf(stderr,"Failed to find the next block marker\n");
4646 return(-1);
4747 }
4848 }
@@ -91,7 +91,7 @@
9292 if (match_base_expr[1].rm_so >=0) {
9393 hostname_length = match_base_expr[1].rm_eo - match_base_expr[1].rm_so;
9494 if (hostname_length > sizeof(hostname)) {
95 - fprintf(stderr,"very long hostname, giving up\n");
 95+ fprintf(stderr,"Very long hostname, giving up\n");
9696 break;
9797 }
9898 else {
@@ -339,7 +339,7 @@
340340 hopefully that doesn't take forever.
341341 */
342342 if (buffer_count>(20000000/BUFINSIZE) && rev_id) {
343 - if (verbose) fprintf(stderr, "passed cutoff for using api\n");
 343+ if (verbose) fprintf(stderr, "passed retries cutoff for using api\n");
344344 if (use_api) {
345345 page_id_found = get_page_id_from_rev_id_via_api(rev_id, fin);
346346 }
@@ -442,19 +442,23 @@
443443 /* if we're this close, we'll check this value and be done with it */
444444 if (iinfo->right_end -iinfo->left_end < (off_t)2) {
445445 new_position = iinfo->left_end;
 446+ if (verbose >= 2) fprintf(stderr," choosing new position (1) %"PRId64"\n",new_position);
446447 iinfo->right_end = iinfo->left_end;
447448 }
448449 else {
449450 if (iinfo->last_value < iinfo->value_wanted) {
450 - if (verbose >=2) fprintf(stderr,"resetting left end\n");
 451+ if (verbose >= 2) fprintf(stderr,"resetting left end\n");
451452 iinfo->left_end = iinfo->last_position;
452453 new_position = iinfo->last_position + interval;
 454+ if (verbose >= 2) fprintf(stderr," choosing new position (2) %"PRId64"\n",new_position);
453455 }
454456 /* iinfo->last_value > iinfo->value_wanted */
455457 else {
456458 if (verbose >=2) fprintf(stderr,"resetting right end\n");
457459 iinfo->right_end = iinfo->last_position;
458460 new_position = iinfo->last_position - interval;
 461+ if (new_position < 0) new_position = 0;
 462+ if (verbose >= 2) fprintf(stderr," choosing new position (3) %"PRId64"\n",new_position);
459463 }
460464 }
461465 res = get_first_page_id_after_offset(fin, new_position, pinfo, use_api, use_stub, stubfilename, verbose);
@@ -550,7 +554,7 @@
551555 else if (optc=='v')
552556 verbose++;
553557 else if (optc==-1) break;
554 - else usage(argv[0],"unknown option or other error\n");
 558+ else usage(argv[0],"Unknown option or other error\n");
555559 }
556560
557561 if (! filename || ! page_id) {
@@ -558,12 +562,12 @@
559563 }
560564
561565 if (page_id <1) {
562 - usage(argv[0], "please specify a page_id >= 1.\n");
 566+ usage(argv[0], "Please specify a page_id >= 1.\n");
563567 }
564568
565569 fin = open (filename, O_RDONLY);
566570 if (fin < 0) {
567 - fprintf(stderr,"failed to open file %s for read\n", argv[1]);
 571+ fprintf(stderr,"Failed to open file %s for read\n", argv[1]);
568572 exit(1);
569573 }
570574
@@ -585,7 +589,7 @@
586590 iinfo.last_position = (off_t)0;
587591 }
588592 else {
589 - fprintf(stderr,"failed to get anything useful from the beginning of the file even, bailing.\n");
 593+ fprintf(stderr,"Failed to find any page from start of file, exiting\n");
590594 exit(1);
591595 }
592596 if (pinfo.page_id == page_id) {
@@ -593,18 +597,26 @@
594598 fprintf(stdout,"position:%"PRId64" page_id:%d\n",pinfo.position, pinfo.page_id);
595599 exit(0);
596600 }
597 -
 601+ if (pinfo.page_id > page_id) {
 602+ fprintf(stderr,"Page requested is less than first page id in file\n");
 603+ exit(-1);
 604+ }
598605 while (1) {
599606 res = do_iteration(&iinfo, fin, &pinfo, use_api, use_stub, stubfile, verbose);
600 - /* things to check: bad return? interval is 0 bytes long? */
601 - if (iinfo.left_end == iinfo.right_end) {
602 - fprintf(stdout,"position:%"PRId64" page_id:%d\n",pinfo.position, pinfo.page_id);
603 - exit(0);
604 - }
605 - else if (res < 0) {
606 - fprintf(stderr,"broken and quitting\n");
 607+ if (res < 0) {
 608+ fprintf(stderr,"Error encountered during search\n");
607609 exit(-1);
608610 }
 611+ else if (iinfo.left_end == iinfo.right_end) {
 612+ if ( pinfo.page_id <= page_id) {
 613+ fprintf(stdout,"position:%"PRId64" page_id:%d\n",pinfo.position, pinfo.page_id);
 614+ exit(0);
 615+ }
 616+ else {
 617+ fprintf(stderr,"File does not contain requested page id\n");
 618+ exit(-1);
 619+ }
 620+ }
609621 }
610622 exit(0);
611623 }

Sign-offs

UserFlagDate
😂inspected16:39, 9 January 2012

Status & tagging log