From 173bfb537146e2a44e26c1302bf41319b530d59a Mon Sep 17 00:00:00 2001 From: Enrico204 Date: Sat, 21 Aug 2021 13:43:51 +0200 Subject: [PATCH] Reply "insufficient storage" on disk full or over-quota This commit will change the current behavior on disk-related errors: * HTTP 507 "Insufficient storage" is the status on disk full or over-quota * HTTP 500 "Internal server error" on other disk-related errors previously both were 400 "Bad request" --- quota/quota.go | 2 +- repo/repo.go | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/quota/quota.go b/quota/quota.go index c36244e..0b1020e 100644 --- a/quota/quota.go +++ b/quota/quota.go @@ -75,7 +75,7 @@ func (m *Manager) WrapWriter(req *http.Request, w io.Writer) (io.Writer, int, er if currentSize+contentLen > m.maxRepoSize { err := fmt.Errorf("incoming blob (%d bytes) would exceed maximum size of repository (%d bytes)", contentLen, m.maxRepoSize) - return nil, http.StatusRequestEntityTooLarge, err + return nil, http.StatusInsufficientStorage, err } } diff --git a/repo/repo.go b/repo/repo.go index 01fe1d8..e8b4b5c 100644 --- a/repo/repo.go +++ b/repo/repo.go @@ -4,6 +4,7 @@ import ( "crypto/sha256" "encoding/hex" "encoding/json" + "errors" "fmt" "io" "io/ioutil" @@ -14,6 +15,7 @@ import ( "regexp" "runtime" "strings" + "syscall" "time" "github.com/miolini/datacounter" @@ -603,7 +605,12 @@ func (h *Handler) saveBlob(w http.ResponseWriter, r *http.Request) { if h.opt.Debug { log.Print(err) } - httpDefaultError(w, http.StatusBadRequest) + var pathError *os.PathError + if errors.As(err, &pathError) && (pathError.Err == syscall.ENOSPC || pathError.Err == syscall.EDQUOT) { + httpDefaultError(w, http.StatusInsufficientStorage) + } else { + httpDefaultError(w, http.StatusInternalServerError) + } return }