mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-25 20:41:49 +03:00
use canonicalized filenames for buffers
This commit is contained in:
parent
5bba01ca9c
commit
0082238c75
@ -94,7 +94,7 @@ void edit(const CommandParameters& params, Context& context)
|
|||||||
if (param_count == 0 or param_count > 3)
|
if (param_count == 0 or param_count > 3)
|
||||||
throw wrong_argument_count();
|
throw wrong_argument_count();
|
||||||
|
|
||||||
const String& name = parser[0];
|
String name = canonicalize_filename(parse_filename(parser[0]));
|
||||||
|
|
||||||
Buffer* buffer = nullptr;
|
Buffer* buffer = nullptr;
|
||||||
if (not force_reload)
|
if (not force_reload)
|
||||||
|
11
src/file.cc
11
src/file.cc
@ -46,6 +46,11 @@ String parse_filename(const String& filename)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String canonicalize_filename(const String& filename)
|
||||||
|
{
|
||||||
|
return filename.replace(R"(((^|(?<=/))\./)+|[^/]+/\.\./)", "");
|
||||||
|
}
|
||||||
|
|
||||||
String read_file(const String& filename)
|
String read_file(const String& filename)
|
||||||
{
|
{
|
||||||
int fd = open(parse_filename(filename).c_str(), O_RDONLY);
|
int fd = open(parse_filename(filename).c_str(), O_RDONLY);
|
||||||
@ -71,9 +76,11 @@ String read_file(const String& filename)
|
|||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer* create_buffer_from_file(const String& filename)
|
Buffer* create_buffer_from_file(String filename)
|
||||||
{
|
{
|
||||||
int fd = open(parse_filename(filename).c_str(), O_RDONLY);
|
filename = canonicalize_filename(parse_filename(filename));
|
||||||
|
|
||||||
|
int fd = open(filename.c_str(), O_RDONLY);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
{
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
|
@ -26,9 +26,10 @@ class Buffer;
|
|||||||
|
|
||||||
// parse ~/ and $env values in filename and returns the translated filename
|
// parse ~/ and $env values in filename and returns the translated filename
|
||||||
String parse_filename(const String& filename);
|
String parse_filename(const String& filename);
|
||||||
|
String canonicalize_filename(const String& filename);
|
||||||
|
|
||||||
String read_file(const String& filename);
|
String read_file(const String& filename);
|
||||||
Buffer* create_buffer_from_file(const String& filename);
|
Buffer* create_buffer_from_file(String filename);
|
||||||
void write_buffer_to_file(const Buffer& buffer, const String& filename);
|
void write_buffer_to_file(const Buffer& buffer, const String& filename);
|
||||||
String find_file(const String& filename, const memoryview<String>& paths);
|
String find_file(const String& filename, const memoryview<String>& paths);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user