Fossil SCM

A change in the size of a file shows definitively that the file has been modified. So if the file size has changed, there is no need to do a full SHA1 hash of the file to verify that it has changed.

drh 2010-12-22 18:10 trunk
Commit e9ffc4cdfba78b130cebc3814c503d9794947bfa
1 file changed +14 -2
+14 -2
--- src/vfile.c
+++ src/vfile.c
@@ -135,20 +135,26 @@
135135
** set VFILE.CHNGED on every folder that contains a file or folder
136136
** that has changed.
137137
**
138138
** If VFILE.DELETED is null or if VFILE.RID is zero, then we can assume
139139
** the file has changed without having the check the on-disk image.
140
+**
141
+** If the size of the file has changed, then we assume that it has
142
+** changed. If the mtime of the file has not changed and useSha1sum is false
143
+** and the mtime-changes setting is true (the default) then we assume that
144
+** the file has not changed. If the mtime has changed, we go ahead and
145
+** double-check that the file has changed by looking at its SHA1 sum.
140146
*/
141147
void vfile_check_signature(int vid, int notFileIsFatal, int useSha1sum){
142148
int nErr = 0;
143149
Stmt q;
144150
Blob fileCksum, origCksum;
145151
int checkMtime = useSha1sum==0 && db_get_boolean("mtime-changes", 1);
146152
147153
db_begin_transaction();
148154
db_prepare(&q, "SELECT id, %Q || pathname,"
149
- " vfile.mrid, deleted, chnged, uuid, mtime"
155
+ " vfile.mrid, deleted, chnged, uuid, size, mtime"
150156
" FROM vfile LEFT JOIN blob ON vfile.mrid=blob.rid"
151157
" WHERE vid=%d ", g.zLocalRoot, vid);
152158
while( db_step(&q)==SQLITE_ROW ){
153159
int id, rid, isDeleted;
154160
const char *zName;
@@ -160,11 +166,11 @@
160166
id = db_column_int(&q, 0);
161167
zName = db_column_text(&q, 1);
162168
rid = db_column_int(&q, 2);
163169
isDeleted = db_column_int(&q, 3);
164170
oldChnged = db_column_int(&q, 4);
165
- oldMtime = db_column_int64(&q, 6);
171
+ oldMtime = db_column_int64(&q, 7);
166172
if( isDeleted ){
167173
chnged = 1;
168174
}else if( !file_isfile(zName) && file_size(0)>=0 ){
169175
if( notFileIsFatal ){
170176
fossil_warning("not an ordinary file: %s", zName);
@@ -176,10 +182,16 @@
176182
}else if( rid==0 ){
177183
chnged = 1;
178184
}
179185
if( chnged!=1 ){
180186
currentMtime = file_mtime(0);
187
+ i64 origSize = db_column_int64(&q, 6);
188
+ if( origSize!=file_size(0) ){
189
+ /* A file size change is definitive - the file has changed. No
190
+ ** need to check the sha1sum */
191
+ chnged = 1;
192
+ }
181193
}
182194
if( chnged!=1 && (checkMtime==0 || currentMtime!=oldMtime) ){
183195
db_ephemeral_blob(&q, 5, &origCksum);
184196
if( sha1sum_file(zName, &fileCksum) ){
185197
blob_zero(&fileCksum);
186198
--- src/vfile.c
+++ src/vfile.c
@@ -135,20 +135,26 @@
135 ** set VFILE.CHNGED on every folder that contains a file or folder
136 ** that has changed.
137 **
138 ** If VFILE.DELETED is null or if VFILE.RID is zero, then we can assume
139 ** the file has changed without having the check the on-disk image.
 
 
 
 
 
 
140 */
141 void vfile_check_signature(int vid, int notFileIsFatal, int useSha1sum){
142 int nErr = 0;
143 Stmt q;
144 Blob fileCksum, origCksum;
145 int checkMtime = useSha1sum==0 && db_get_boolean("mtime-changes", 1);
146
147 db_begin_transaction();
148 db_prepare(&q, "SELECT id, %Q || pathname,"
149 " vfile.mrid, deleted, chnged, uuid, mtime"
150 " FROM vfile LEFT JOIN blob ON vfile.mrid=blob.rid"
151 " WHERE vid=%d ", g.zLocalRoot, vid);
152 while( db_step(&q)==SQLITE_ROW ){
153 int id, rid, isDeleted;
154 const char *zName;
@@ -160,11 +166,11 @@
160 id = db_column_int(&q, 0);
161 zName = db_column_text(&q, 1);
162 rid = db_column_int(&q, 2);
163 isDeleted = db_column_int(&q, 3);
164 oldChnged = db_column_int(&q, 4);
165 oldMtime = db_column_int64(&q, 6);
166 if( isDeleted ){
167 chnged = 1;
168 }else if( !file_isfile(zName) && file_size(0)>=0 ){
169 if( notFileIsFatal ){
170 fossil_warning("not an ordinary file: %s", zName);
@@ -176,10 +182,16 @@
176 }else if( rid==0 ){
177 chnged = 1;
178 }
179 if( chnged!=1 ){
180 currentMtime = file_mtime(0);
 
 
 
 
 
 
181 }
182 if( chnged!=1 && (checkMtime==0 || currentMtime!=oldMtime) ){
183 db_ephemeral_blob(&q, 5, &origCksum);
184 if( sha1sum_file(zName, &fileCksum) ){
185 blob_zero(&fileCksum);
186
--- src/vfile.c
+++ src/vfile.c
@@ -135,20 +135,26 @@
135 ** set VFILE.CHNGED on every folder that contains a file or folder
136 ** that has changed.
137 **
138 ** If VFILE.DELETED is null or if VFILE.RID is zero, then we can assume
139 ** the file has changed without having the check the on-disk image.
140 **
141 ** If the size of the file has changed, then we assume that it has
142 ** changed. If the mtime of the file has not changed and useSha1sum is false
143 ** and the mtime-changes setting is true (the default) then we assume that
144 ** the file has not changed. If the mtime has changed, we go ahead and
145 ** double-check that the file has changed by looking at its SHA1 sum.
146 */
147 void vfile_check_signature(int vid, int notFileIsFatal, int useSha1sum){
148 int nErr = 0;
149 Stmt q;
150 Blob fileCksum, origCksum;
151 int checkMtime = useSha1sum==0 && db_get_boolean("mtime-changes", 1);
152
153 db_begin_transaction();
154 db_prepare(&q, "SELECT id, %Q || pathname,"
155 " vfile.mrid, deleted, chnged, uuid, size, mtime"
156 " FROM vfile LEFT JOIN blob ON vfile.mrid=blob.rid"
157 " WHERE vid=%d ", g.zLocalRoot, vid);
158 while( db_step(&q)==SQLITE_ROW ){
159 int id, rid, isDeleted;
160 const char *zName;
@@ -160,11 +166,11 @@
166 id = db_column_int(&q, 0);
167 zName = db_column_text(&q, 1);
168 rid = db_column_int(&q, 2);
169 isDeleted = db_column_int(&q, 3);
170 oldChnged = db_column_int(&q, 4);
171 oldMtime = db_column_int64(&q, 7);
172 if( isDeleted ){
173 chnged = 1;
174 }else if( !file_isfile(zName) && file_size(0)>=0 ){
175 if( notFileIsFatal ){
176 fossil_warning("not an ordinary file: %s", zName);
@@ -176,10 +182,16 @@
182 }else if( rid==0 ){
183 chnged = 1;
184 }
185 if( chnged!=1 ){
186 currentMtime = file_mtime(0);
187 i64 origSize = db_column_int64(&q, 6);
188 if( origSize!=file_size(0) ){
189 /* A file size change is definitive - the file has changed. No
190 ** need to check the sha1sum */
191 chnged = 1;
192 }
193 }
194 if( chnged!=1 && (checkMtime==0 || currentMtime!=oldMtime) ){
195 db_ephemeral_blob(&q, 5, &origCksum);
196 if( sha1sum_file(zName, &fileCksum) ){
197 blob_zero(&fileCksum);
198

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button