zip downloads: make zip entries relative to the current dir when possible

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2022-09-19 17:06:42 +02:00
parent 554a1cb1f4
commit f19691250d
7 changed files with 40 additions and 20 deletions

View File

@@ -271,13 +271,13 @@ func (s *httpdServer) downloadFromShare(w http.ResponseWriter, r *http.Request)
compress := true
var info os.FileInfo
if len(share.Paths) == 1 && r.URL.Query().Get("compress") == "false" {
if len(share.Paths) == 1 {
info, err = connection.Stat(share.Paths[0], 1)
if err != nil {
sendAPIResponse(w, r, err, "", getRespStatus(err))
return
}
if info.Mode().IsRegular() {
if info.Mode().IsRegular() && r.URL.Query().Get("compress") == "false" {
compress = false
}
}
@@ -289,9 +289,16 @@ func (s *httpdServer) downloadFromShare(w http.ResponseWriter, r *http.Request)
err = connection.GetReadQuotaExceededError()
connection.Log(logger.LevelInfo, "denying share read due to quota limits")
sendAPIResponse(w, r, err, "", getMappedStatusCode(err))
dataprovider.UpdateShareLastUse(&share, -1) //nolint:errcheck
return
}
baseDir := "/"
if info != nil && info.IsDir() {
baseDir = share.Paths[0]
share.Paths[0] = "/"
}
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"share-%v.zip\"", share.Name))
renderCompressedFiles(w, connection, "/", share.Paths, &share)
renderCompressedFiles(w, connection, baseDir, share.Paths, &share)
return
}
if status, err := downloadFile(w, r, connection, share.Paths[0], info, false, &share); err != nil {