Skip to content

Commit

Permalink
fix symlink create error
Browse files Browse the repository at this point in the history
fixes the error:
```
ln: failed to create symbolic link 'chats/last.md': Directory not empty
```
  • Loading branch information
argshook committed May 17, 2024
1 parent 93fc0e8 commit 42076bf
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lua/gp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,17 @@ M.prep_chat = function(buf, file_name)
-- make last.md a symlink to the last opened chat file
local last = M.config.chat_dir .. "/last.md"
if file_name ~= last then
os.execute("ln -sf " .. file_name .. " " .. last)
local check_command = "if [[ -L " .. last .. " || ! -e " .. last .. " ]]; then echo 'ok'; else echo 'fail'; fi"
local handle = io.popen(check_command)
local result = handle:read("*a")
handle:close()

if result:find("ok") then
os.remove(last)
os.execute("ln -sf " .. file_name .. " " .. last)
else
print("Error: 'last.md' exists and is not a symbolic link.")
end
end
end

Expand Down

0 comments on commit 42076bf

Please sign in to comment.