mirror of
https://github.com/jech/galene.git
synced 2024-11-22 08:35:57 +01:00
Replace uses of os.IsExist and os.IsNotExist with errors.Is.
The former don't properly unwrap errors.
This commit is contained in:
parent
68887f13d5
commit
3409f5a27f
10 changed files with 21 additions and 19 deletions
|
@ -264,7 +264,7 @@ func openDiskFile(directory, username, extension string) (*os.File, error) {
|
|||
)
|
||||
if err == nil {
|
||||
return f, nil
|
||||
} else if !os.IsExist(err) {
|
||||
} else if !errors.Is(err, os.ErrExist) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -232,7 +232,7 @@ func getDescriptionFile[T any](name string, allowSubgroups bool, get func(string
|
|||
Directory, path.Clean("/"+name)+".json",
|
||||
)
|
||||
r, err := get(fileName)
|
||||
if !os.IsNotExist(err) {
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
return r, fileName, isSubgroup, err
|
||||
}
|
||||
if !allowSubgroups {
|
||||
|
@ -348,7 +348,7 @@ func UpdateDescription(name, etag string, desc *Description) error {
|
|||
if err == nil {
|
||||
oldetag = makeETag(old.fileSize, old.modTime)
|
||||
filename = old.FileName
|
||||
} else if os.IsNotExist(err) {
|
||||
} else if errors.Is(err, os.ErrNotExist) {
|
||||
old = nil
|
||||
filename = filepath.Join(
|
||||
Directory, path.Clean("/"+name)+".json",
|
||||
|
|
|
@ -474,7 +474,7 @@ func add(name string, desc *Description) (*Group, []Client, error) {
|
|||
} else if !descriptionUnchanged(name, g.description) {
|
||||
desc, err = readDescription(name, true)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
log.Printf("Reading group %v: %v", name, err)
|
||||
}
|
||||
deleteUnlocked(g)
|
||||
|
@ -886,7 +886,7 @@ func GetConfiguration() (*Configuration, error) {
|
|||
filename := filepath.Join(DataDirectory, "config.json")
|
||||
fi, err := os.Stat(filename)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
if !configuration.configuration.Zero() {
|
||||
configuration.configuration = &Configuration{}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ func Update() *configuration {
|
|||
found = true
|
||||
file, err := os.Open(ICEFilename)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
log.Printf("Open %v: %v", ICEFilename, err)
|
||||
} else {
|
||||
found = false
|
||||
|
|
|
@ -1299,7 +1299,7 @@ func leaveGroup(c *webClient) {
|
|||
|
||||
func closeDownConn(c *webClient, id string, message string) error {
|
||||
err := delDownConn(c, id)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
if err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
log.Printf("Close down connection: %v", err)
|
||||
}
|
||||
err = c.write(clientMessage{
|
||||
|
@ -1413,7 +1413,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
|
|||
if err != nil {
|
||||
var e, s string
|
||||
var autherr *group.NotAuthorisedError
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
s = "group does not exist"
|
||||
} else if errors.Is(err, group.ErrAnonymousNotAuthorised) {
|
||||
s = "please choose a username"
|
||||
|
|
|
@ -62,7 +62,7 @@ func getStateful(token string) (*Stateful, error) {
|
|||
defer tokens.mu.Unlock()
|
||||
err := tokens.load()
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
|
@ -109,7 +109,7 @@ func (state *state) load() error {
|
|||
state.modTime = time.Time{}
|
||||
state.fileSize = 0
|
||||
state.tokens = nil
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
|
@ -125,7 +125,7 @@ func (state *state) load() error {
|
|||
state.modTime = time.Time{}
|
||||
state.fileSize = 0
|
||||
state.tokens = nil
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
|
@ -153,7 +153,7 @@ func (state *state) load() error {
|
|||
state.modTime = time.Time{}
|
||||
state.fileSize = 0
|
||||
state.tokens = nil
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
|
@ -262,7 +262,7 @@ func (state *state) extend(group, token string, expires time.Time) (*Stateful, e
|
|||
func (state *state) rewrite() error {
|
||||
if state.tokens == nil || len(state.tokens) == 0 {
|
||||
err := os.Remove(state.filename)
|
||||
if err == nil || os.IsNotExist(err) {
|
||||
if err == nil || errors.Is(err, os.ErrNotExist) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
|
|
|
@ -2,6 +2,7 @@ package token
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -294,7 +295,7 @@ func TestTokenStorage(t *testing.T) {
|
|||
}
|
||||
|
||||
_, err = os.Stat(s.filename)
|
||||
if !os.IsNotExist(err) {
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
t.Errorf("existence check: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
@ -170,7 +171,7 @@ func apiGroupHandler(w http.ResponseWriter, r *http.Request, pth string) {
|
|||
return
|
||||
} else if r.Method == "PUT" {
|
||||
etag, err := group.GetDescriptionTag(g)
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
err = nil
|
||||
etag = ""
|
||||
} else if err != nil {
|
||||
|
@ -299,7 +300,7 @@ func usersHandler(w http.ResponseWriter, r *http.Request, g, pth string) {
|
|||
return
|
||||
} else if r.Method == "PUT" {
|
||||
etag, err := group.GetUserTag(g, username)
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
etag = ""
|
||||
err = nil
|
||||
} else if err != nil {
|
||||
|
|
|
@ -291,7 +291,7 @@ func TestApi(t *testing.T) {
|
|||
}
|
||||
|
||||
_, err = group.GetDescription("test")
|
||||
if !os.IsNotExist(err) {
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
t.Errorf("Group exists after delete")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ func notFound(w http.ResponseWriter) {
|
|||
var ErrIsDirectory = errors.New("is a directory")
|
||||
|
||||
func httpError(w http.ResponseWriter, err error) {
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
notFound(w)
|
||||
return
|
||||
}
|
||||
|
@ -235,7 +235,7 @@ func (fh *fileHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
ff, err := fh.root.Open(index)
|
||||
if err != nil {
|
||||
// return 403 if index.html doesn't exist
|
||||
if os.IsNotExist(err) {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
http.Error(w, "Forbidden", http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue