mirror of
https://github.com/Luzifer/discord-community.git
synced 2024-12-20 02:11:23 +00:00
Fix: Handle empty store-file created for permission management
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
879f88831f
commit
ab2e77a9b5
1 changed files with 16 additions and 1 deletions
17
metastore.go
17
metastore.go
|
@ -21,7 +21,7 @@ func newMetaStoreFromDisk(filename string) (*metaStore, error) {
|
||||||
filename: filename,
|
filename: filename,
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := os.Open(filename)
|
s, err := os.Stat(filename)
|
||||||
switch {
|
switch {
|
||||||
case err == nil:
|
case err == nil:
|
||||||
// This is fine
|
// This is fine
|
||||||
|
@ -31,6 +31,21 @@ func newMetaStoreFromDisk(filename string) (*metaStore, error) {
|
||||||
return out, nil
|
return out, nil
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
return nil, errors.Wrap(err, "getting file stats for store")
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.IsDir() {
|
||||||
|
// A directory was provided
|
||||||
|
return nil, errors.New("store location is directory")
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.Size() == 0 {
|
||||||
|
// An empty file was created, we don't care and will overwrite on save
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := os.Open(filename)
|
||||||
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "opening store")
|
return nil, errors.Wrap(err, "opening store")
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
Loading…
Reference in a new issue