aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluaneko <luaneko@chiya.dev>2022-12-21 00:18:37 +1100
committerluaneko <luaneko@chiya.dev>2022-12-21 00:18:37 +1100
commit5fbfa412864ee1d0396267c1b438bf2923d3653b (patch)
tree455af28b4787ea66aafb3700e269ebe780a47e55
parentf4b1fa84e121f20925c1abea22468bf5338db5f4 (diff)
downloaddep-5fbfa412864ee1d0396267c1b438bf2923d3653b.tar.gz
dep-5fbfa412864ee1d0396267c1b438bf2923d3653b.tar.bz2
dep-5fbfa412864ee1d0396267c1b438bf2923d3653b.zip
Ensure cache directory is created before opening log file
Merging from #5
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)