mirror of
https://github.com/restic/rest-server.git
synced 2025-10-19 07:33:21 +00:00
Check errors in many places
Admittedly, in some places just document the fact that we ignore error return values, 'cause we don't know what to do with it. At least, the linter is happy.
This commit is contained in:
parent
10951e4540
commit
d056b85432
2 changed files with 16 additions and 10 deletions
20
handlers.go
20
handlers.go
|
@ -159,7 +159,7 @@ func GetConfig(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
w.Write(bytes)
|
||||
_, _ = w.Write(bytes)
|
||||
}
|
||||
|
||||
// SaveConfig allows for a config to be saved.
|
||||
|
@ -272,7 +272,7 @@ func ListBlobs(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
w.Write(data)
|
||||
_, _ = w.Write(data)
|
||||
}
|
||||
|
||||
// CheckBlob tests whether a blob exists.
|
||||
|
@ -322,7 +322,11 @@ func GetBlob(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
wc := datacounter.NewResponseWriterCounter(w)
|
||||
http.ServeContent(wc, r, "", time.Unix(0, 0), file)
|
||||
file.Close()
|
||||
|
||||
if err = file.Close(); err != nil {
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if Config.Prometheus {
|
||||
labels := prometheus.Labels{"repo": getRepo(r), "type": pat.Param(r, "type")}
|
||||
|
@ -354,8 +358,8 @@ func SaveBlob(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
written, err := io.Copy(tf, r.Body)
|
||||
if err != nil {
|
||||
tf.Close()
|
||||
os.Remove(path)
|
||||
_ = tf.Close()
|
||||
_ = os.Remove(path)
|
||||
if Config.Debug {
|
||||
log.Print(err)
|
||||
}
|
||||
|
@ -364,8 +368,8 @@ func SaveBlob(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
if err := tf.Sync(); err != nil {
|
||||
tf.Close()
|
||||
os.Remove(path)
|
||||
_ = tf.Close()
|
||||
_ = os.Remove(path)
|
||||
if Config.Debug {
|
||||
log.Print(err)
|
||||
}
|
||||
|
@ -374,7 +378,7 @@ func SaveBlob(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
if err := tf.Close(); err != nil {
|
||||
os.Remove(path)
|
||||
_ = os.Remove(path)
|
||||
if Config.Debug {
|
||||
log.Print(err)
|
||||
}
|
||||
|
|
|
@ -88,7 +88,6 @@ func (h *HtpasswdFile) Reload() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
cr := csv.NewReader(r)
|
||||
cr.Comma = ':'
|
||||
|
@ -97,6 +96,7 @@ func (h *HtpasswdFile) Reload() error {
|
|||
|
||||
records, err := cr.ReadAll()
|
||||
if err != nil {
|
||||
_ = r.Close()
|
||||
return err
|
||||
}
|
||||
users := make(map[string]string)
|
||||
|
@ -108,6 +108,8 @@ func (h *HtpasswdFile) Reload() error {
|
|||
h.mutex.Lock()
|
||||
h.Users = users
|
||||
h.mutex.Unlock()
|
||||
|
||||
_ = r.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -160,7 +162,7 @@ func (h *HtpasswdFile) Validate(user string, password string) bool {
|
|||
}
|
||||
if realPassword[:5] == "{SHA}" {
|
||||
d := sha1.New()
|
||||
d.Write([]byte(password))
|
||||
_, _ = d.Write([]byte(password))
|
||||
if realPassword[5:] == base64.StdEncoding.EncodeToString(d.Sum(nil)) {
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue