Diff
Not logged in

Differences From:

File src/wiki.c part of check-in [87a1a31d1d] - removed 2 remaining debug lines. Cleaned up help text. by stephan on 2008-05-14 20:02:10. [view]

To:

File src/wiki.c part of check-in [feee32d3af] - cleaned up error handling a bit, minor code style changes, s/import/commit/ by stephan on 2008-05-14 20:26:13. [view]

@@ -607,9 +607,9 @@
 
 /*
 ** COMMAND: wiki
 **
-** Usage: %fossil wiki (export|import|list) WikiName
+** Usage: %fossil wiki (export|commit|list) WikiName
 **
 ** Run various subcommands to fetch wiki entries.
 **
 **     %fossil wiki export WikiName
@@ -624,9 +624,9 @@
 **
 ** TODOs:
 **
 **     %fossil export WikiName ?UUID? ?-f outfile?
-**     %fossil import WikiName ?-f infile?
+**     %fossil commit WikiName ?-f infile?
 */
 void wiki_cmd(void){
   int n;
   db_find_and_open_repository(1);
@@ -647,19 +647,16 @@
     if( g.argc!=4 ){
       usage("export EntryName");
     }
     wname = g.argv[3];
-    //printf("exporting wiki entry %s\n",wname);
     rid = -1;
-
-    sql = mprintf("select x.rid from tag t, tagxref x "
-          "where x.tagid=t.tagid and t.tagname='wiki-%q' "
-      " order by x.mtime desc limit 1",
+    sql = mprintf("SELECT x.rid FROM tag t, tagxref x"
+      " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
+      " ORDER BY x.mtime DESC LIMIT 1",
       wname );
     db_prepare(&q, "%z", sql );
-    while( db_step(&q) == SQLITE_ROW ){
-      rid = db_column_int(&q,0);
-      break;
+    if( db_step(&q) == SQLITE_ROW ){
+      rid = db_column_int(&q,0);
     }
     db_finalize(&q);
     if( -1 == rid ){
       fprintf(stderr,"export error: wiki entry [%s] not found.\n",wname);
@@ -691,8 +688,14 @@
             ++it;
           }
           continue;
         }
+        if( ! *it )
+        {
+            fprintf(stderr,
+              "export reached end of input before finding a 'W' card.\n");
+            exit(1);
+        }
         ++it;
         while( (*it) && (*it != '\n') ){
           if( isspace(*it) ) { ++it; continue; }
           blob_append(&numbuf,it,1);
@@ -701,30 +704,39 @@
         if( '\n' == *it ) ++it;
         if( 0 == blob_size(&numbuf) ){
           fprintf(stderr,
           "export error: didn't find \"W NUMBER\" line in input!\n");
-          blob_zero(&buf);
-          blob_zero(&numbuf);
+          blob_reset(&buf);
+          blob_reset(&numbuf);
           exit(1);
         }
         len = atoi(blob_buffer(&numbuf));
-        //fprintf(stderr,"Writing %d (%s) bytes...\n",len,blob_buffer(&numbuf));
-        blob_zero(&numbuf);
+        //fprintf(stderr,"Writing %s (%d) bytes...\n",blob_buffer(&numbuf),len);
+        blob_reset(&numbuf);
+        if( ( (it - blob_buffer(&buf)) + len) > blob_size(&buf) ){
+          fprintf(stderr,
+            "export error: manifest data doesn't match actual data size!"
+            " Manifest says [%s (%d)] bytes.\n",
+            blob_buffer(&numbuf), len );
+          blob_reset(&buf);
+          blob_reset(&numbuf);
+          exit(1);
+        }
         fwrite(it,sizeof(char),len,stdout);
-        blob_zero(&buf);
+        blob_reset(&buf);
         return;
       }
     }
-    blob_zero(&buf);
+    blob_reset(&buf);
     return;
   }else
-  if( strncmp(g.argv[2],"import",n)==0 ){
+  if( strncmp(g.argv[2],"commit",n)==0 ){
     char *wname;
     if( g.argc!=4 ){
-      usage("import EntryName");
+      usage("commit EntryName");
     }
     wname = g.argv[3];
-    fprintf(stderr,"import not yet implemented.\n");
+    fprintf(stderr,"commit not yet implemented.\n");
     exit(1);
   }else
   if( strncmp(g.argv[2],"delete",n)==0 ){
     if( g.argc!=5 ){
@@ -750,7 +762,7 @@
   }
   return;
 
 wiki_cmd_usage:
-  usage("delete|export|import|list [EntryName]");
+  usage("delete|export|commit|list [EntryName]");
 }