1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-25 04:24:48 +03:00

Fix implementation of real_path to handle non-existing directories in /

Fixes #1937
This commit is contained in:
Maxime Coste 2018-03-18 23:23:00 +11:00
parent 7ba4ef897b
commit ac91a79b12
5 changed files with 12 additions and 5 deletions

View File

@ -67,6 +67,7 @@ std::pair<StringView, StringView> split_path(StringView path)
String real_path(StringView filename) String real_path(StringView filename)
{ {
kak_assert(not filename.empty());
char buffer[PATH_MAX+1]; char buffer[PATH_MAX+1];
StringView existing = filename; StringView existing = filename;
@ -74,22 +75,21 @@ String real_path(StringView filename)
while (true) while (true)
{ {
char* res = realpath(existing.zstr(), buffer); if (char* res = realpath(existing.zstr(), buffer))
if (res)
{ {
if (non_existing.empty()) if (non_existing.empty())
return res; return res;
return format("{}/{}", res, non_existing); return format("{}{}", res, non_existing);
} }
auto it = find(existing.rbegin(), existing.rend(), '/'); auto it = find(existing.rbegin() + 1, existing.rend(), '/');
if (it == existing.rend()) if (it == existing.rend())
{ {
char cwd[1024]; char cwd[1024];
return format("{}/{}", getcwd(cwd, 1024), filename); return format("{}/{}", getcwd(cwd, 1024), filename);
} }
existing = StringView{existing.begin(), it.base()-1}; existing = StringView{existing.begin(), it.base()};
non_existing = StringView{it.base(), filename.end()}; non_existing = StringView{it.base(), filename.end()};
} }
} }

View File

@ -0,0 +1 @@
"aP

View File

@ -0,0 +1 @@
/kakoune-inexisting-directory/missing-file

View File

@ -0,0 +1,4 @@
eval -draft %{
edit /kakoune-inexisting-directory/missing-file
reg a %val{buffile}
}