Changeset

4010:21311bd31f6b

storagemanager: Add new "null" provider to get used when loading a driver or opening a store fails, instead of falling back to the default driver
author Matthew Wild <mwild1@gmail.com>
date Thu, 06 Jan 2011 13:56:39 +0000
parents 4009:71b2c1dcf26d
children 4011:0df6b99cb74a
files core/storagemanager.lua
diffstat 1 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/core/storagemanager.lua	Thu Jan 06 13:54:37 2011 +0000
+++ b/core/storagemanager.lua	Thu Jan 06 13:56:39 2011 +0000
@@ -15,6 +15,19 @@
 
 module("storagemanager")
 
+local null_storage_method = function () return false, "no data storage active"; end
+local null_storage_driver = setmetatable(
+	{
+		name = "null",
+		open = function (self) return self; end
+	}, {
+		__index = function (self, method)
+			return null_storage_method;
+		end
+	}
+);
+
+--TODO: Move default driver to mod_auth_internal
 local default_driver_mt = { name = "internal" };
 default_driver_mt.__index = default_driver_mt;
 function default_driver_mt:open(store)
@@ -73,10 +86,13 @@
 		if not driver then
 			if driver_name or (type(storage) == "string"
 			or type(storage) == "table" and storage[store]) then
-				log("warn", "Falling back to default driver for %s storage on %s", store, host);
+				log("warn", "Falling back to null driver for %s storage on %s", store, host);
+				driver_name = "null";
+				driver = null_storage_driver;
+			else
+				driver_name = "internal";
+				driver = load_driver(host, driver_name);
 			end
-			driver_name = "internal";
-			driver = load_driver(host, driver_name);
 		end
 	end
 	
@@ -85,7 +101,7 @@
 		if err == "unsupported-store" then
 			log("debug", "Storage driver %s does not support store %s (%s), falling back to internal driver",
 				driver_name, store, typ);
-			ret = setmetatable({ host = host, store = store }, default_driver_mt); -- default to default driver
+			ret = null_storage_driver;
 			err = nil;
 		end
 	end