whoops double ext not backwards compatible
parent
82d9519e72
commit
0121c426f7
10
files.go
10
files.go
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue