From 7e5a26f42caaa4a4bdb84341e6687d594cdb4f17 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Sun, 31 May 2015 19:35:34 +0100 Subject: [PATCH] Protect the exported method Delete() --- pkg/storage/drivers/memory/memory_cache.go | 10 ++++++++-- pkg/storage/drivers/memory/memory_multipart.go | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/storage/drivers/memory/memory_cache.go b/pkg/storage/drivers/memory/memory_cache.go index a543880fd..ce482f599 100644 --- a/pkg/storage/drivers/memory/memory_cache.go +++ b/pkg/storage/drivers/memory/memory_cache.go @@ -128,7 +128,7 @@ func (r *Cache) Set(key string, value interface{}) bool { // remove random key if only we reach the maxSize threshold for key := range r.items { for (r.currentSize + valueLen) > r.maxSize { - r.Delete(key) + r.doDelete(key) } break } @@ -145,13 +145,19 @@ func (r *Cache) Expire() { defer r.Unlock() for key := range r.items { if !r.isValid(key) { - r.Delete(key) + r.doDelete(key) } } } // Delete deletes a given key if exists func (r *Cache) Delete(key string) { + r.Lock() + defer r.Unlock() + r.doDelete(key) +} + +func (r *Cache) doDelete(key string) { if _, ok := r.items[key]; ok { r.currentSize -= uint64(len(r.items[key].([]byte))) delete(r.items, key) diff --git a/pkg/storage/drivers/memory/memory_multipart.go b/pkg/storage/drivers/memory/memory_multipart.go index bf5ba0cba..53799121d 100644 --- a/pkg/storage/drivers/memory/memory_multipart.go +++ b/pkg/storage/drivers/memory/memory_multipart.go @@ -212,7 +212,7 @@ func (memory *memoryDriver) cleanupMultiparts(bucket, key, uploadID string) { defer memory.lock.Unlock() for i := 1; i <= memory.storedBuckets[bucket].multiPartSession[key].totalParts; i++ { objectKey := bucket + "/" + getMultipartKey(key, uploadID, i) - memory.multiPartObjects.Delete(objectKey) + memory.multiPartObjects.doDelete(objectKey) } }