143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
**
** 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;
db_begin_transaction();
db_prepare(&q, "SELECT id, %Q || pathname,"
" vfile.mrid, deleted, chnged, uuid"
" 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;
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);
if( oldChnged>=2 ){
chnged = oldChnged;
}else if( isDeleted || rid==0 ){
chnged = 1;
}
if( chnged!=1 ){
db_ephemeral_blob(&q, 5, &origCksum);
if( sha1sum_file(zName, &fileCksum) ){
blob_zero(&fileCksum);
}
if( blob_compare(&fileCksum, &origCksum) ){
chnged = 1;
}
blob_reset(&origCksum);
blob_reset(&fileCksum);
}
if( chnged!=oldChnged ){
db_multi_exec("UPDATE vfile SET chnged=%d WHERE id=%d", chnged, id);
}
|
>
|
>
>
>
>
>
>
>
>
>
|
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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
|
**
** 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"
" 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;
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);
}
if( chnged!=1 && (checkMtime==0 || currentMtime!=oldMtime) ){
db_ephemeral_blob(&q, 5, &origCksum);
if( sha1sum_file(zName, &fileCksum) ){
blob_zero(&fileCksum);
}
if( blob_compare(&fileCksum, &origCksum) ){
chnged = 1;
}else if( currentMtime!=oldMtime ){
db_multi_exec("UPDATE vfile SET mtime=%lld WHERE id=%d",
currentMtime, id);
}
blob_reset(&origCksum);
blob_reset(&fileCksum);
}
if( chnged!=oldChnged ){
db_multi_exec("UPDATE vfile SET chnged=%d WHERE id=%d", chnged, id);
}
|
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
id = db_column_int(&q, 0);
zName = db_column_text(&q, 1);
rid = db_column_int(&q, 2);
content_get(rid, &content);
if( verbose ) printf("%s\n", &zName[nRepos]);
blob_write_to_file(&content, zName);
}
db_finalize(&q);
}
/*
** Delete from the disk every file in VFILE vid.
*/
void vfile_unlink(int vid){
Stmt q;
db_prepare(&q, "SELECT %Q || pathname FROM vfile"
" WHERE vid=%d AND mrid>0", g.zLocalRoot, vid);
while( db_step(&q)==SQLITE_ROW ){
const char *zName;
zName = db_column_text(&q, 0);
unlink(zName);
}
db_finalize(&q);
}
/*
** Load into table SFILE the name of every ordinary file in
** the directory pPath. Omit the first nPrefix characters of
** of pPath when inserting into the SFILE table.
**
|
>
>
>
|
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
|
id = db_column_int(&q, 0);
zName = db_column_text(&q, 1);
rid = db_column_int(&q, 2);
content_get(rid, &content);
if( verbose ) printf("%s\n", &zName[nRepos]);
blob_write_to_file(&content, zName);
db_multi_exec("UPDATE vfile SET mtime=%lld WHERE id=%d",
file_mtime(zName), id);
}
db_finalize(&q);
}
/*
** Delete from the disk every file in VFILE vid.
*/
void vfile_unlink(int vid){
Stmt q;
db_prepare(&q, "SELECT %Q || pathname FROM vfile"
" WHERE vid=%d AND mrid>0", g.zLocalRoot, vid);
while( db_step(&q)==SQLITE_ROW ){
const char *zName;
zName = db_column_text(&q, 0);
unlink(zName);
}
db_finalize(&q);
db_multi_exec("UPDATE vfile SET mtime=NULL HERE vid=%d AND mrid>0", vid);
}
/*
** Load into table SFILE the name of every ordinary file in
** the directory pPath. Omit the first nPrefix characters of
** of pPath when inserting into the SFILE table.
**
|