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).

drh 2020-05-10 13:58 trunk
Commit 54a8243bf5e4b24b5760b29b42299bb7368b7b2f0058f2e1593597d9f92531e6
2 files changed +23 -5 +2 -1
+23 -5
--- src/etag.c
+++ src/etag.c
@@ -66,27 +66,45 @@
6666
#endif
6767
6868
static char zETag[33]; /* The generated ETag */
6969
static int iMaxAge = 0; /* The max-age parameter in the reply */
7070
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
+}
7190
7291
/*
7392
** Generate an ETag
7493
*/
7594
void etag_check(unsigned eFlags, const char *zHash){
76
- sqlite3_int64 mtime;
7795
const char *zIfNoneMatch;
7896
char zBuf[50];
7997
assert( zETag[0]==0 ); /* Only call this routine once! */
8098
8199
iMaxAge = 86400;
82100
md5sum_init();
83101
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);
88106
89107
if( (eFlags & ETAG_HASH)!=0 && zHash ){
90108
md5sum_step_text("hash: ", -1);
91109
md5sum_step_text(zHash, -1);
92110
md5sum_step_text("\n", 1);
93111
--- 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 @@
707707
708708
/*
709709
** Generate code to load a single javascript file
710710
*/
711711
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>
713713
}
714714
715715
/*
716716
** All extra JS files to load.
717717
*/
@@ -1259,10 +1259,11 @@
12591259
@ anonymous-adds = %s(find_anon_capabilities(zCap))<br />
12601260
}
12611261
@ g.zRepositoryName = %h(g.zRepositoryName)<br />
12621262
@ load_average() = %f(load_average())<br />
12631263
@ cgi_csrf_safe(0) = %d(cgi_csrf_safe(0))<br />
1264
+ @ fossil_exe_id() = %h(fossil_exe_id())<br />
12641265
@ <hr />
12651266
P("HTTP_USER_AGENT");
12661267
cgi_print_all(showAll, 0);
12671268
if( showAll && blob_size(&g.httpHeader)>0 ){
12681269
@ <hr />
12691270
--- 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

Keyboard Shortcuts

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