From 1cd83acccf467b086b11319efbfa00eed3a25e48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Gul=C3=A1csi?= Date: Sun, 6 Oct 2013 08:23:53 +0200 Subject: [PATCH] Let diskpacked maxFileSize be configurable And on the way, remove diskpacked.New, as unused. Change-Id: Idd14dd08fcf0645237dda66b4fa2d6c5e6e5b3e4 --- pkg/blobserver/diskpacked/diskpacked.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/blobserver/diskpacked/diskpacked.go b/pkg/blobserver/diskpacked/diskpacked.go index c1ae18f2d..05a70ec76 100644 --- a/pkg/blobserver/diskpacked/diskpacked.go +++ b/pkg/blobserver/diskpacked/diskpacked.go @@ -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() {