Fossil SCM
Add the fossil_exe_id() internal interface that returns a unique hash that changes whenever Fossil is recompiled (more precisely, whenever the MANIFEST_UUID changes or the etag.c source file is recompiled).
Commit
54a8243bf5e4b24b5760b29b42299bb7368b7b2f0058f2e1593597d9f92531e6
Parent
7eaeceddc49be20…
2 files changed
+23
-5
+2
-1
+23
-5
| --- src/etag.c | ||
| +++ src/etag.c | ||
| @@ -66,27 +66,45 @@ | ||
| 66 | 66 | #endif |
| 67 | 67 | |
| 68 | 68 | static char zETag[33]; /* The generated ETag */ |
| 69 | 69 | static int iMaxAge = 0; /* The max-age parameter in the reply */ |
| 70 | 70 | static sqlite3_int64 iEtagMtime = 0; /* Last-Modified time */ |
| 71 | + | |
| 72 | +/* | |
| 73 | +** Return a hash that changes every time the Fossil source code is | |
| 74 | +** rebuilt. | |
| 75 | +** | |
| 76 | +** The current implementation is a hash of MANIFEST_UUID, __DATE__, and | |
| 77 | +** __TIME__. But this might change in the future if we think of a better | |
| 78 | +** way to compute an identifier that changes with each build. | |
| 79 | +*/ | |
| 80 | +const char *fossil_exe_id(void){ | |
| 81 | + static char zExecId[33]; | |
| 82 | + if( zExecId[0]==0 ){ | |
| 83 | + Blob x; | |
| 84 | + blob_init(&x, MANIFEST_UUID "," __DATE__ "," __TIME__, -1); | |
| 85 | + md5sum_blob(&x, &x); | |
| 86 | + memcpy(zExecId, x.aData, 32); | |
| 87 | + } | |
| 88 | + return zExecId; | |
| 89 | +} | |
| 71 | 90 | |
| 72 | 91 | /* |
| 73 | 92 | ** Generate an ETag |
| 74 | 93 | */ |
| 75 | 94 | void etag_check(unsigned eFlags, const char *zHash){ |
| 76 | - sqlite3_int64 mtime; | |
| 77 | 95 | const char *zIfNoneMatch; |
| 78 | 96 | char zBuf[50]; |
| 79 | 97 | assert( zETag[0]==0 ); /* Only call this routine once! */ |
| 80 | 98 | |
| 81 | 99 | iMaxAge = 86400; |
| 82 | 100 | md5sum_init(); |
| 83 | 101 | |
| 84 | - /* Always include the mtime of the executable as part of the hash */ | |
| 85 | - mtime = file_mtime(g.nameOfExe, ExtFILE); | |
| 86 | - sqlite3_snprintf(sizeof(zBuf),zBuf,"mtime: %lld\n", mtime); | |
| 87 | - md5sum_step_text(zBuf, -1); | |
| 102 | + /* Always include the executable ID as part of the hash */ | |
| 103 | + md5sum_step_text("exe-id: ", -1); | |
| 104 | + md5sum_step_text(fossil_exe_id(), -1); | |
| 105 | + md5sum_step_text("\n", 1); | |
| 88 | 106 | |
| 89 | 107 | if( (eFlags & ETAG_HASH)!=0 && zHash ){ |
| 90 | 108 | md5sum_step_text("hash: ", -1); |
| 91 | 109 | md5sum_step_text(zHash, -1); |
| 92 | 110 | md5sum_step_text("\n", 1); |
| 93 | 111 |
| --- src/etag.c | |
| +++ src/etag.c | |
| @@ -66,27 +66,45 @@ | |
| 66 | #endif |
| 67 | |
| 68 | static char zETag[33]; /* The generated ETag */ |
| 69 | static int iMaxAge = 0; /* The max-age parameter in the reply */ |
| 70 | static sqlite3_int64 iEtagMtime = 0; /* Last-Modified time */ |
| 71 | |
| 72 | /* |
| 73 | ** Generate an ETag |
| 74 | */ |
| 75 | void etag_check(unsigned eFlags, const char *zHash){ |
| 76 | sqlite3_int64 mtime; |
| 77 | const char *zIfNoneMatch; |
| 78 | char zBuf[50]; |
| 79 | assert( zETag[0]==0 ); /* Only call this routine once! */ |
| 80 | |
| 81 | iMaxAge = 86400; |
| 82 | md5sum_init(); |
| 83 | |
| 84 | /* Always include the mtime of the executable as part of the hash */ |
| 85 | mtime = file_mtime(g.nameOfExe, ExtFILE); |
| 86 | sqlite3_snprintf(sizeof(zBuf),zBuf,"mtime: %lld\n", mtime); |
| 87 | md5sum_step_text(zBuf, -1); |
| 88 | |
| 89 | if( (eFlags & ETAG_HASH)!=0 && zHash ){ |
| 90 | md5sum_step_text("hash: ", -1); |
| 91 | md5sum_step_text(zHash, -1); |
| 92 | md5sum_step_text("\n", 1); |
| 93 |
| --- src/etag.c | |
| +++ src/etag.c | |
| @@ -66,27 +66,45 @@ | |
| 66 | #endif |
| 67 | |
| 68 | static char zETag[33]; /* The generated ETag */ |
| 69 | static int iMaxAge = 0; /* The max-age parameter in the reply */ |
| 70 | static sqlite3_int64 iEtagMtime = 0; /* Last-Modified time */ |
| 71 | |
| 72 | /* |
| 73 | ** Return a hash that changes every time the Fossil source code is |
| 74 | ** rebuilt. |
| 75 | ** |
| 76 | ** The current implementation is a hash of MANIFEST_UUID, __DATE__, and |
| 77 | ** __TIME__. But this might change in the future if we think of a better |
| 78 | ** way to compute an identifier that changes with each build. |
| 79 | */ |
| 80 | const char *fossil_exe_id(void){ |
| 81 | static char zExecId[33]; |
| 82 | if( zExecId[0]==0 ){ |
| 83 | Blob x; |
| 84 | blob_init(&x, MANIFEST_UUID "," __DATE__ "," __TIME__, -1); |
| 85 | md5sum_blob(&x, &x); |
| 86 | memcpy(zExecId, x.aData, 32); |
| 87 | } |
| 88 | return zExecId; |
| 89 | } |
| 90 | |
| 91 | /* |
| 92 | ** Generate an ETag |
| 93 | */ |
| 94 | void etag_check(unsigned eFlags, const char *zHash){ |
| 95 | const char *zIfNoneMatch; |
| 96 | char zBuf[50]; |
| 97 | assert( zETag[0]==0 ); /* Only call this routine once! */ |
| 98 | |
| 99 | iMaxAge = 86400; |
| 100 | md5sum_init(); |
| 101 | |
| 102 | /* Always include the executable ID as part of the hash */ |
| 103 | md5sum_step_text("exe-id: ", -1); |
| 104 | md5sum_step_text(fossil_exe_id(), -1); |
| 105 | md5sum_step_text("\n", 1); |
| 106 | |
| 107 | if( (eFlags & ETAG_HASH)!=0 && zHash ){ |
| 108 | md5sum_step_text("hash: ", -1); |
| 109 | md5sum_step_text(zHash, -1); |
| 110 | md5sum_step_text("\n", 1); |
| 111 |
+2
-1
| --- src/style.c | ||
| +++ src/style.c | ||
| @@ -707,11 +707,11 @@ | ||
| 707 | 707 | |
| 708 | 708 | /* |
| 709 | 709 | ** Generate code to load a single javascript file |
| 710 | 710 | */ |
| 711 | 711 | void style_load_one_js_file(const char *zFile){ |
| 712 | - @ <script src='%R/builtin/%s(zFile)?id=%S(MANIFEST_UUID)'></script> | |
| 712 | + @ <script src='%R/builtin/%s(zFile)?id=%S(fossil_exe_id())'></script> | |
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | /* |
| 716 | 716 | ** All extra JS files to load. |
| 717 | 717 | */ |
| @@ -1259,10 +1259,11 @@ | ||
| 1259 | 1259 | @ anonymous-adds = %s(find_anon_capabilities(zCap))<br /> |
| 1260 | 1260 | } |
| 1261 | 1261 | @ g.zRepositoryName = %h(g.zRepositoryName)<br /> |
| 1262 | 1262 | @ load_average() = %f(load_average())<br /> |
| 1263 | 1263 | @ cgi_csrf_safe(0) = %d(cgi_csrf_safe(0))<br /> |
| 1264 | + @ fossil_exe_id() = %h(fossil_exe_id())<br /> | |
| 1264 | 1265 | @ <hr /> |
| 1265 | 1266 | P("HTTP_USER_AGENT"); |
| 1266 | 1267 | cgi_print_all(showAll, 0); |
| 1267 | 1268 | if( showAll && blob_size(&g.httpHeader)>0 ){ |
| 1268 | 1269 | @ <hr /> |
| 1269 | 1270 |
| --- src/style.c | |
| +++ src/style.c | |
| @@ -707,11 +707,11 @@ | |
| 707 | |
| 708 | /* |
| 709 | ** Generate code to load a single javascript file |
| 710 | */ |
| 711 | void style_load_one_js_file(const char *zFile){ |
| 712 | @ <script src='%R/builtin/%s(zFile)?id=%S(MANIFEST_UUID)'></script> |
| 713 | } |
| 714 | |
| 715 | /* |
| 716 | ** All extra JS files to load. |
| 717 | */ |
| @@ -1259,10 +1259,11 @@ | |
| 1259 | @ anonymous-adds = %s(find_anon_capabilities(zCap))<br /> |
| 1260 | } |
| 1261 | @ g.zRepositoryName = %h(g.zRepositoryName)<br /> |
| 1262 | @ load_average() = %f(load_average())<br /> |
| 1263 | @ cgi_csrf_safe(0) = %d(cgi_csrf_safe(0))<br /> |
| 1264 | @ <hr /> |
| 1265 | P("HTTP_USER_AGENT"); |
| 1266 | cgi_print_all(showAll, 0); |
| 1267 | if( showAll && blob_size(&g.httpHeader)>0 ){ |
| 1268 | @ <hr /> |
| 1269 |
| --- src/style.c | |
| +++ src/style.c | |
| @@ -707,11 +707,11 @@ | |
| 707 | |
| 708 | /* |
| 709 | ** Generate code to load a single javascript file |
| 710 | */ |
| 711 | void style_load_one_js_file(const char *zFile){ |
| 712 | @ <script src='%R/builtin/%s(zFile)?id=%S(fossil_exe_id())'></script> |
| 713 | } |
| 714 | |
| 715 | /* |
| 716 | ** All extra JS files to load. |
| 717 | */ |
| @@ -1259,10 +1259,11 @@ | |
| 1259 | @ anonymous-adds = %s(find_anon_capabilities(zCap))<br /> |
| 1260 | } |
| 1261 | @ g.zRepositoryName = %h(g.zRepositoryName)<br /> |
| 1262 | @ load_average() = %f(load_average())<br /> |
| 1263 | @ cgi_csrf_safe(0) = %d(cgi_csrf_safe(0))<br /> |
| 1264 | @ fossil_exe_id() = %h(fossil_exe_id())<br /> |
| 1265 | @ <hr /> |
| 1266 | P("HTTP_USER_AGENT"); |
| 1267 | cgi_print_all(showAll, 0); |
| 1268 | if( showAll && blob_size(&g.httpHeader)>0 ){ |
| 1269 | @ <hr /> |
| 1270 |