From ff5ac238c4053c9e17af511f1a6f086553ccad56 Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Tue, 18 Jan 2022 17:25:44 +0000 Subject: [PATCH 1/6] Allow files ending "txt.gz" to be uploaded as a log file. --- submit.go | 2 +- submit_test.go | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/submit.go b/submit.go index e53db1b..c680351 100644 --- a/submit.go +++ b/submit.go @@ -424,7 +424,7 @@ func saveFormPart(leafName string, reader io.Reader, reportDir string) (string, // we require a sensible extension, and don't allow the filename to start with // '.' -var logRegexp = regexp.MustCompile(`^[a-zA-Z0-9_-][a-zA-Z0-9_.-]*\.(log|txt)$`) +var logRegexp = regexp.MustCompile(`^[a-zA-Z0-9_-][a-zA-Z0-9_.-]*\.(log|txt)(\.gz)?$`) // saveLogPart saves a log upload to the report directory. // diff --git a/submit_test.go b/submit_test.go index f5cca86..0b7edbf 100644 --- a/submit_test.go +++ b/submit_test.go @@ -160,6 +160,7 @@ func TestMultipartUpload(t *testing.T) { // check file uploaded correctly checkUploadedFile(t, reportDir, "passwd.txt", false, "bibblybobbly") + checkUploadedFile(t, reportDir, "crash.log.gz.gz", true, "test\n") } func multipartBody() (body string) { @@ -215,6 +216,18 @@ Content-Type: application/octet-stream bibblybobbly ` + body += `------WebKitFormBoundarySsdgl8Nq9voFyhdO +Content-Disposition: form-data; name="compressed-log"; filename="crash.log.gz" +Content-Type: application/octet-stream + +` + body += string([]byte{ + 0x1f, 0x8b, 0x08, 0x00, 0xbf, 0xd8, 0xf5, 0x58, 0x00, 0x03, + 0x2b, 0x49, 0x2d, 0x2e, 0xe1, 0x02, 0x00, + 0xc6, 0x35, 0xb9, 0x3b, 0x05, 0x00, 0x00, 0x00, + 0x0a, + }) + body += "------WebKitFormBoundarySsdgl8Nq9voFyhdO--\n" return } @@ -224,8 +237,8 @@ func checkParsedMultipartUpload(t *testing.T, p *parsedPayload) { if p.UserText != wanted { t.Errorf("User text: got %s, want %s", p.UserText, wanted) } - if len(p.Logs) != 3 { - t.Errorf("Log length: got %d, want 3", len(p.Logs)) + if len(p.Logs) != 4 { + t.Errorf("Log length: got %d, want 4", len(p.Logs)) } if len(p.Data) != 3 { t.Errorf("Data length: got %d, want 3", len(p.Data)) @@ -249,6 +262,10 @@ func checkParsedMultipartUpload(t *testing.T, p *parsedPayload) { if p.Logs[2] != wanted { t.Errorf("Log 2: got %s, want %s", p.Logs[2], wanted) } + wanted = "crash.log.gz.gz" + if p.Logs[3] != wanted { + t.Errorf("Log 3: got %s, want %s", p.Logs[3], wanted) + } } func TestLabels(t *testing.T) { From d337ec9843cdf96ca11b2cdc1672e799942baf96 Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Tue, 18 Jan 2022 17:28:01 +0000 Subject: [PATCH 2/6] Update test to look for file to not gain an additional `.gz` extension. --- submit_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/submit_test.go b/submit_test.go index 0b7edbf..e19be5f 100644 --- a/submit_test.go +++ b/submit_test.go @@ -160,7 +160,7 @@ func TestMultipartUpload(t *testing.T) { // check file uploaded correctly checkUploadedFile(t, reportDir, "passwd.txt", false, "bibblybobbly") - checkUploadedFile(t, reportDir, "crash.log.gz.gz", true, "test\n") + checkUploadedFile(t, reportDir, "crash.log.gz", true, "test\n") } func multipartBody() (body string) { @@ -262,7 +262,7 @@ func checkParsedMultipartUpload(t *testing.T, p *parsedPayload) { if p.Logs[2] != wanted { t.Errorf("Log 2: got %s, want %s", p.Logs[2], wanted) } - wanted = "crash.log.gz.gz" + wanted = "crash.log.gz" if p.Logs[3] != wanted { t.Errorf("Log 3: got %s, want %s", p.Logs[3], wanted) } From 523333f5a04769d6b2a832d49044d15f8a8cfe17 Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Tue, 18 Jan 2022 17:30:50 +0000 Subject: [PATCH 3/6] Don't append a second `.gz` extension --- submit.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/submit.go b/submit.go index c680351..e457b30 100644 --- a/submit.go +++ b/submit.go @@ -438,7 +438,11 @@ func saveLogPart(logNum int, filename string, reader io.Reader, reportDir string // Either way, we need to append .gz, because we're compressing it. var leafName string if logRegexp.MatchString(filename) { - leafName = filename + ".gz" + if strings.HasSuffix(filename, ".gz") { + leafName = filename + } else { + leafName = filename + ".gz" + } } else { leafName = fmt.Sprintf("logs-%04d.log.gz", logNum) } From 8e842a3fc284b4e20e8f81cb7126f0cba670f5a7 Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Tue, 18 Jan 2022 17:33:28 +0000 Subject: [PATCH 4/6] Add changelog fragment. --- changelog.d/40.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/40.feature diff --git a/changelog.d/40.feature b/changelog.d/40.feature new file mode 100644 index 0000000..f472465 --- /dev/null +++ b/changelog.d/40.feature @@ -0,0 +1 @@ +Support element-android submitting logs with .gz suffix. From ac76e5e70697aea6548fe24195a7bdf113093671 Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Mon, 24 Jan 2022 13:38:50 +0000 Subject: [PATCH 5/6] Update submit.go Refactor slightly to be clearer that we only add .gz if it's not already there. Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> --- submit.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/submit.go b/submit.go index e457b30..9b5d3c8 100644 --- a/submit.go +++ b/submit.go @@ -438,10 +438,9 @@ func saveLogPart(logNum int, filename string, reader io.Reader, reportDir string // Either way, we need to append .gz, because we're compressing it. var leafName string if logRegexp.MatchString(filename) { - if strings.HasSuffix(filename, ".gz") { - leafName = filename - } else { - leafName = filename + ".gz" + leafName = filename + if !strings.HasSuffix(filename, ".gz") { + leafName += ".gz" } } else { leafName = fmt.Sprintf("logs-%04d.log.gz", logNum) From c674f7e24361b64519558ffa14b019b6151ea48f Mon Sep 17 00:00:00 2001 From: Michael Kaye <1917473+michaelkaye@users.noreply.github.com> Date: Mon, 24 Jan 2022 13:41:36 +0000 Subject: [PATCH 6/6] Update comment to be accurate. --- submit.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/submit.go b/submit.go index 9b5d3c8..0554a4f 100644 --- a/submit.go +++ b/submit.go @@ -435,10 +435,13 @@ func saveLogPart(logNum int, filename string, reader io.Reader, reportDir string // some clients use sensible names (foo.N.log), which we preserve. For // others, we just make up a filename. // - // Either way, we need to append .gz, because we're compressing it. + // We append a ".gz" extension if not already present, as the final file we store on + // disk will be gzipped. The original filename may or may not contain a '.gz' depending + // on the client that uploaded it, and if it was uploaded already compressed. + var leafName string if logRegexp.MatchString(filename) { - leafName = filename + leafName = filename if !strings.HasSuffix(filename, ".gz") { leafName += ".gz" }