| ︙ | | | ︙ | |
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
#define CKSIG_ENOTFILE 0x001 /* non-file FS objects throw an error */
#define CKSIG_SHA1 0x002 /* Verify file content using sha1sum */
#define CKSIG_SETMTIME 0x004 /* Set mtime to last check-out time */
#endif /* INTERFACE */
/*
** Look at every VFILE entry with the given vid and update
** VFILE.CHNGED field according to whether or not
** the file has changed. 0 means no change. 1 means edited. 2 means
** the file has changed due to a merge. 3 means the file was added
** by a merge.
**
** If VFILE.DELETED is true or if VFILE.RID is zero, then the file was either
** removed from configuration management via "fossil rm" or added via
** "fossil add", respectively, and in both cases we always know that
** the file has changed without having the check the size, mtime,
** or on-disk content.
**
|
|
|
|
>
|
|
>
>
>
>
>
>
|
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
#define CKSIG_ENOTFILE 0x001 /* non-file FS objects throw an error */
#define CKSIG_SHA1 0x002 /* Verify file content using sha1sum */
#define CKSIG_SETMTIME 0x004 /* Set mtime to last check-out time */
#endif /* INTERFACE */
/*
** Look at every VFILE entry with the given vid and update VFILE.CHNGED field
** according to whether or not the file has changed.
** - 0 means no change.
** - 1 means edited.
** - 2 means changed due to a merge.
** - 3 means added by a merge.
** - 4 means changed due to an integrate merge.
** - 5 means added by an integrate merge.
** - 6 means became executable but has unmodified contents.
** - 7 means became a symlink whose target equals its old contents.
** - 8 means lost executable status but has unmodified contents.
** - 9 means lost symlink status and has contents equal to its old target.
**
** If VFILE.DELETED is true or if VFILE.RID is zero, then the file was either
** removed from configuration management via "fossil rm" or added via
** "fossil add", respectively, and in both cases we always know that
** the file has changed without having the check the size, mtime,
** or on-disk content.
**
|
| ︙ | | | ︙ | |
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
Stmt q;
Blob fileCksum, origCksum;
int useMtime = (cksigFlags & CKSIG_SHA1)==0
&& db_get_boolean("mtime-changes", 1);
db_begin_transaction();
db_prepare(&q, "SELECT id, %Q || pathname,"
" vfile.mrid, deleted, chnged, uuid, size, mtime"
" FROM vfile LEFT JOIN blob ON vfile.mrid=blob.rid"
" WHERE vid=%d ", g.zLocalRoot, vid);
while( db_step(&q)==SQLITE_ROW ){
int id, rid, isDeleted;
const char *zName;
int chnged = 0;
int oldChnged;
i64 oldMtime;
i64 currentMtime;
i64 origSize;
i64 currentSize;
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);
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++;
|
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
Stmt q;
Blob fileCksum, origCksum;
int useMtime = (cksigFlags & CKSIG_SHA1)==0
&& db_get_boolean("mtime-changes", 1);
db_begin_transaction();
db_prepare(&q, "SELECT id, %Q || pathname,"
" vfile.mrid, deleted, chnged, uuid, size, mtime,"
" CASE WHEN isexe THEN %d WHEN islink THEN %d ELSE %d END"
" FROM vfile LEFT JOIN blob ON vfile.mrid=blob.rid"
" WHERE vid=%d ", g.zLocalRoot, PERM_EXE, PERM_LNK, PERM_REG,
vid);
while( db_step(&q)==SQLITE_ROW ){
int id, rid, isDeleted;
const char *zName;
int chnged = 0;
int oldChnged;
int origPerm;
int currentPerm;
i64 oldMtime;
i64 currentMtime;
i64 origSize;
i64 currentSize;
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);
origPerm = db_column_int(&q, 8);
currentPerm = file_wd_perm(zName);
#if !defined(_WIN32)
/*
** Windows doesn't have an execute bit, but it does support symlinks;
** if the current permission is not a symlink, make it the original
** permission (EXE or REG); if it is a symlink, leave it alone
*/
if( currentPerm != PERM_LNK ){
currentPerm = origPerm;
}
#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++;
|
| ︙ | | | ︙ | |
250
251
252
253
254
255
256
257
258
259
260
261
262
263
|
if( mtime_of_manifest_file(vid,rid,&desiredMtime)==0 ){
if( currentMtime!=desiredMtime ){
file_set_mtime(zName, desiredMtime);
currentMtime = file_wd_mtime(zName);
}
}
}
if( currentMtime!=oldMtime || chnged!=oldChnged ){
db_multi_exec("UPDATE vfile SET mtime=%lld, chnged=%d WHERE id=%d",
currentMtime, chnged, id);
}
}
db_finalize(&q);
if( nErr ) fossil_fatal("abort due to prior errors");
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
if( mtime_of_manifest_file(vid,rid,&desiredMtime)==0 ){
if( currentMtime!=desiredMtime ){
file_set_mtime(zName, desiredMtime);
currentMtime = file_wd_mtime(zName);
}
}
}
#if !defined(_WIN32) || 1
/*
** as written this block was only designed to work on posix systems;
** I can see no reason why it shouldn't work on Windows as well
** in the winsymlink branch (after making a couple of other minor
** tweak), so I've modified the condition to be "not windows or true";
** the conditional can be removed when / if this is ever merged
** to trunk, but I think it serves as a handy reminder for now
** that this code might be "special"
*/
if( chnged==0 || chnged==6 || chnged==7 || chnged==8 || chnged==9 ){
if( origPerm == currentPerm ){
chnged = 0;
}else if( currentPerm == PERM_EXE ){
chnged = 6;
}else if( currentPerm == PERM_LNK ){
chnged = 7;
}else if( origPerm == PERM_EXE ){
chnged = 8;
}else if( origPerm == PERM_LNK ){
chnged = 9;
}
}
#endif
if( currentMtime!=oldMtime || chnged!=oldChnged ){
db_multi_exec("UPDATE vfile SET mtime=%lld, chnged=%d WHERE id=%d",
currentMtime, chnged, id);
}
}
db_finalize(&q);
if( nErr ) fossil_fatal("abort due to prior errors");
|
| ︙ | | | ︙ | |
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
|
** Returns the total number of files found.
*/
int vfile_dir_scan(
Blob *pPath, /* Base directory to be scanned */
int nPrefix, /* Number of bytes in base directory name */
unsigned scanFlags, /* Zero or more SCAN_xxx flags */
Glob *pIgnore1, /* Do not add directories that match this GLOB */
Glob *pIgnore2, /* Omit directories matching this GLOB too */
Glob *pIgnore3 /* Omit directories matching this GLOB too */
){
int result = 0;
DIR *d;
int origSize;
struct dirent *pEntry;
int skipAll = 0;
static Stmt ins;
static Stmt upd;
static int depth = 0;
void *zNative;
origSize = blob_size(pPath);
if( pIgnore1 || pIgnore2 || pIgnore3 ){
blob_appendf(pPath, "/");
if( glob_match(pIgnore1, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
if( glob_match(pIgnore2, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
if( glob_match(pIgnore3, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
blob_resize(pPath, origSize);
}
if( skipAll ) return result;
if( depth==0 ){
db_multi_exec("DROP TABLE IF EXISTS dscan_temp;"
"CREATE TEMP TABLE dscan_temp("
|
|
<
|
<
|
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
|
** Returns the total number of files found.
*/
int vfile_dir_scan(
Blob *pPath, /* Base directory to be scanned */
int nPrefix, /* Number of bytes in base directory name */
unsigned scanFlags, /* Zero or more SCAN_xxx flags */
Glob *pIgnore1, /* Do not add directories that match this GLOB */
Glob *pIgnore2 /* Omit directories matching this GLOB too */
){
int result = 0;
DIR *d;
int origSize;
struct dirent *pEntry;
int skipAll = 0;
static Stmt ins;
static Stmt upd;
static int depth = 0;
void *zNative;
origSize = blob_size(pPath);
if( pIgnore1 || pIgnore2 ){
blob_appendf(pPath, "/");
if( glob_match(pIgnore1, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
if( glob_match(pIgnore2, &blob_str(pPath)[nPrefix+1]) ) skipAll = 1;
blob_resize(pPath, origSize);
}
if( skipAll ) return result;
if( depth==0 ){
db_multi_exec("DROP TABLE IF EXISTS dscan_temp;"
"CREATE TEMP TABLE dscan_temp("
|
| ︙ | | | ︙ | |
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
|
if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
}
zOrigPath = mprintf("%s", blob_str(pPath));
zUtf8 = fossil_filename_to_utf8(pEntry->d_name);
blob_appendf(pPath, "/%s", zUtf8);
zPath = blob_str(pPath);
if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
glob_match(pIgnore2, &zPath[nPrefix+1]) ||
glob_match(pIgnore3, &zPath[nPrefix+1]) ){
/* do nothing */
#if defined(_DIRENT_HAVE_D_TYPE) && !defined(_WIN32)
}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, pIgnore3);
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? */
}
|
|
<
|
|
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
|
if( pEntry->d_name[1]=='.' && pEntry->d_name[2]==0 ) continue;
}
zOrigPath = mprintf("%s", blob_str(pPath));
zUtf8 = fossil_filename_to_utf8(pEntry->d_name);
blob_appendf(pPath, "/%s", zUtf8);
zPath = blob_str(pPath);
if( glob_match(pIgnore1, &zPath[nPrefix+1]) ||
glob_match(pIgnore2, &zPath[nPrefix+1]) ){
/* do nothing */
#if defined(_DIRENT_HAVE_D_TYPE) && !defined(_WIN32)
}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? */
}
|
| ︙ | | | ︙ | |
917
918
919
920
921
922
923
924
925
926
927
928
929
930
|
}
manifest_destroy(pManifest);
md5sum_finish(pOut);
}
/*
** COMMAND: test-agg-cksum
*/
void test_agg_cksum_cmd(void){
int vid;
Blob hash, hash2;
db_must_be_within_tree();
vid = db_lget_int("checkout", 0);
vfile_aggregate_checksum_disk(vid, &hash);
|
>
>
>
>
>
|
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
|
}
manifest_destroy(pManifest);
md5sum_finish(pOut);
}
/*
** COMMAND: test-agg-cksum
**
** Display the aggregate checksum for content computed in several
** different ways. The aggregate checksum is used during "fossil commit"
** to double-check that the information about to be committed to the
** repository exactly matches the information currently in the check-out.
*/
void test_agg_cksum_cmd(void){
int vid;
Blob hash, hash2;
db_must_be_within_tree();
vid = db_lget_int("checkout", 0);
vfile_aggregate_checksum_disk(vid, &hash);
|
| ︙ | | | ︙ | |