Fossil

Check-in [5d913409]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fixes to the unversioned file sync protocol.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | unversioned-files
Files: files | file ages | folders
SHA1:5d913409b70a013d6fc7bd2463026f2bc0c86bd2
User & Date: drh 2016-08-09 17:18:56
Context
2016-08-09
17:31
Another unversioned file sync fix. check-in: a6b66652 user: drh tags: unversioned-files
17:18
Fixes to the unversioned file sync protocol. check-in: 5d913409 user: drh tags: unversioned-files
15:29
More work on unversioned file sync. check-in: a3dcfe75 user: drh tags: unversioned-files
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/xfer.c.

368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
...
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
....
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
....
1958
1959
1960
1961
1962
1963
1964

1965
1966
1967
1968
1969
1970
1971
....
2032
2033
2034
2035
2036
2037
2038
2039

2040
2041
2042
2043
2044
2045
2046
      "REPLACE INTO unversioned(name, rcvid, mtime, hash, sz, content)"
      " VALUES(:name,:rcvid,:mtime,:hash,:sz,:content)"
    );
  }
  db_bind_text(&q, ":name", blob_str(&pXfer->aToken[1]));
  db_bind_int(&q, ":rcvid", g.rcvid);
  db_bind_int64(&q, ":mtime", mtime);
  db_bind_text(&q, ":hash", blob_str(&pXfer->aToken[5]));
  db_bind_int(&q, ":sz", blob_size(&content));
  if( !nullContent ){
    blob_compress(&content, &content);
    db_bind_blob(&q, ":content", &content);
  }
  db_step(&q);
  db_finalize(&q);
................................................................................
**
** If the noContent flag is set, omit the CONTENT and set the 0x0004 flag in FLAGS.
*/
static void send_unversioned_file(Xfer *pXfer, const char *zName, int noContent){
  Stmt q1;

  if( noContent ){
    db_static_prepare(&q1,
      "SELECT mtime, hash, encoding, sz FROM unversioned WHERE name=%Q",
      zName
    );
  }else{
    db_static_prepare(&q1,
      "SELECT mtime, hash, encoding, sz, content FROM unversioned WHERE name=%Q",
      zName
    );
  }
  if( db_step(&q1)==SQLITE_ROW ){
    sqlite3_int64 mtime = db_column_int64(&q1, 0);
    const char *zHash = db_column_text(&q1, 1);
................................................................................
    ** obsolete on the server.
    */
    if( uvDoPush ){
      Stmt uvq;
      assert( (syncFlags & SYNC_UNVERSIONED)!=0 );
      assert( uvStatus==2 );
      db_prepare(&uvq, "SELECT name, mtimeOnly FROM uv_tosend");
      while( db_step(&uvq) ){
        send_unversioned_file(&xfer, db_column_text(&uvq,0), db_column_int(&uvq,1));
        nCardSent++;
      }
      db_finalize(&uvq);
      uvDoPush = 0;
    }

................................................................................

      /*   uvfile NAME MTIME HASH SIZE FLAGS \n CONTENT
      **
      ** Accept an unversioned file from the client.
      */
      if( blob_eq(&xfer.aToken[0], "uvfile") ){
        xfer_accept_unversioned_file(&xfer, 1);

      }else

      /*   gimme UUID
      **
      ** Server is requesting a file.  If the file is a manifest, assume
      ** that the server will also want to know all of the content files
      ** associated with the manifest and send those too.
................................................................................
        const char *zName = blob_str(&xfer.aToken[1]);
        const char *zHash = blob_str(&xfer.aToken[3]);
        int iStatus;
        if( uvStatus==0 ) uvStatus = 2;
        iStatus = unversioned_status(zName, mtime, zHash);
        if( iStatus<=1 ){
          if( zHash[0]!='-' ){
            @ uvgimme %s(zName)

          }else if( iStatus==1 ){
            db_multi_exec(
               "UPDATE unversioned"
               "   SET mtime=%lld, hash=NULL, sz=0, encoding=0, content=NULL"
               " WHERE name=%Q", mtime, zName
            );
            db_unset("uv-hash", 0);







|







 







|




|







 







|







 







>







 







|
>







368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
...
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
....
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
....
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
....
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
      "REPLACE INTO unversioned(name, rcvid, mtime, hash, sz, content)"
      " VALUES(:name,:rcvid,:mtime,:hash,:sz,:content)"
    );
  }
  db_bind_text(&q, ":name", blob_str(&pXfer->aToken[1]));
  db_bind_int(&q, ":rcvid", g.rcvid);
  db_bind_int64(&q, ":mtime", mtime);
  db_bind_text(&q, ":hash", blob_str(pHash));
  db_bind_int(&q, ":sz", blob_size(&content));
  if( !nullContent ){
    blob_compress(&content, &content);
    db_bind_blob(&q, ":content", &content);
  }
  db_step(&q);
  db_finalize(&q);
................................................................................
**
** If the noContent flag is set, omit the CONTENT and set the 0x0004 flag in FLAGS.
*/
static void send_unversioned_file(Xfer *pXfer, const char *zName, int noContent){
  Stmt q1;

  if( noContent ){
    db_prepare(&q1,
      "SELECT mtime, hash, encoding, sz FROM unversioned WHERE name=%Q",
      zName
    );
  }else{
    db_prepare(&q1,
      "SELECT mtime, hash, encoding, sz, content FROM unversioned WHERE name=%Q",
      zName
    );
  }
  if( db_step(&q1)==SQLITE_ROW ){
    sqlite3_int64 mtime = db_column_int64(&q1, 0);
    const char *zHash = db_column_text(&q1, 1);
................................................................................
    ** obsolete on the server.
    */
    if( uvDoPush ){
      Stmt uvq;
      assert( (syncFlags & SYNC_UNVERSIONED)!=0 );
      assert( uvStatus==2 );
      db_prepare(&uvq, "SELECT name, mtimeOnly FROM uv_tosend");
      while( db_step(&uvq)==SQLITE_ROW ){
        send_unversioned_file(&xfer, db_column_text(&uvq,0), db_column_int(&uvq,1));
        nCardSent++;
      }
      db_finalize(&uvq);
      uvDoPush = 0;
    }

................................................................................

      /*   uvfile NAME MTIME HASH SIZE FLAGS \n CONTENT
      **
      ** Accept an unversioned file from the client.
      */
      if( blob_eq(&xfer.aToken[0], "uvfile") ){
        xfer_accept_unversioned_file(&xfer, 1);
        nArtifactRcvd++;
      }else

      /*   gimme UUID
      **
      ** Server is requesting a file.  If the file is a manifest, assume
      ** that the server will also want to know all of the content files
      ** associated with the manifest and send those too.
................................................................................
        const char *zName = blob_str(&xfer.aToken[1]);
        const char *zHash = blob_str(&xfer.aToken[3]);
        int iStatus;
        if( uvStatus==0 ) uvStatus = 2;
        iStatus = unversioned_status(zName, mtime, zHash);
        if( iStatus<=1 ){
          if( zHash[0]!='-' ){
            blob_appendf(xfer.pOut, "uvgimme %s\n", zName);
            nCardSent++;
          }else if( iStatus==1 ){
            db_multi_exec(
               "UPDATE unversioned"
               "   SET mtime=%lld, hash=NULL, sz=0, encoding=0, content=NULL"
               " WHERE name=%Q", mtime, zName
            );
            db_unset("uv-hash", 0);