From 426b38bb3362d2d477d0d8aa27d880664d537431 Mon Sep 17 00:00:00 2001 From: Ramires Viana <59319979+ramiresviana@users.noreply.github.com> Date: Fri, 12 Mar 2021 15:52:52 +0000 Subject: [PATCH] fix: root path name on archive --- http/raw.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/http/raw.go b/http/raw.go index 85c180ad..5c224caa 100644 --- a/http/raw.go +++ b/http/raw.go @@ -173,13 +173,6 @@ func rawDirHandler(w http.ResponseWriter, r *http.Request, d *data, file *files. return http.StatusInternalServerError, err } - name := file.Name - if name == "." || name == "" { - name = "archive" - } - name += extension - w.Header().Set("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(name)) - err = ar.Create(w) if err != nil { return http.StatusInternalServerError, err @@ -188,6 +181,18 @@ func rawDirHandler(w http.ResponseWriter, r *http.Request, d *data, file *files. commonDir := fileutils.CommonPrefix(filepath.Separator, filenames...) + var name string + if len(filenames) > 1 { + name = "_" + filepath.Base(commonDir) + } else { + name = file.Name + } + if name == "." || name == "" { + name = "archive" + } + name += extension + w.Header().Set("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(name)) + for _, fname := range filenames { err = addFile(ar, d, fname, commonDir) if err != nil {