aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--lua/dep/log.lua16
1 files changed, 13 insertions, 3 deletions
diff --git a/lua/dep/log.lua b/lua/dep/log.lua
index d3ae9e1..00dc8ca 100644
--- a/lua/dep/log.lua
+++ b/lua/dep/log.lua
@@ -6,7 +6,17 @@
--
-- https://opensource.org/licenses/MIT
--
-local vim, setmetatable, pcall, debug, string, os = vim, setmetatable, pcall, debug, string, os
+local vim, setmetatable, pcall, debug, string, os, assert = vim, setmetatable, pcall, debug, string, os, assert
+
+local function default_log_path()
+ -- ensure cache directory exists (#5)
+ local path = vim.fn.stdpath("cache")
+ if not vim.loop.fs_stat(path) then
+ vim.loop.fs_mkdir(path, 0x1ff) -- 0777
+ end
+
+ return path .. "/dep.log"
+end
local function try_format(...)
local ok, s = pcall(string.format, ...)
@@ -67,10 +77,10 @@ local Logger = setmetatable({
}, {
--- Constructs a new `Logger`.
__call = function(mt, path)
- path = path or vim.fn.stdpath("cache") .. "/dep.log"
+ path = path or default_log_path()
-- clear and open log file
- local handle = vim.loop.fs_open(path, "w", 0x1b4) -- 0664
+ local handle = assert(vim.loop.fs_open(path, "w", 0x1a4)) -- 0644
local pipe = vim.loop.new_pipe()
pipe:open(handle)