util.datamanager: Make the util.pposix dependency optional.
authorWaqas Hussain <waqas20@gmail.com>
Wed, 12 Sep 2012 22:03:06 +0500
changeset 5118 0dc9e6c128c3
parent 5117 2c7e1ce8f482
child 5119 d868ce990838
child 5124 a4a74a0e9b9c
util.datamanager: Make the util.pposix dependency optional.
util/datamanager.lua
--- a/util/datamanager.lua	Wed Sep 12 21:41:51 2012 +0500
+++ b/util/datamanager.lua	Wed Sep 12 22:03:06 2012 +0500
@@ -25,28 +25,23 @@
 local path_separator = assert ( package.config:match ( "^([^\n]+)" ) , "package.config not in standard form" ) -- Extract directory seperator from package.config (an undocumented string that comes with lua)
 local lfs = require "lfs";
 local prosody = prosody;
-local raw_mkdir;
-local fallocate;
 
-if prosody.platform == "posix" then
-	raw_mkdir = require "util.pposix".mkdir; -- Doesn't trample on umask
-	fallocate = require "util.pposix".fallocate;
-else
-	raw_mkdir = lfs.mkdir;
-end
-
-if not fallocate then -- Fallback
-	function fallocate(f, offset, len)
-		-- This assumes that current position == offset
-		local fake_data = (" "):rep(len);
-		local ok, msg = f:write(fake_data);
-		if not ok then
-			return ok, msg;
-		end
-		f:seek("set", offset);
-		return true;
+local raw_mkdir = lfs.mkdir;
+local function fallocate(f, offset, len)
+	-- This assumes that current position == offset
+	local fake_data = (" "):rep(len);
+	local ok, msg = f:write(fake_data);
+	if not ok then
+		return ok, msg;
 	end
-end
+	f:seek("set", offset);
+	return true;
+end;
+pcall(function()
+	local pposix = require "util.pposix";
+	raw_mkdir = pposix.mkdir or raw_mkdir; -- Doesn't trample on umask
+	fallocate = pposix.fallocate or fallocate;
+end);
 
 module "datamanager"