|
86 | 86 | function utils.copyfile(src, target) |
87 | 87 | if utils.file_exists(src) then |
88 | 88 | -- if we don't always use terminal |
89 | | - local cmd = "exec " |
90 | | - .. "'!cmake -E copy " |
91 | | - .. utils.shell_quote(src) |
92 | | - .. " " |
93 | | - .. utils.shell_quote(target) |
94 | | - .. "'" |
| 89 | + local cmd = table.concat({ |
| 90 | + "exec", |
| 91 | + "'!cmake -E copy", |
| 92 | + utils.shell_quote(src), |
| 93 | + utils.shell_quote(target) .. "'", |
| 94 | + }, " ") |
95 | 95 | vim.cmd(cmd) |
96 | 96 | end |
97 | 97 | end |
98 | 98 |
|
99 | 99 | function utils.softlink(src, target) |
100 | | - if utils.file_exists(src) and not utils.file_exists(target) then |
101 | | - -- if we don't always use terminal |
102 | | - local cmd = "exec " |
103 | | - .. "'!cmake -E create_symlink " |
104 | | - .. utils.shell_quote(src) |
105 | | - .. " " |
106 | | - .. utils.shell_quote(target) |
107 | | - .. "'" |
108 | | - vim.cmd(cmd) |
| 100 | + if not utils.file_exists(src) then |
| 101 | + return |
| 102 | + end |
| 103 | + |
| 104 | + local stat = vim.loop.fs_lstat(target) |
| 105 | + if stat then |
| 106 | + if stat.type == "link" then |
| 107 | + if vim.loop.fs_readlink(target) == src then |
| 108 | + return |
| 109 | + end |
| 110 | + else |
| 111 | + -- target is a regular file, remove it first |
| 112 | + os.remove(target) |
| 113 | + end |
109 | 114 | end |
| 115 | + |
| 116 | + local cmd = table.concat({ |
| 117 | + "exec", |
| 118 | + "'!cmake -E create_symlink", |
| 119 | + utils.shell_quote(src), |
| 120 | + utils.shell_quote(target) .. "'", |
| 121 | + }, " ") |
| 122 | + vim.cmd(cmd) |
110 | 123 | end |
111 | 124 |
|
112 | 125 | function utils.shell_quote(str) |
|
0 commit comments