| ︙ | | | ︙ | |
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
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 = chnged = db_column_int(&q, 4);
oldMtime = db_column_int64(&q, 7);
origSize = db_column_int64(&q, 6);
currentSize = file_wd_size(zName);
currentMtime = file_wd_mtime(0);
#ifndef _WIN32
origPerm = db_column_int(&q, 8);
currentPerm = file_wd_perm(zName);
#endif
if( chnged==0 && (isDeleted || rid==0) ){
/* "fossil rm" or "fossil add" always change the file */
chnged = 1;
}else if( !file_wd_isfile_or_link(0) && currentSize>=0 ){
if( cksigFlags & CKSIG_ENOTFILE ){
fossil_warning("not an ordinary file: %s", zName);
nErr++;
}
chnged = 1;
}
if( origSize!=currentSize ){
|
|
|
|
|
|
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
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 = chnged = db_column_int(&q, 4);
oldMtime = db_column_int64(&q, 7);
origSize = db_column_int64(&q, 6);
currentSize = file_size(zName, RepoFILE);
currentMtime = file_mtime(0, 0);
#ifndef _WIN32
origPerm = db_column_int(&q, 8);
currentPerm = file_perm(zName, RepoFILE);
#endif
if( chnged==0 && (isDeleted || rid==0) ){
/* "fossil rm" or "fossil add" always change the file */
chnged = 1;
}else if( !file_isfile_or_link(0) && currentSize>=0 ){
if( cksigFlags & CKSIG_ENOTFILE ){
fossil_warning("not an ordinary file: %s", zName);
nErr++;
}
chnged = 1;
}
if( origSize!=currentSize ){
|
| ︙ | | | ︙ | |
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
if( !hname_verify_file_hash(zName, zUuid, nUuid) ) chnged = 1;
}
if( (cksigFlags & CKSIG_SETMTIME) && (chnged==0 || chnged==2 || chnged==4) ){
i64 desiredMtime;
if( mtime_of_manifest_file(vid,rid,&desiredMtime)==0 ){
if( currentMtime!=desiredMtime ){
file_set_mtime(zName, desiredMtime);
currentMtime = file_wd_mtime(zName);
}
}
}
#ifndef _WIN32
if( origPerm!=PERM_LNK && currentPerm==PERM_LNK ){
/* Changing to a symlink takes priority over all other change types. */
chnged = 7;
|
|
|
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
if( !hname_verify_file_hash(zName, zUuid, nUuid) ) chnged = 1;
}
if( (cksigFlags & CKSIG_SETMTIME) && (chnged==0 || chnged==2 || chnged==4) ){
i64 desiredMtime;
if( mtime_of_manifest_file(vid,rid,&desiredMtime)==0 ){
if( currentMtime!=desiredMtime ){
file_set_mtime(zName, desiredMtime);
currentMtime = file_mtime(zName, RepoFILE);
}
}
}
#ifndef _WIN32
if( origPerm!=PERM_LNK && currentPerm==PERM_LNK ){
/* Changing to a symlink takes priority over all other change types. */
chnged = 7;
|
| ︙ | | | ︙ | |
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
zName = db_column_text(&q, 1);
rid = db_column_int(&q, 2);
isExe = db_column_int(&q, 3);
isLink = db_column_int(&q, 4);
content_get(rid, &content);
if( file_is_the_same(&content, zName) ){
blob_reset(&content);
if( file_wd_setexe(zName, isExe) ){
db_multi_exec("UPDATE vfile SET mtime=%lld WHERE id=%d",
file_wd_mtime(zName), id);
}
continue;
}
if( promptFlag && file_wd_size(zName)>=0 ){
Blob ans;
char *zMsg;
char cReply;
zMsg = mprintf("overwrite %s (a=always/y/N)? ", zName);
prompt_user(zMsg, &ans);
free(zMsg);
cReply = blob_str(&ans)[0];
blob_reset(&ans);
if( cReply=='a' || cReply=='A' ){
promptFlag = 0;
} else if( cReply!='y' && cReply!='Y' ){
blob_reset(&content);
continue;
}
}
if( verbose ) fossil_print("%s\n", &zName[nRepos]);
if( file_wd_isdir(zName)==1 ){
/*TODO(dchest): remove directories? */
fossil_fatal("%s is directory, cannot overwrite", zName);
}
if( file_wd_size(zName)>=0 && (isLink || file_wd_islink(0)) ){
file_delete(zName);
}
if( isLink ){
symlink_create(blob_str(&content), zName);
}else{
blob_write_to_file(&content, zName);
}
file_wd_setexe(zName, isExe);
blob_reset(&content);
db_multi_exec("UPDATE vfile SET mtime=%lld WHERE id=%d",
file_wd_mtime(zName), id);
}
db_finalize(&q);
}
/*
** Delete from the disk every file in VFILE vid.
|
|
|
|
|
|
|
|
|
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
zName = db_column_text(&q, 1);
rid = db_column_int(&q, 2);
isExe = db_column_int(&q, 3);
isLink = db_column_int(&q, 4);
content_get(rid, &content);
if( file_is_the_same(&content, zName) ){
blob_reset(&content);
if( file_setexe(zName, isExe) ){
db_multi_exec("UPDATE vfile SET mtime=%lld WHERE id=%d",
file_mtime(zName, RepoFILE), id);
}
continue;
}
if( promptFlag && file_size(zName, RepoFILE)>=0 ){
Blob ans;
char *zMsg;
char cReply;
zMsg = mprintf("overwrite %s (a=always/y/N)? ", zName);
prompt_user(zMsg, &ans);
free(zMsg);
cReply = blob_str(&ans)[0];
blob_reset(&ans);
if( cReply=='a' || cReply=='A' ){
promptFlag = 0;
} else if( cReply!='y' && cReply!='Y' ){
blob_reset(&content);
continue;
}
}
if( verbose ) fossil_print("%s\n", &zName[nRepos]);
if( file_isdir(zName, RepoFILE)==1 ){
/*TODO(dchest): remove directories? */
fossil_fatal("%s is directory, cannot overwrite", zName);
}
if( file_size(zName, RepoFILE)>=0 && (isLink || file_islink(0)) ){
file_delete(zName);
}
if( isLink ){
symlink_create(blob_str(&content), zName);
}else{
blob_write_to_file(&content, zName);
}
file_setexe(zName, isExe);
blob_reset(&content);
db_multi_exec("UPDATE vfile SET mtime=%lld WHERE id=%d",
file_mtime(zName, RepoFILE), id);
}
db_finalize(&q);
}
/*
** Delete from the disk every file in VFILE vid.
|
| ︙ | | | ︙ | |
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
|
** "_FOSSIL_" or ".fslckout". Return true or false.
*/
int vfile_top_of_checkout(const char *zPath){
char *zFile;
int fileFound = 0;
zFile = mprintf("%s/_FOSSIL_", zPath);
fileFound = file_size(zFile)>=1024;
fossil_free(zFile);
if( !fileFound ){
zFile = mprintf("%s/.fslckout", zPath);
fileFound = file_size(zFile)>=1024;
fossil_free(zFile);
}
/* Check for ".fos" for legacy support. But the use of ".fos" as the
** per-checkout database name is deprecated. At some point, all support
** for ".fos" will end and this code should be removed. This comment
** added on 2012-02-04.
*/
if( !fileFound ){
zFile = mprintf("%s/.fos", zPath);
fileFound = file_size(zFile)>=1024;
fossil_free(zFile);
}
return fileFound;
}
/*
** Return TRUE if zFile is a temporary file. Return FALSE if not.
|
|
|
|
|
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
|
** "_FOSSIL_" or ".fslckout". Return true or false.
*/
int vfile_top_of_checkout(const char *zPath){
char *zFile;
int fileFound = 0;
zFile = mprintf("%s/_FOSSIL_", zPath);
fileFound = file_size(zFile, ExtFILE)>=1024;
fossil_free(zFile);
if( !fileFound ){
zFile = mprintf("%s/.fslckout", zPath);
fileFound = file_size(zFile, ExtFILE)>=1024;
fossil_free(zFile);
}
/* Check for ".fos" for legacy support. But the use of ".fos" as the
** per-checkout database name is deprecated. At some point, all support
** for ".fos" will end and this code should be removed. This comment
** added on 2012-02-04.
*/
if( !fileFound ){
zFile = mprintf("%s/.fos", zPath);
fileFound = file_size(zFile, ExtFILE)>=1024;
fossil_free(zFile);
}
return fileFound;
}
/*
** Return TRUE if zFile is a temporary file. Return FALSE if not.
|
| ︙ | | | ︙ | |
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
|
blob_appendf(pPath, "/%s", zUtf8);
zPath = blob_str(pPath);
if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
glob_match(pIgnore2, &zPath[nPrefix+1]) ){
/* do nothing */
#ifdef _DIRENT_HAVE_D_TYPE
}else if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
? (file_wd_isdir(zPath)==1) : (pEntry->d_type==DT_DIR) ){
#else
}else if( file_wd_isdir(zPath)==1 ){
#endif
if( !vfile_top_of_checkout(zPath) ){
vfile_scan(pPath, nPrefix, scanFlags, pIgnore1, pIgnore2);
}
#ifdef _DIRENT_HAVE_D_TYPE
}else if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
? (file_wd_isfile_or_link(zPath)) : (pEntry->d_type==DT_REG) ){
#else
}else if( file_wd_isfile_or_link(zPath) ){
#endif
if( (scanFlags & SCAN_TEMP)==0 || is_temporary_file(zUtf8) ){
db_bind_text(&ins, ":file", &zPath[nPrefix+1]);
if( scanFlags & SCAN_MTIME ){
db_bind_int(&ins, ":mtime", file_mtime(zPath));
}
if( scanFlags & SCAN_SIZE ){
db_bind_int(&ins, ":size", file_size(zPath));
}
db_step(&ins);
db_reset(&ins);
}
}
fossil_path_free(zUtf8);
blob_resize(pPath, origSize);
|
|
|
|
|
|
|
|
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
|
blob_appendf(pPath, "/%s", zUtf8);
zPath = blob_str(pPath);
if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
glob_match(pIgnore2, &zPath[nPrefix+1]) ){
/* do nothing */
#ifdef _DIRENT_HAVE_D_TYPE
}else if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
? (file_isdir(zPath, RepoFILE)==1) : (pEntry->d_type==DT_DIR) ){
#else
}else if( file_isdir(zPath, RepoFILE)==1 ){
#endif
if( !vfile_top_of_checkout(zPath) ){
vfile_scan(pPath, nPrefix, scanFlags, pIgnore1, pIgnore2);
}
#ifdef _DIRENT_HAVE_D_TYPE
}else if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
? (file_isfile_or_link(zPath)) : (pEntry->d_type==DT_REG) ){
#else
}else if( file_isfile_or_link(zPath) ){
#endif
if( (scanFlags & SCAN_TEMP)==0 || is_temporary_file(zUtf8) ){
db_bind_text(&ins, ":file", &zPath[nPrefix+1]);
if( scanFlags & SCAN_MTIME ){
db_bind_int(&ins, ":mtime", file_mtime(zPath, RepoFILE));
}
if( scanFlags & SCAN_SIZE ){
db_bind_int(&ins, ":size", file_size(zPath, RepoFILE));
}
db_step(&ins);
db_reset(&ins);
}
}
fossil_path_free(zUtf8);
blob_resize(pPath, origSize);
|
| ︙ | | | ︙ | |
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
|
blob_appendf(pPath, "/%s", zUtf8);
zPath = blob_str(pPath);
if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
glob_match(pIgnore2, &zPath[nPrefix+1]) ){
/* do nothing */
#ifdef _DIRENT_HAVE_D_TYPE
}else if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
? (file_wd_isdir(zPath)==1) : (pEntry->d_type==DT_DIR) ){
#else
}else if( file_wd_isdir(zPath)==1 ){
#endif
if( (scanFlags & SCAN_NESTED) || !vfile_top_of_checkout(zPath) ){
char *zSavePath = mprintf("%s", zPath);
int count = vfile_dir_scan(pPath, nPrefix, scanFlags, pIgnore1,
pIgnore2);
db_bind_text(&ins, ":file", &zSavePath[nPrefix+1]);
db_bind_int(&ins, ":count", count);
db_step(&ins);
db_reset(&ins);
fossil_free(zSavePath);
result += count; /* found X normal files? */
}
#ifdef _DIRENT_HAVE_D_TYPE
}else if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
? (file_wd_isfile_or_link(zPath)) : (pEntry->d_type==DT_REG) ){
#else
}else if( file_wd_isfile_or_link(zPath) ){
#endif
db_bind_text(&upd, ":file", zOrigPath);
db_step(&upd);
db_reset(&upd);
result++; /* found 1 normal file */
}
fossil_path_free(zUtf8);
|
|
|
|
|
|
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
|
blob_appendf(pPath, "/%s", zUtf8);
zPath = blob_str(pPath);
if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
glob_match(pIgnore2, &zPath[nPrefix+1]) ){
/* do nothing */
#ifdef _DIRENT_HAVE_D_TYPE
}else if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
? (file_isdir(zPath, RepoFILE)==1) : (pEntry->d_type==DT_DIR) ){
#else
}else if( file_isdir(zPath, RepoFILE)==1 ){
#endif
if( (scanFlags & SCAN_NESTED) || !vfile_top_of_checkout(zPath) ){
char *zSavePath = mprintf("%s", zPath);
int count = vfile_dir_scan(pPath, nPrefix, scanFlags, pIgnore1,
pIgnore2);
db_bind_text(&ins, ":file", &zSavePath[nPrefix+1]);
db_bind_int(&ins, ":count", count);
db_step(&ins);
db_reset(&ins);
fossil_free(zSavePath);
result += count; /* found X normal files? */
}
#ifdef _DIRENT_HAVE_D_TYPE
}else if( (pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK)
? (file_isfile_or_link(zPath)) : (pEntry->d_type==DT_REG) ){
#else
}else if( file_isfile_or_link(zPath) ){
#endif
db_bind_text(&upd, ":file", zOrigPath);
db_step(&upd);
db_reset(&upd);
result++; /* found 1 normal file */
}
fossil_path_free(zUtf8);
|
| ︙ | | | ︙ | |
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
|
while( db_step(&q)==SQLITE_ROW ){
const char *zFullpath = db_column_text(&q, 0);
const char *zName = db_column_text(&q, 1);
int isSelected = db_column_int(&q, 3);
if( isSelected ){
md5sum_step_text(zName, -1);
if( file_wd_islink(zFullpath) ){
/* Instead of file content, use link destination path */
Blob pathBuf;
sqlite3_snprintf(sizeof(zBuf), zBuf, " %ld\n",
blob_read_link(&pathBuf, zFullpath));
md5sum_step_text(zBuf, -1);
md5sum_step_text(blob_str(&pathBuf), -1);
|
|
|
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
|
while( db_step(&q)==SQLITE_ROW ){
const char *zFullpath = db_column_text(&q, 0);
const char *zName = db_column_text(&q, 1);
int isSelected = db_column_int(&q, 3);
if( isSelected ){
md5sum_step_text(zName, -1);
if( file_islink(zFullpath) ){
/* Instead of file content, use link destination path */
Blob pathBuf;
sqlite3_snprintf(sizeof(zBuf), zBuf, " %ld\n",
blob_read_link(&pathBuf, zFullpath));
md5sum_step_text(zBuf, -1);
md5sum_step_text(blob_str(&pathBuf), -1);
|
| ︙ | | | ︙ | |
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
|
char *write_blob_to_temp_file(Blob *pBlob){
sqlite3_uint64 r;
char *zOut = 0;
do{
sqlite3_free(zOut);
sqlite3_randomness(8, &r);
zOut = sqlite3_mprintf("file-%08llx", r);
}while( file_size(zOut)>=0 );
blob_write_to_file(pBlob, zOut);
return zOut;
}
/*
** Do a file-by-file comparison of the content of the repository and
** the working check-out on disk. Report any errors.
|
|
|
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
|
char *write_blob_to_temp_file(Blob *pBlob){
sqlite3_uint64 r;
char *zOut = 0;
do{
sqlite3_free(zOut);
sqlite3_randomness(8, &r);
zOut = sqlite3_mprintf("file-%08llx", r);
}while( file_size(zOut, ExtFILE)>=0 );
blob_write_to_file(pBlob, zOut);
return zOut;
}
/*
** Do a file-by-file comparison of the content of the repository and
** the working check-out on disk. Report any errors.
|
| ︙ | | | ︙ | |
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
|
md5sum_init();
while( db_step(&q)==SQLITE_ROW ){
const char *zFullpath = db_column_text(&q, 0);
const char *zName = db_column_text(&q, 1);
int rid = db_column_int(&q, 2);
blob_zero(&disk);
if( file_wd_islink(zFullpath) ){
rc = blob_read_link(&disk, zFullpath);
}else{
rc = blob_read_from_file(&disk, zFullpath);
}
if( rc<0 ){
fossil_print("ERROR: cannot read file [%s]\n", zFullpath);
blob_reset(&disk);
continue;
}
blob_zero(&repo);
content_get(rid, &repo);
|
<
<
<
|
<
|
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
|
md5sum_init();
while( db_step(&q)==SQLITE_ROW ){
const char *zFullpath = db_column_text(&q, 0);
const char *zName = db_column_text(&q, 1);
int rid = db_column_int(&q, 2);
blob_zero(&disk);
rc = blob_read_from_file(&disk, zFullpath, RepoFILE);
if( rc<0 ){
fossil_print("ERROR: cannot read file [%s]\n", zFullpath);
blob_reset(&disk);
continue;
}
blob_zero(&repo);
content_get(rid, &repo);
|
| ︙ | | | ︙ | |