From 64b014369c9230ceda6335cd6a1d9c0ed5ce18fe Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 8 Jun 2015 17:08:46 -0700 Subject: [PATCH] Return back entity too large for createObject requests bigger than cache size --- main.go | 3 ++- pkg/storage/drivers/memory/memory.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 89a962dc1..5f256f936 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ package main import ( "fmt" + "net/http" "os" "os/user" "runtime" @@ -116,7 +117,7 @@ func getBuildDate() string { if t.IsZero() { return "" } - return t.Format(time.RFC1123) + return t.Format(http.TimeFormat) } // Tries to get os/arch/platform specific information diff --git a/pkg/storage/drivers/memory/memory.go b/pkg/storage/drivers/memory/memory.go index d7a365a1d..eca76b24e 100644 --- a/pkg/storage/drivers/memory/memory.go +++ b/pkg/storage/drivers/memory/memory.go @@ -43,6 +43,7 @@ type memoryDriver struct { lock *sync.RWMutex objects *trove.Cache multiPartObjects *trove.Cache + maxSize uint64 } type storedBucket struct { @@ -71,6 +72,7 @@ func Start(maxSize uint64, expiration time.Duration) (chan<- string, <-chan erro memory = new(memoryDriver) memory.storedBuckets = make(map[string]storedBucket) memory.objects = trove.NewCache(maxSize, expiration) + memory.maxSize = maxSize memory.multiPartObjects = trove.NewCache(0, time.Duration(0)) memory.lock = new(sync.RWMutex) @@ -204,6 +206,14 @@ func isMD5SumEqual(expectedMD5Sum, actualMD5Sum string) error { } func (memory *memoryDriver) CreateObject(bucket, key, contentType, expectedMD5Sum string, size int64, data io.Reader) (string, error) { + if size > int64(memory.maxSize) { + generic := drivers.GenericObjectError{Bucket: bucket, Object: key} + return "", iodine.New(drivers.EntityTooLarge{ + GenericObjectError: generic, + Size: strconv.FormatInt(size, 10), + MaxSize: strconv.FormatUint(memory.maxSize, 10), + }, nil) + } md5sum, err := memory.createObject(bucket, key, contentType, expectedMD5Sum, size, data) // free debug.FreeOSMemory()