mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-24 20:13:00 +03:00
Fix implementation of real_path to handle non-existing directories in /
Fixes #1937
This commit is contained in:
parent
7ba4ef897b
commit
ac91a79b12
10
src/file.cc
10
src/file.cc
@ -67,6 +67,7 @@ std::pair<StringView, StringView> split_path(StringView path)
|
||||
|
||||
String real_path(StringView filename)
|
||||
{
|
||||
kak_assert(not filename.empty());
|
||||
char buffer[PATH_MAX+1];
|
||||
|
||||
StringView existing = filename;
|
||||
@ -74,22 +75,21 @@ String real_path(StringView filename)
|
||||
|
||||
while (true)
|
||||
{
|
||||
char* res = realpath(existing.zstr(), buffer);
|
||||
if (res)
|
||||
if (char* res = realpath(existing.zstr(), buffer))
|
||||
{
|
||||
if (non_existing.empty())
|
||||
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())
|
||||
{
|
||||
char cwd[1024];
|
||||
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()};
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
"aP
|
@ -0,0 +1 @@
|
||||
|
@ -0,0 +1 @@
|
||||
/kakoune-inexisting-directory/missing-file
|
@ -0,0 +1,4 @@
|
||||
eval -draft %{
|
||||
edit /kakoune-inexisting-directory/missing-file
|
||||
reg a %val{buffile}
|
||||
}
|
Loading…
Reference in New Issue
Block a user