From cc031163d90c92aaa89faeef92146a6fd8e20b35 Mon Sep 17 00:00:00 2001 From: MickaelK Date: Mon, 4 Aug 2025 23:26:38 +1000 Subject: [PATCH] fix (zip): handle offline edge case --- server/ctrl/files.go | 16 +++++++++------- server/plugin/plg_backend_s3/index.go | 2 ++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/server/ctrl/files.go b/server/ctrl/files.go index 457d8537..391ceef3 100644 --- a/server/ctrl/files.go +++ b/server/ctrl/files.go @@ -783,19 +783,21 @@ func FileDownloader(ctx *App, res http.ResponseWriter, req *http.Request) { if strings.HasSuffix(backendPath, "/") == false { // Process File zipPath := strings.TrimPrefix(backendPath, zipRoot) + file, err := ctx.Backend.Cat(backendPath) + if err != nil { + *errList = append(*errList, fmt.Sprintf("downloader::cat %s %s\n", zipPath, err.Error())) + if err == ErrNotReachable { + return nil + } + Log.Debug("downloader::cat backendPath['%s'] zipPath['%s'] error['%s']", backendPath, zipPath, err.Error()) + return err + } zipFile, err := zw.Create(zipPath) if err != nil { *errList = append(*errList, fmt.Sprintf("downloader::create %s %s\n", zipPath, err.Error())) Log.Debug("downloader::create backendPath['%s'] zipPath['%s'] error['%s']", backendPath, zipPath, err.Error()) return err } - file, err := ctx.Backend.Cat(backendPath) - if err != nil { - *errList = append(*errList, fmt.Sprintf("downloader::cat %s %s\n", zipPath, err.Error())) - Log.Debug("downloader::cat backendPath['%s'] zipPath['%s'] error['%s']", backendPath, zipPath, err.Error()) - io.Copy(zipFile, strings.NewReader("")) - return err - } if _, err = io.Copy(zipFile, file); err != nil { *errList = append(*errList, fmt.Sprintf("downloader::copy %s %s\n", zipPath, err.Error())) Log.Debug("downloader::copy backendPath['%s'] zipPath['%s'] error['%s']", backendPath, zipPath, err.Error()) diff --git a/server/plugin/plg_backend_s3/index.go b/server/plugin/plg_backend_s3/index.go index f2baae1f..61dfe395 100644 --- a/server/plugin/plg_backend_s3/index.go +++ b/server/plugin/plg_backend_s3/index.go @@ -282,6 +282,8 @@ func (this S3Backend) Cat(path string) (io.ReadCloser, error) { return nil, NewError("This file is encrypted file, you need the correct key!", 400) } else if awsErr.Code() == "AccessDenied" { return nil, ErrNotAllowed + } else if awsErr.Code() == "InvalidObjectState" { + return nil, ErrNotReachable } return nil, err }