From 875cc63fd3768254f60205583bfb7641eceb41c6 Mon Sep 17 00:00:00 2001 From: Angel Pons <22937129+Th3Fanbus@users.noreply.github.com> Date: Sun, 4 Feb 2024 12:09:55 +0000 Subject: [PATCH] fix: do not add zero-length filenames in per-target zips Rewrite the compound conditional to avoid future confusions. This bug has gone unnoticed for so long because Alpakit-generated zip files do not contain folder entries when iterating with a `zipReader`. However, manually generated zip files, e.g. ContentLib mods, could contain folder entries depending on the zipping program used. The resulting zero-length folder in the per-target zips breaks SMM2 on Windows, but not SMM3. --- storage/storage.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/storage/storage.go b/storage/storage.go index da94729e..55d2c4b6 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -386,11 +386,15 @@ func SeparateModTarget(ctx context.Context, body []byte, modID, name, modVersion zipWriter := zip.NewWriter(buf) for _, file := range zipReader.File { - if !strings.HasPrefix(file.Name, target+"/") && file.Name != target+"/" { + if !strings.HasPrefix(file.Name, target+"/") { + continue + } + trimmedName := strings.TrimPrefix(file.Name, target+"/") + if len(trimmedName) == 0 { continue } - err = copyModFileToArchZip(file, zipWriter, strings.TrimPrefix(file.Name, target+"/")) + err = copyModFileToArchZip(file, zipWriter, trimmedName) if err != nil { log.Err(err).Msg("failed to add file to " + target + " archive")