Skip to content

Commit

Permalink
Make sure file path exist before creating the file (#30)
Browse files Browse the repository at this point in the history
* Make sure file path exist before creating the file by making the directory
  • Loading branch information
KortanZ authored Apr 30, 2024
1 parent 1246a3a commit 4961ea3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lua/org-roam/core/utils/io.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ end
---@param data string|string[]
---@param cb fun(err:string|nil)
function M.write_file(path, data, cb)
-- Create file directory with 0o644 (rw-r--r--) if not exist
local dir = vim.fs.dirname(path)
if 0 == vim.fn.isdirectory(dir) then
vim.fn.mkdir(dir, "p", DEFAULT_WRITE_PERMISSIONS)
end
-- Open or create file with 0o644 (rw-r--r--)
uv.fs_open(path, "w", DEFAULT_WRITE_PERMISSIONS, function(err, fd)
if err then
Expand Down

0 comments on commit 4961ea3

Please sign in to comment.