From 8783a062f76ffa2c328fa98288a404f478d78908 Mon Sep 17 00:00:00 2001 From: JINNOUCHI Yasushi Date: Sat, 25 May 2024 21:24:30 +0900 Subject: [PATCH] fix: make the path for file_lock unless it exists (#205) --- lua/frecency/file_lock.lua | 8 ++++++++ lua/frecency/types.lua | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lua/frecency/file_lock.lua b/lua/frecency/file_lock.lua index fa1f2bb..9453cb8 100644 --- a/lua/frecency/file_lock.lua +++ b/lua/frecency/file_lock.lua @@ -1,3 +1,4 @@ +local Path = require "plenary.path" --[[@as FrecencyPlenaryPath]] local async = require "plenary.async" --[[@as FrecencyPlenaryAsync]] local log = require "plenary.log" @@ -30,6 +31,13 @@ function FileLock:get() local err, fd while true do count = count + 1 + local dir = Path.new(self.filename):parent() + if not dir:exists() then + -- TODO: make this call be async + log.debug(("file_lock get(): mkdir parent: %s"):format(dir.filename)) + ---@diagnostic disable-next-line: undefined-field + dir:mkdir { parents = true } + end err, fd = async.uv.fs_open(self.filename, "wx", tonumber("600", 8)) if not err then break diff --git a/lua/frecency/types.lua b/lua/frecency/types.lua index 52d002a..53eacff 100644 --- a/lua/frecency/types.lua +++ b/lua/frecency/types.lua @@ -10,7 +10,7 @@ ---@field filename string ---@field joinpath fun(self: FrecencyPlenaryPath, ...): FrecencyPlenaryPath ---@field make_relative fun(self: FrecencyPlenaryPath, cwd: string): string ----@field parent FrecencyPlenaryPath +---@field parent fun(self: FrecencyPlenaryPath): FrecencyPlenaryPath ---@field path { sep: string } ---@field rm fun(self: FrecencyPlenaryPath, opts?: { recursive: boolean }): nil ---@field touch fun(self: FrecencyPlenaryPath, opts?: { parents: boolean }): nil