Let diskpacked maxFileSize be configurable

And on the way, remove diskpacked.New, as unused.

Change-Id: Idd14dd08fcf0645237dda66b4fa2d6c5e6e5b3e4
This commit is contained in:
Tamás Gulácsi 2013-10-06 08:23:53 +02:00 committed by Tamás Gulácsi
parent 3ddaa99206
commit 1cd83acccf
1 changed files with 10 additions and 4 deletions

View File

@ -48,7 +48,7 @@ import (
"camlistore.org/third_party/github.com/camlistore/lock"
)
const defaultMaxFileSize = 512 << 20
const defaultMaxFileSize = 512 << 20 // 512MB
type storage struct {
root string
@ -64,7 +64,9 @@ type storage struct {
closeErr error
}
func New(root string) (*storage, error) {
// newStorage returns a new storage in path root with the given maxFileSize,
// or defaultMaxFileSize (512MB) if <= 0
func newStorage(root string, maxFileSize int64) (*storage, error) {
fi, err := os.Stat(root)
if os.IsNotExist(err) {
return nil, fmt.Errorf("storage root %q doesn't exist", root)
@ -76,7 +78,10 @@ func New(root string) (*storage, error) {
return nil, fmt.Errorf("storage root %q exists but is not a directory.", root)
}
index, _, err := kvfile.NewStorage(filepath.Join(root, "index.kv"))
s := &storage{root: root, index: index, maxFileSize: defaultMaxFileSize}
if maxFileSize <= 0 {
maxFileSize = defaultMaxFileSize
}
s := &storage{root: root, index: index, maxFileSize: maxFileSize}
if err := s.openCurrent(); err != nil {
return nil, err
}
@ -85,10 +90,11 @@ func New(root string) (*storage, error) {
func newFromConfig(_ blobserver.Loader, config jsonconfig.Obj) (storage blobserver.Storage, err error) {
path := config.RequiredString("path")
maxFileSize := config.OptionalInt("maxFileSize", 0)
if err := config.Validate(); err != nil {
return nil, err
}
return New(path)
return newStorage(path, int64(maxFileSize))
}
func init() {