Fix duplicate buffer problem, fix real_path beahviour

This commit is contained in:
Maxime Coste 2016-05-15 10:37:01 +01:00
parent 1788126f38
commit baf219ee2f
2 changed files with 7 additions and 2 deletions

View File

@ -25,9 +25,11 @@ BufferManager::~BufferManager()
Buffer* BufferManager::create_buffer(String name, Buffer::Flags flags, Buffer* BufferManager::create_buffer(String name, Buffer::Flags flags,
StringView data, timespec fs_timestamp) StringView data, timespec fs_timestamp)
{ {
auto path = real_path(parse_filename(name));
for (auto& buf : m_buffers) for (auto& buf : m_buffers)
{ {
if (buf->name() == name) if (buf->name() == name or
(buf->flags() & Buffer::Flags::File and buf->name() == path))
throw name_not_unique(); throw name_not_unique();
} }

View File

@ -90,7 +90,10 @@ String real_path(StringView filename)
auto it = find(existing.rbegin(), existing.rend(), '/'); auto it = find(existing.rbegin(), existing.rend(), '/');
if (it == existing.rend()) if (it == existing.rend())
return filename.str(); {
char cwd[1024];
return format("{}/{}", getcwd(cwd, 1024), filename);
}
existing = StringView{existing.begin(), it.base()-1}; existing = StringView{existing.begin(), it.base()-1};
non_existing = StringView{it.base(), filename.end()}; non_existing = StringView{it.base(), filename.end()};