whoops double ext not backwards compatible

master
Bel LaPointe 2021-09-28 13:53:15 -06:00
parent 82d9519e72
commit 0121c426f7
2 changed files with 8 additions and 5 deletions

View File

@ -5,8 +5,8 @@ import (
"errors"
"io"
"io/ioutil"
"local/logb"
"local/storage/resolve"
"log"
"os"
"path"
"path/filepath"
@ -76,10 +76,10 @@ func (b *Files) Get(key string, ns ...string) ([]byte, error) {
func (b *Files) GetStream(key string, ns ...string) (io.Reader, error) {
namespace := resolve.Namespace(ns)
key += fileExt
path := path.Join(b.root, namespace, key)
r, err := os.Open(path + fileExt)
if os.IsNotExist(err) {
logb.Warnf("does not exist: %q + %q from key=%q ns=%v namespace=%q, trying %q instead", path, fileExt, key, ns, namespace, path)
r, err = os.Open(path)
}
if os.IsNotExist(err) {
@ -121,18 +121,18 @@ func (b *Files) SetStream(key string, r io.Reader, ns ...string) error {
return err
}
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
log.Printf("failed mkdir: %v", err)
logb.Warnf("failed mkdir: %v", err)
return err
}
f, err := os.Create(path)
if err != nil {
log.Printf("failed create: %v: path=%q, dir=%q, ns=%q", err, path, dir, namespace)
logb.Warnf("failed create: %v: path=%q, dir=%q, ns=%q", err, path, dir, namespace)
return err
}
defer f.Close()
_, err = io.Copy(f, r)
if err != nil {
log.Printf("failed copy: %v", err)
logb.Warnf("failed copy: %v", err)
return err
}
return nil

3
go.mod
View File

@ -14,4 +14,7 @@ require (
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/syndtr/goleveldb v1.0.0
go.mongodb.org/mongo-driver v1.7.2
local/logb v0.0.0-00010101000000-000000000000
)
replace local/logb => ../logb