Rename etc dump to bakedres dump

This commit is contained in:
kamkow1
2025-06-26 00:07:12 +02:00
parent 632d731118
commit d9071a4947
6 changed files with 50 additions and 50 deletions

View File

@ -5,7 +5,7 @@ how the code is architectured and some cool tricks that are used throughout the
## Our "engine" ## Our "engine"
![the engine](/etc/tmoa-engine.jpg) ![the engine](/bakedres/tmoa-engine.jpg)
This image is a joke, obviously. This image is a joke, obviously.
@ -133,7 +133,7 @@ void *route_thread_function(void *param)
// Unparsable HTTP request // Unparsable HTTP request
} }
if (mg_match(http_msg.uri, mg_str("/etc/*"), nil)) { if (mg_match(http_msg.uri, mg_str("/bakedres/*"), nil)) {
// Request for static resource // Request for static resource
} }
@ -147,7 +147,7 @@ this functionality comes with mongoose built-in. God bless you mongoose!
## Dynamic pages and static assets. ## Dynamic pages and static assets.
![the assets](/etc/tmoa-garbage.jpg) ![the assets](/bakedres/tmoa-garbage.jpg)
Let's stop here now and talk about something different entirely (dont' worry, we'll come back later). Let's stop here now and talk about something different entirely (dont' worry, we'll come back later).
I'd like to show you how assets/pages are implemented in aboba, so we get the whole picture. I'd like to show you how assets/pages are implemented in aboba, so we get the whole picture.

64
main.c
View File

@ -18,7 +18,7 @@
#include "locked.h" #include "locked.h"
static locked(Route *) route_hashtable = locked_init(nil); static locked(Route *) route_hashtable = locked_init(nil);
static locked(char *) etc_dump_path = locked_init(nil); static locked(char *) baked_dump_path = locked_init(nil);
void run_in_thread(void *(*f)(void *), void *p) void run_in_thread(void *(*f)(void *), void *p)
{ {
@ -49,7 +49,7 @@ void *route_thread_function(void *param)
return nil; return nil;
} }
if (mg_match(http_msg.uri, mg_str("/etc/*"), nil)) { if (mg_match(http_msg.uri, mg_str("/bakedres/*"), nil)) {
Route_Result result = {0}; Route_Result result = {0};
result.type = ROUTE_RESULT_STATIC; result.type = ROUTE_RESULT_STATIC;
@ -60,9 +60,9 @@ void *route_thread_function(void *param)
char *file = basename(p); char *file = basename(p);
char *full_path = malloc(PATH_MAX); char *full_path = malloc(PATH_MAX);
lockx(&etc_dump_path); lockx(&baked_dump_path);
snprintf(full_path, PATH_MAX, "%s/%s", etc_dump_path.value, file); snprintf(full_path, PATH_MAX, "%s/%s", baked_dump_path.value, file);
unlockx(&etc_dump_path); unlockx(&baked_dump_path);
sb_append_nstr(&result.body, full_path); sb_append_nstr(&result.body, full_path);
sb_finish(&result.body); sb_finish(&result.body);
@ -165,23 +165,23 @@ void free_route_hashtable(void)
unlockx(&route_hashtable); unlockx(&route_hashtable);
} }
char *init_etc_dump(void) char *init_baked_dump(void)
{ {
char template[] = "/tmp/aboba-etc.XXXXXX"; char template[] = "/tmp/aboba-bakedres.XXXXXX";
char *etc_dump1 = mkdtemp(template); char *baked_dump1 = mkdtemp(template);
char *etc_dump = malloc(strlen(etc_dump1)+1); char *baked_dump = malloc(strlen(baked_dump1)+1);
strcpy(etc_dump, etc_dump1); strcpy(baked_dump, baked_dump1);
if (etc_dump == nil) { if (baked_dump == nil) {
LOGE("Could not create etc dump\n"); LOGE("Could not create bakedres dump\n");
return nil; return nil;
} }
LOGI("etc dump dir is %s\n", etc_dump); LOGI("bakedres dump dir is %s\n", baked_dump);
return etc_dump; return baked_dump;
} }
int etc_dump_rm_cb(const char *path, int baked_dump_rm_cb(const char *path,
discard const struct stat *st, discard const struct stat *st,
discard int type, discard int type,
discard struct FTW *ftw) discard struct FTW *ftw)
@ -189,14 +189,14 @@ int etc_dump_rm_cb(const char *path,
return remove(path); return remove(path);
} }
bool free_etc_dump(char *etc_dump) bool free_baked_dump(char *baked_dump)
{ {
LOGI("Removing etc dump %s\n", etc_dump); LOGI("Removing bakedres dump %s\n", baked_dump);
bool ok = nftw(etc_dump, etc_dump_rm_cb, FOPEN_MAX, FTW_DEPTH | FTW_MOUNT | FTW_PHYS) != -1; bool ok = nftw(baked_dump, baked_dump_rm_cb, FOPEN_MAX, FTW_DEPTH | FTW_MOUNT | FTW_PHYS) != -1;
if (!ok) { if (!ok) {
LOGE("Could not remove %s\n", etc_dump); LOGE("Could not remove %s\n", baked_dump);
} }
free(etc_dump); free(baked_dump);
return ok; return ok;
} }
@ -234,20 +234,20 @@ int cp(const char* source, const char* destination)
return result; return result;
} }
void copy_baked_resources_to_etc_dump(Baked_Resource *resource, void *udata) void copy_baked_resources_to_baked_dump(Baked_Resource *resource, void *udata)
{ {
char *etc_dump = (char *)udata; char *baked_dump = (char *)udata;
char path[PATH_MAX]; char path[PATH_MAX];
get_baked_resource_path(resource->key, path, sizeof(path)); get_baked_resource_path(resource->key, path, sizeof(path));
char dest[PATH_MAX]; char dest[PATH_MAX];
snprintf(dest, sizeof(dest), "%s/%s", etc_dump, resource->key); snprintf(dest, sizeof(dest), "%s/%s", baked_dump, resource->key);
cp(path, dest); cp(path, dest);
} }
void populate_etc_dump(char *etc_dump) void populate_baked_dump(char *baked_dump)
{ {
lock_baked_resources(); lock_baked_resources();
baked_resource_each(&copy_baked_resources_to_etc_dump, etc_dump); baked_resource_each(&copy_baked_resources_to_baked_dump, baked_dump);
unlock_baked_resources(); unlock_baked_resources();
} }
@ -261,12 +261,12 @@ int main(int argc, char ** argv)
start_timer(); start_timer();
init_baked_resources(); init_baked_resources();
lockx(&etc_dump_path); lockx(&baked_dump_path);
if ((etc_dump_path.value = init_etc_dump()) == nil) { if ((baked_dump_path.value = init_baked_dump()) == nil) {
return 1; return 1;
} }
populate_etc_dump(etc_dump_path.value); populate_baked_dump(baked_dump_path.value);
unlockx(&etc_dump_path); unlockx(&baked_dump_path);
mg_log_set(MG_LL_DEBUG); mg_log_set(MG_LL_DEBUG);
struct mg_mgr mgr; struct mg_mgr mgr;
@ -284,9 +284,9 @@ int main(int argc, char ** argv)
mg_mgr_free(&mgr); mg_mgr_free(&mgr);
lockx(&etc_dump_path); lockx(&baked_dump_path);
free_etc_dump(etc_dump_path.value); free_baked_dump(baked_dump_path.value);
unlockx(&etc_dump_path); unlockx(&baked_dump_path);
free_baked_resources(); free_baked_resources();
return 0; return 0;

View File

@ -3,7 +3,7 @@
<head> <head>
<title>Blog</title> <title>Blog</title>
<meta charset="utf-8" /> <meta charset="utf-8" />
<link rel="stylesheet" href="/etc/simple.css" /> <link rel="stylesheet" href="/bakedres/simple.css" />
<#META_TAGS> <#META_TAGS>
</head> </head>
<body> <body>
@ -24,8 +24,8 @@
</footer> </footer>
<#ifdef HOTRELOAD> <#ifdef HOTRELOAD>
<script src="/etc/hotreload.js"></script> <script src="/bakedres/hotreload.js"></script>
<#endif> <#endif>
<script src="/etc/theme.js"></script> <script src="/bakedres/theme.js"></script>
</body> </body>
</html> </html>

View File

@ -3,7 +3,7 @@
<head> <head>
<title>Kamil's personal website</title> <title>Kamil's personal website</title>
<meta charset="utf-8" /> <meta charset="utf-8" />
<link rel="stylesheet" href="/etc/simple.css" /> <link rel="stylesheet" href="/bakedres/simple.css" />
<#META_TAGS> <#META_TAGS>
</head> </head>
<body> <body>
@ -54,7 +54,7 @@
</ul> </ul>
</section> </section>
<section> <section>
<img src="/etc/me.jpg" alt="literally me" /> <img src="/bakedres/me.jpg" alt="literally me" />
</section> </section>
<footer> <footer>
<div style="float: left;"> <div style="float: left;">
@ -65,8 +65,8 @@
</footer> </footer>
<#ifdef HOTRELOAD> <#ifdef HOTRELOAD>
<script src="/etc/hotreload.js"></script> <script src="/bakedres/hotreload.js"></script>
<#endif> <#endif>
<script src="/etc/theme.js"></script> <script src="/bakedres/theme.js"></script>
</body> </body>
</html> </html>

View File

@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<title>404 - Page not found</title> <title>404 - Page not found</title>
<link rel="stylesheet" href="/etc/simple.css" /> <link rel="stylesheet" href="/bakedres/simple.css" />
<#META_TAGS> <#META_TAGS>
</head> </head>
<body> <body>
@ -19,8 +19,8 @@
</footer> </footer>
<#ifdef HOTRELOAD> <#ifdef HOTRELOAD>
<script src="/etc/hotreload.js"></script> <script src="/bakedres/hotreload.js"></script>
<#endif> <#endif>
<script src="/etc/theme.js"></script> <script src="/bakedres/theme.js"></script>
</body> </body>
</html> </html>

View File

@ -3,10 +3,10 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title><#BLOG_POST_TITLE></title> <title><#BLOG_POST_TITLE></title>
<link rel="stylesheet" href="/etc/simple.css" /> <link rel="stylesheet" href="/bakedres/simple.css" />
<#META_TAGS> <#META_TAGS>
<link rel="stylesheet" href="/etc/hljs-rainbow.css"> <link rel="stylesheet" href="/bakedres/hljs-rainbow.css">
<script src="/etc/highlight.js"></script> <script src="/bakedres/highlight.js"></script>
</head> </head>
<body> <body>
<div id="content"></div> <div id="content"></div>
@ -23,9 +23,9 @@
</script> </script>
<#ifdef HOTRELOAD> <#ifdef HOTRELOAD>
<script src="/etc/hotreload.js"></script> <script src="/bakedres/hotreload.js"></script>
<#endif> <#endif>
<script src="/etc/theme.js"></script> <script src="/bakedres/theme.js"></script>
<script>hljs.highlightAll();</script> <script>hljs.highlightAll();</script>
</body> </body>
</html> </html>