# HG changeset patch # User Waqas Hussain # Date 1347469386 -18000 # Node ID 0dc9e6c128c303ef6aff84d1c937f9da2e06ff47 # Parent 2c7e1ce8f48266283e5183cfc30c104b20d76d61 util.datamanager: Make the util.pposix dependency optional. diff -r 2c7e1ce8f482 -r 0dc9e6c128c3 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"