@@ -3,6 +3,7 @@ package repo
33import (
44 "encoding/hex"
55 "encoding/json"
6+ "errors"
67 "fmt"
78 "io"
89 "io/ioutil"
@@ -13,6 +14,7 @@ import (
1314 "regexp"
1415 "runtime"
1516 "strings"
17+ "syscall"
1618 "time"
1719
1820 "github.com/minio/sha256-simd"
@@ -83,6 +85,10 @@ func httpMethodNotAllowed(w http.ResponseWriter, allowed []string) {
8385 httpDefaultError (w , http .StatusMethodNotAllowed )
8486}
8587
88+ // errFileContentDoesntMatchHash is the error raised when the file content hash
89+ // doesn't match the hash provided in the URL
90+ var errFileContentDoesntMatchHash = errors .New ("file content does not match hash" )
91+
8692// BlobPathRE matches valid blob URI paths with optional object IDs
8793var BlobPathRE = regexp .MustCompile (`^/(data|index|keys|locks|snapshots)/([0-9a-f]{64})?$` )
8894
@@ -592,7 +598,7 @@ func (h *Handler) saveBlob(w http.ResponseWriter, r *http.Request) {
592598
593599 // reject if file content doesn't match file name
594600 if err == nil && hex .EncodeToString (hasher .Sum (nil )) != objectID {
595- err = fmt . Errorf ( "file content does not match hash" )
601+ err = errFileContentDoesntMatchHash
596602 }
597603 }
598604
@@ -603,7 +609,23 @@ func (h *Handler) saveBlob(w http.ResponseWriter, r *http.Request) {
603609 if h .opt .Debug {
604610 log .Print (err )
605611 }
606- httpDefaultError (w , http .StatusBadRequest )
612+ var pathError * os.PathError
613+ if errors .As (err , & pathError ) && (pathError .Err == syscall .ENOSPC ||
614+ pathError .Err == syscall .EDQUOT ) {
615+ // The error is disk-related (no space left, no quota left),
616+ // notify the client using the correct HTTP status
617+ httpDefaultError (w , http .StatusInsufficientStorage )
618+ } else if errors .Is (err , errFileContentDoesntMatchHash ) ||
619+ errors .Is (err , io .ErrUnexpectedEOF ) ||
620+ errors .Is (err , http .ErrMissingBoundary ) ||
621+ errors .Is (err , http .ErrNotMultipart ) {
622+ // The error is connection-related, send a client-side HTTP status
623+ httpDefaultError (w , http .StatusBadRequest )
624+ } else {
625+ // Otherwise we have a different internal error, reply with
626+ // server-side HTTP status
627+ h .internalServerError (w , err )
628+ }
607629 return
608630 }
609631
0 commit comments