From 42076bfe0e37d6f5f037b53c1e233dbf2fe24a32 Mon Sep 17 00:00:00 2001 From: argshook Date: Fri, 17 May 2024 15:51:18 +0300 Subject: [PATCH] fix symlink create error fixes the error: ``` ln: failed to create symbolic link 'chats/last.md': Directory not empty ``` --- lua/gp/init.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lua/gp/init.lua b/lua/gp/init.lua index c1c4b98..7d7cfdb 100644 --- a/lua/gp/init.lua +++ b/lua/gp/init.lua @@ -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