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.
Commit
e9ffc4cdfba78b130cebc3814c503d9794947bfa
Parent
c1c18b72245b63b…
1 file changed
+14
-2
+14
-2
| --- src/vfile.c | ||
| +++ src/vfile.c | ||
| @@ -135,20 +135,26 @@ | ||
| 135 | 135 | ** set VFILE.CHNGED on every folder that contains a file or folder |
| 136 | 136 | ** that has changed. |
| 137 | 137 | ** |
| 138 | 138 | ** If VFILE.DELETED is null or if VFILE.RID is zero, then we can assume |
| 139 | 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. | |
| 140 | 146 | */ |
| 141 | 147 | void vfile_check_signature(int vid, int notFileIsFatal, int useSha1sum){ |
| 142 | 148 | int nErr = 0; |
| 143 | 149 | Stmt q; |
| 144 | 150 | Blob fileCksum, origCksum; |
| 145 | 151 | int checkMtime = useSha1sum==0 && db_get_boolean("mtime-changes", 1); |
| 146 | 152 | |
| 147 | 153 | db_begin_transaction(); |
| 148 | 154 | db_prepare(&q, "SELECT id, %Q || pathname," |
| 149 | - " vfile.mrid, deleted, chnged, uuid, mtime" | |
| 155 | + " vfile.mrid, deleted, chnged, uuid, size, mtime" | |
| 150 | 156 | " FROM vfile LEFT JOIN blob ON vfile.mrid=blob.rid" |
| 151 | 157 | " WHERE vid=%d ", g.zLocalRoot, vid); |
| 152 | 158 | while( db_step(&q)==SQLITE_ROW ){ |
| 153 | 159 | int id, rid, isDeleted; |
| 154 | 160 | const char *zName; |
| @@ -160,11 +166,11 @@ | ||
| 160 | 166 | id = db_column_int(&q, 0); |
| 161 | 167 | zName = db_column_text(&q, 1); |
| 162 | 168 | rid = db_column_int(&q, 2); |
| 163 | 169 | isDeleted = db_column_int(&q, 3); |
| 164 | 170 | oldChnged = db_column_int(&q, 4); |
| 165 | - oldMtime = db_column_int64(&q, 6); | |
| 171 | + oldMtime = db_column_int64(&q, 7); | |
| 166 | 172 | if( isDeleted ){ |
| 167 | 173 | chnged = 1; |
| 168 | 174 | }else if( !file_isfile(zName) && file_size(0)>=0 ){ |
| 169 | 175 | if( notFileIsFatal ){ |
| 170 | 176 | fossil_warning("not an ordinary file: %s", zName); |
| @@ -176,10 +182,16 @@ | ||
| 176 | 182 | }else if( rid==0 ){ |
| 177 | 183 | chnged = 1; |
| 178 | 184 | } |
| 179 | 185 | if( chnged!=1 ){ |
| 180 | 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 | + } | |
| 181 | 193 | } |
| 182 | 194 | if( chnged!=1 && (checkMtime==0 || currentMtime!=oldMtime) ){ |
| 183 | 195 | db_ephemeral_blob(&q, 5, &origCksum); |
| 184 | 196 | if( sha1sum_file(zName, &fileCksum) ){ |
| 185 | 197 | blob_zero(&fileCksum); |
| 186 | 198 |
| --- 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 |