diff options
author | Waqas Hussain <waqas20@gmail.com> | 2012-09-12 22:03:06 +0500 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2012-09-12 22:03:06 +0500 |
commit | 184e6cad288c8d51ed5a9eda5b9c7d378317fad2 (patch) | |
tree | e71fdd4f2fc3d1b5ec106ea03aa9294f4fade4e5 /util/datamanager.lua | |
parent | 92515e7aa6dbcc3a9a8e3d8de5f368c69df59842 (diff) | |
download | prosody-184e6cad288c8d51ed5a9eda5b9c7d378317fad2.tar.gz prosody-184e6cad288c8d51ed5a9eda5b9c7d378317fad2.zip |
util.datamanager: Make the util.pposix dependency optional.
Diffstat (limited to 'util/datamanager.lua')
-rw-r--r-- | util/datamanager.lua | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/util/datamanager.lua b/util/datamanager.lua index 17c614ed..e6ad86db 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -25,28 +25,23 @@ local serialize = require "util.serialization".serialize; 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" |