Fossil

Check-in [d861fe77]
Login

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

Overview
Comment:If a file in the check-out is changed to something other than a file (like a directory) then raise an error when checking file signatures. Also fix a problem with the new multi-file "revert" command and add some comments to "update".
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d861fe77fbeb26a31c79d5ce39c1eeb0242e506d
User & Date: drh 2009-12-17 18:47:14
References
2009-12-18
00:05 Fixed ticket [816f1656]: Changing a file to a directory causes cksum error on commit plus 2 other changes artifact: 43171373 user: drh
Context
2009-12-17
21:22
Remove the --yes option from the "revert" command. In its place, make the "revert" opration undoable. check-in: 7b82a73b user: drh tags: trunk
18:47
If a file in the check-out is changed to something other than a file (like a directory) then raise an error when checking file signatures. Also fix a problem with the new multi-file "revert" command and add some comments to "update". check-in: d861fe77 user: drh tags: trunk
16:17
Add --nochanges and --verbose options to the "update" command. Tickets [4d6b7d4e1] and [7a27e10f1fe]. check-in: 1d9ebd9e user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/update.c.

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
...
299
300
301
302
303
304
305
306


307
308
309
310
311
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
327
  }
  db_finalize(&q);

  db_prepare(&q, 
    "SELECT fn, idv, ridv, idt, ridt, chnged FROM fv ORDER BY 1"
  );
  while( db_step(&q)==SQLITE_ROW ){
    const char *zName = db_column_text(&q, 0);
    int idv = db_column_int(&q, 1);
    int ridv = db_column_int(&q, 2);
    int idt = db_column_int(&q, 3);
    int ridt = db_column_int(&q, 4);
    int chnged = db_column_int(&q, 5);

    if( idv>0 && ridv==0 && idt>0 ){
      /* Conflict.  This file has been added to the current checkout
      ** but also exists in the target checkout.  Use the current version.
      */
      printf("CONFLICT %s\n", zName);
    }else if( idt>0 && idv==0 ){
................................................................................
void revert_cmd(void){
  char *zFile;
  const char *zRevision;
  Blob fname;
  Blob record;
  Blob ans;
  int i;
  int rid = 0, yesRevert;


  
  yesRevert = find_option("yes", "y", 0)!=0;
  zRevision = find_option("revision", "r", 1);
  verify_all_options();
  
  if( g.argc<3 ){
    usage("?OPTIONS FILE ...");
  }
  db_must_be_within_tree();

  for(i=2; i<g.argc; i++){  
    zFile = mprintf("%/", g.argv[i]);
    file_tree_name(zFile, &fname, 1);

    if( access(zFile, 0) ) yesRevert = 1;  
    if( yesRevert==0 ){
      char *prompt = mprintf("revert file %B? this will"
                             " destroy local changes (y/N)? ",
                             &fname);
      blob_zero(&ans);
      prompt_user(prompt, &ans);
      free( prompt );







|
|
|
|
|
|







 







|
>
>

|








|


>
|







162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
...
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
  }
  db_finalize(&q);

  db_prepare(&q, 
    "SELECT fn, idv, ridv, idt, ridt, chnged FROM fv ORDER BY 1"
  );
  while( db_step(&q)==SQLITE_ROW ){
    const char *zName = db_column_text(&q, 0);  /* The filename */
    int idv = db_column_int(&q, 1);             /* VFILE entry for current */
    int ridv = db_column_int(&q, 2);            /* RecordID for current */
    int idt = db_column_int(&q, 3);             /* VFILE entry for target */
    int ridt = db_column_int(&q, 4);            /* RecordID for target */
    int chnged = db_column_int(&q, 5);          /* Current is edited */

    if( idv>0 && ridv==0 && idt>0 ){
      /* Conflict.  This file has been added to the current checkout
      ** but also exists in the target checkout.  Use the current version.
      */
      printf("CONFLICT %s\n", zName);
    }else if( idt>0 && idv==0 ){
................................................................................
void revert_cmd(void){
  char *zFile;
  const char *zRevision;
  Blob fname;
  Blob record;
  Blob ans;
  int i;
  int rid = 0;
  int yesFlag;
  int yesRevert;
  
  yesFlag = find_option("yes", "y", 0)!=0;
  zRevision = find_option("revision", "r", 1);
  verify_all_options();
  
  if( g.argc<3 ){
    usage("?OPTIONS FILE ...");
  }
  db_must_be_within_tree();

  for(i=2; i<g.argc; i++){
    zFile = mprintf("%/", g.argv[i]);
    file_tree_name(zFile, &fname, 1);
    yesRevert = yesFlag;
    if( !yesRevert && access(zFile, 0) ) yesRevert = 1;  
    if( yesRevert==0 ){
      char *prompt = mprintf("revert file %B? this will"
                             " destroy local changes (y/N)? ",
                             &fname);
      blob_zero(&ans);
      prompt_user(prompt, &ans);
      free( prompt );

Changes to src/vfile.c.

141
142
143
144
145
146
147

148
149
150
151
152
153
154
...
164
165
166
167
168
169
170





171
172
173
174
175
176
177
...
191
192
193
194
195
196
197

198
199
200
201
202
203
204
** set VFILE.CHNGED on every folder that contains a file or folder 
** that has changed.
**
** If VFILE.DELETED is null or if VFILE.RID is zero, then we can assume
** the file has changed without having the check the on-disk image.
*/
void vfile_check_signature(int vid){

  Stmt q;
  Blob fileCksum, origCksum;
  int checkMtime = db_get_boolean("mtime-changes", 0);

  db_begin_transaction();
  db_prepare(&q, "SELECT id, %Q || pathname,"
                 "       vfile.mrid, deleted, chnged, uuid, mtime"
................................................................................

    id = db_column_int(&q, 0);
    zName = db_column_text(&q, 1);
    rid = db_column_int(&q, 2);
    isDeleted = db_column_int(&q, 3);
    oldChnged = db_column_int(&q, 4);
    oldMtime = db_column_int64(&q, 6);





    if( oldChnged>=2 ){
      chnged = oldChnged;
    }else if( isDeleted || rid==0 ){
      chnged = 1;
    }
    if( chnged!=1 ){
      currentMtime = file_mtime(zName);
................................................................................
      blob_reset(&fileCksum);
    }
    if( chnged!=oldChnged ){
      db_multi_exec("UPDATE vfile SET chnged=%d WHERE id=%d", chnged, id);
    }
  }
  db_finalize(&q);

  db_end_transaction(0);
}

/*
** Write all files from vid to the disk.  Or if vid==0 and id!=0
** write just the specific file where VFILE.ID=id.
*/







>







 







>
>
>
>
>







 







>







141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
...
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
** set VFILE.CHNGED on every folder that contains a file or folder 
** that has changed.
**
** If VFILE.DELETED is null or if VFILE.RID is zero, then we can assume
** the file has changed without having the check the on-disk image.
*/
void vfile_check_signature(int vid){
  int nErr = 0;
  Stmt q;
  Blob fileCksum, origCksum;
  int checkMtime = db_get_boolean("mtime-changes", 0);

  db_begin_transaction();
  db_prepare(&q, "SELECT id, %Q || pathname,"
                 "       vfile.mrid, deleted, chnged, uuid, mtime"
................................................................................

    id = db_column_int(&q, 0);
    zName = db_column_text(&q, 1);
    rid = db_column_int(&q, 2);
    isDeleted = db_column_int(&q, 3);
    oldChnged = db_column_int(&q, 4);
    oldMtime = db_column_int64(&q, 6);
    if( !file_isfile(zName) && file_size(zName)>=0 ){
      fossil_warning("not a ordinary file: %s", zName);
      nErr++;
      continue;
    }
    if( oldChnged>=2 ){
      chnged = oldChnged;
    }else if( isDeleted || rid==0 ){
      chnged = 1;
    }
    if( chnged!=1 ){
      currentMtime = file_mtime(zName);
................................................................................
      blob_reset(&fileCksum);
    }
    if( chnged!=oldChnged ){
      db_multi_exec("UPDATE vfile SET chnged=%d WHERE id=%d", chnged, id);
    }
  }
  db_finalize(&q);
  if( nErr ) fossil_fatal("abort due to prior errors");
  db_end_transaction(0);
}

/*
** Write all files from vid to the disk.  Or if vid==0 and id!=0
** write just the specific file where VFILE.ID=id.
*/