Fix: Handle empty store-file created for permission management

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-08-22 15:23:23 +02:00
parent 879f88831f
commit ab2e77a9b5
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D

View file

@ -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()