From ec1cb0f57e6185135f52db52cb2dbd7ad4d0c4a5 Mon Sep 17 00:00:00 2001
From: AO55
Date: Sat, 7 Nov 2026 23:13:35 -0300
Subject: [PATCH] [tracer] A log sent in a .zip or a .gz downloads under a
log's name
The site keeps a packed log as its text, and the report page's Download
saved that text under the archive's name (logs.zip), a .zip nothing
opens: it is named as a log now (logs.log, game.log for game.log.gz).
Signed-off-by: AO55
---
docs/TESTING.md | 4 +--
docs/TRACER.md | 2 +-
tracer/Makefile | 2 +-
tracer/src/files.c | 14 ++++++++
tracer/src/files.h | 4 +++
tracer/src/site.c | 6 +++-
tracer/tests/test_tracer.c | 69 ++++++++++++++++++++++++++++++++++++++
7 files changed, 96 insertions(+), 5 deletions(-)
diff --git a/docs/TESTING.md b/docs/TESTING.md
index c8b9c76..ea8d54b 100644
--- a/docs/TESTING.md
+++ b/docs/TESTING.md
@@ -47,8 +47,8 @@ usage.
temporary folder:
- the events and what a message asks; which files are logs, screenshots and videos; the logs unpacked from a `.gz` and
- a `.zip`; the screenshots' metadata taken out (PNG, JPEG, WebP, GIF) and broken ones refused; an MP4's place and
- camera blanked; text made valid UTF-8;
+ a `.zip`, and the name each downloads as from the site (a log's, never the archive's); the screenshots' metadata
+ taken out (PNG, JPEG, WebP, GIF) and broken ones refused; an MP4's place and camera blanked; text made valid UTF-8;
- the game a log names (and the older builds' titles, a garbled one, a name in another script); the crash report's
dumps left out of a log as the log summary leaves them out; the games' names from the list (an update's and an
add-on's ID, a report named at once, one named at the next start, a log's name first, a GBA game by its code, a
diff --git a/docs/TRACER.md b/docs/TRACER.md
index f66397b..7b56a1b 100644
--- a/docs/TRACER.md
+++ b/docs/TRACER.md
@@ -185,7 +185,7 @@ Static files, drawn again where a report changes them, and all of them at each s
| `index.html` | each game, its latest outcome, its reports' count; a search and a filter by outcome |
| `all.html` | every report, the newest first |
| `g/.html` | a game's reports: `` its title ID, or `n-` and its name's letters for a game known by name |
-| `r//` | a report: its facts, screenshots, and each log with its summary, to read or download |
+| `r//` | a report: its facts, screenshots, and each log with its summary, to read or download (a log sent in a `.zip` or a `.gz` is kept as its text and downloads as one: `logs.zip` as `logs.log`, `game.log.gz` as `game.log`) |
| `api/` | the same as JSON: `games.json`, `reports.json`, `r/.json` (a report with its logs' summaries and the notes added later); no Discord id |
| `style.css`, `site.js`, `tracer.svg` | copied from `TRACER_ASSETS` at each start |
diff --git a/tracer/Makefile b/tracer/Makefile
index a82148d..dd2bc99 100644
--- a/tracer/Makefile
+++ b/tracer/Makefile
@@ -61,7 +61,7 @@ src/files.o: src/files.c src/files.h src/tracer.h
$(CC) $(CFLAGS) $(OURS) -c -o $@ src/files.c
src/store.o: src/store.c src/store.h src/tracer.h
$(CC) $(CFLAGS) $(OURS) $(SQLITE_CFLAGS) -c -o $@ src/store.c
-src/site.o: src/site.c src/site.h src/store.h src/tracer.h
+src/site.o: src/site.c src/site.h src/files.h src/store.h src/tracer.h
$(CC) $(CFLAGS) $(OURS) -c -o $@ src/site.c
src/worker.o: src/worker.c src/worker.h src/report.h src/age.h src/tracer.h
$(CC) $(CFLAGS) $(OURS) -c -o $@ src/worker.c
diff --git a/tracer/src/files.c b/tracer/src/files.c
index 481e262..4a7bfeb 100644
--- a/tracer/src/files.c
+++ b/tracer/src/files.c
@@ -411,6 +411,20 @@ int tr_unpack(const char* name, const char* data, size_t n, size_t max, Buf* out
return -1;
}
+char* tr_unpacked_name(const char* name) {
+ size_t n = strlen(name);
+ if (ends(name, ".zip")) return rei_format("%.*s.log", (int)(n - 4), name);
+ if (ends(name, ".gz")) {
+ char* rest = rei_format("%.*s", (int)(n - 3), name);
+ char* named;
+ if (ends(rest, ".log") || ends(rest, ".txt")) return rest;
+ named = rei_format("%s.log", rest);
+ free(rest);
+ return named;
+ }
+ return rei_strdup(name);
+}
+
char* tr_utf8(const char* text, size_t n) {
const unsigned char* s = (const unsigned char*)text;
Buf b = {0};
diff --git a/tracer/src/files.h b/tracer/src/files.h
index d0dce64..3bdb507 100644
--- a/tracer/src/files.h
+++ b/tracer/src/files.h
@@ -36,6 +36,10 @@ int tr_ppm_png(const char* data, size_t n, Buf* out);
/* a log as text: a .gz's or a .zip's (its first .log or .txt, else its first file) unpacked, any other name's bytes
as they are, max bytes at most. 0, or -1 with why (owned) */
int tr_unpack(const char* name, const char* data, size_t n, size_t max, Buf* out, char** why);
+/* the name the text tr_unpack made of name is saved as: a .gz's without its .gz ("game.log.gz" as "game.log"), with
+ .log after it when what is left is no .log or .txt; a .zip's with .log for its .zip ("logs.zip" as "logs.log"); any
+ other name as it is. The site keeps the text, never the archive. Owned */
+char* tr_unpacked_name(const char* name);
/* the n bytes of text with each byte that is not part of valid UTF-8 as U+FFFD, and each NUL left out; owned */
char* tr_utf8(const char* text, size_t n);
diff --git a/tracer/src/site.c b/tracer/src/site.c
index 546a260..bc8e434 100644
--- a/tracer/src/site.c
+++ b/tracer/src/site.c
@@ -10,6 +10,8 @@
#include
#include
+#include "files.h"
+
/* ---- pieces of a page ---- */
static void esc(Buf* b, const char* s) {
@@ -357,6 +359,7 @@ static void log_section(Buf* b, const StFile* f) {
cJSON* s = f->summary ? cJSON_Parse(f->summary) : NULL;
const cJSON *failure = cJSON_GetObjectItemCaseSensitive(s, "failure"), *frame;
const char* file = f->path;
+ char* saved = tr_unpacked_name(f->name); /* the file is the log's text, also when it came in a .zip or a .gz */
buf_add(b, "
\n");
+ free(saved);
if (cJSON_IsObject(failure)) {
const cJSON* fn = cJSON_GetObjectItemCaseSensitive(failure, "function");
buf_add(b, "\n");
diff --git a/tracer/tests/test_tracer.c b/tracer/tests/test_tracer.c
index 3ccbf9d..f7b0d5b 100644
--- a/tracer/tests/test_tracer.c
+++ b/tracer/tests/test_tracer.c
@@ -524,6 +524,25 @@ static void test_unpack(void) {
CHECK(tr_unpack("plain.txt", "text", 4, 3, &out, &why));
free(why);
buf_free(&out);
+ /* the name the unpacked text is saved as: never an archive's, as it is no archive any more */
+ {
+ static const char* const names[][2] = {
+ {"logs.zip", "logs.log"},
+ {"scarletnx-logs-2026-11-07.ZIP", "scarletnx-logs-2026-11-07.log"},
+ {"game.log.gz", "game.log"},
+ {"notes.TXT.gz", "notes.TXT"},
+ {"run.gz", "run.log"},
+ {"backup.tar.gz", "backup.tar.log"},
+ {"scarletnx.log", "scarletnx.log"},
+ {"plain.txt", "plain.txt"},
+ {".zip", ".zip"} /* no name before it: tr_unpack takes it as text, not a zip */};
+ size_t i;
+ for (i = 0; i < sizeof names / sizeof *names; ++i) {
+ char* got = tr_unpacked_name(names[i][0]);
+ SAME(got, names[i][1]);
+ free(got);
+ }
+ }
}
/* the log's summary as the bot makes it, owned */
@@ -2782,6 +2801,55 @@ static void test_age(void) {
gql_answer = gql_body = NULL;
}
+/* a log sent in a .zip or a .gz is kept as its text: the report page's Download saves that text under a name of a log,
+ never the archive's, which no program opens as one */
+static void test_archive_download(void) {
+ static char zip[1 << 16], gz[1 << 16];
+ size_t nzip, ngz;
+ TrMessage m;
+ StFile* files;
+ StReport r;
+ int nfiles;
+ char *t, *p, *rel, *data;
+ data = packed(1, "games/Some Game/scarletnx.log", LOG, &nzip); /* one buffer of packed's: copied before the next */
+ memcpy(zip, data, nzip);
+ data = packed(0, "data", LOG, &ngz);
+ memcpy(gz, data, ngz);
+ serve("https://cdn.discordapp.com/9/scarletnx-logs-2026-11-07.zip", zip, nzip);
+ serve("https://cdn.discordapp.com/9/game.log.gz", gz, ngz);
+ m = message(9500, 950, "<@99> from the launcher's Share Zip");
+ attach(&m, "scarletnx-logs-2026-11-07.zip", "https://cdn.discordapp.com/9/scarletnx-logs-2026-11-07.zip",
+ (double)nzip);
+ attach(&m, "game.log.gz", "https://cdn.discordapp.com/9/game.log.gz", (double)ngz);
+ t = answer_text(respond(&m));
+ HAS(t, "2 logs, 0 screenshots");
+ free(t);
+ CHECK(st_get(tracer.store, st_by_message(tracer.store, 9500), &r, &files, &nfiles) == 1);
+ CHECK(nfiles == 2);
+ if (nfiles == 2) {
+ SAME(files[0].name, "scarletnx-logs-2026-11-07.zip"); /* what was sent, as the page's heading and JSON say */
+ rel = rei_format("r/%ld/index.html", r.id);
+ p = page(rel);
+ HAS(p, "
scarletnx-logs-2026-11-07.zip ");
+ CHECK(strstr(p, "\" download=\"scarletnx-logs-2026-11-07.log\">Download") != NULL);
+ CHECK(strstr(p, "\" download=\"game.log\">Download") != NULL);
+ LACKS(p, "download=\"scarletnx-logs-2026-11-07.zip\"");
+ LACKS(p, "download=\"game.log.gz\"");
+ free(p);
+ free(rel);
+ /* and the file the link names is the log's text, not a zip's bytes */
+ rel = rei_format("r/%ld/%s", r.id, files[0].path);
+ p = page(rel);
+ CHECK(p && strncmp(p, "PK", 2));
+ HAS(p, "ScarletNX - Some Game");
+ free(p);
+ free(rel);
+ }
+ st_report_free(&r);
+ st_files_free(files, nfiles);
+ tr_message_free(&m);
+}
+
int main(int argc, char** argv) {
char *db, *command;
if (argc == 2) return as_worker(argv[1]);
@@ -2834,6 +2902,7 @@ int main(int argc, char** argv) {
test_untraceable(argv[0]);
test_issues();
test_age();
+ test_archive_download();
}
st_close(tracer.store);
if (getenv("TRACER_TEST_KEEP")) fprintf(stderr, "kept %s\n", site);