fix: make the path for file_lock unless it exists (#205)

This commit is contained in:
JINNOUCHI Yasushi 2024-05-25 21:24:30 +09:00 committed by GitHub
parent 865f51a611
commit 8783a062f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View File

@ -1,3 +1,4 @@
local Path = require "plenary.path" --[[@as FrecencyPlenaryPath]]
local async = require "plenary.async" --[[@as FrecencyPlenaryAsync]] local async = require "plenary.async" --[[@as FrecencyPlenaryAsync]]
local log = require "plenary.log" local log = require "plenary.log"
@ -30,6 +31,13 @@ function FileLock:get()
local err, fd local err, fd
while true do while true do
count = count + 1 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)) err, fd = async.uv.fs_open(self.filename, "wx", tonumber("600", 8))
if not err then if not err then
break break

View File

@ -10,7 +10,7 @@
---@field filename string ---@field filename string
---@field joinpath fun(self: FrecencyPlenaryPath, ...): FrecencyPlenaryPath ---@field joinpath fun(self: FrecencyPlenaryPath, ...): FrecencyPlenaryPath
---@field make_relative fun(self: FrecencyPlenaryPath, cwd: string): string ---@field make_relative fun(self: FrecencyPlenaryPath, cwd: string): string
---@field parent FrecencyPlenaryPath ---@field parent fun(self: FrecencyPlenaryPath): FrecencyPlenaryPath
---@field path { sep: string } ---@field path { sep: string }
---@field rm fun(self: FrecencyPlenaryPath, opts?: { recursive: boolean }): nil ---@field rm fun(self: FrecencyPlenaryPath, opts?: { recursive: boolean }): nil
---@field touch fun(self: FrecencyPlenaryPath, opts?: { parents: boolean }): nil ---@field touch fun(self: FrecencyPlenaryPath, opts?: { parents: boolean }): nil