-
Notifications
You must be signed in to change notification settings - Fork 751
Remove max path #5389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Remove max path #5389
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,24 +63,33 @@ std::pair<StringView, StringView> split_path(StringView path) | |
| return { {path.begin(), slash+1}, {slash+1, path.end()} }; | ||
| } | ||
|
|
||
| struct MallocDeleter | ||
| { | ||
| void operator()(char *ptr) const | ||
| { | ||
| free(ptr); | ||
| } | ||
| }; | ||
|
|
||
| String real_path(StringView filename) | ||
| { | ||
| if (filename.empty()) | ||
| return {}; | ||
|
|
||
| char buffer[PATH_MAX+1]; | ||
|
|
||
| StringView existing = filename; | ||
| StringView non_existing{}; | ||
|
|
||
| using unique_cstr = std::unique_ptr<char, MallocDeleter>; | ||
|
|
||
| while (true) | ||
| { | ||
| if (char* res = realpath(existing.zstr(), buffer)) | ||
| unique_cstr res(realpath(existing.zstr(), nullptr)); | ||
| if (res) | ||
| { | ||
| if (non_existing.empty()) | ||
| return res; | ||
| return String(res.get()); | ||
|
|
||
| StringView dir = res; | ||
| StringView dir = res.get(); | ||
| while (not dir.empty() and dir.back() == '/') | ||
| dir = dir.substr(0_byte, dir.length()-1_byte); | ||
| return format("{}/{}", dir, non_existing); | ||
|
|
@@ -295,22 +304,25 @@ void write_to_file(StringView filename, StringView data) | |
| write(fd, data); | ||
| } | ||
|
|
||
| int open_temp_file(StringView filename, char (&buffer)[PATH_MAX]) | ||
| int open_temp_file(StringView filename, String &buffer) | ||
| { | ||
| String path = real_path(filename); | ||
| auto [dir,file] = split_path(path); | ||
|
|
||
| if (dir.empty()) | ||
| format_to(buffer, ".{}.kak.XXXXXX", file); | ||
| buffer = format(".{}.kak.XXXXXX", file); | ||
| else | ||
| format_to(buffer, "{}/.{}.kak.XXXXXX", dir, file); | ||
| buffer = format("{}/.{}.kak.XXXXXX", dir, file); | ||
|
|
||
| return mkstemp(buffer); | ||
| char* tmplt = strndup(buffer.c_str(), (size_t)buffer.length()); | ||
| int fp = mkstemp(tmplt); | ||
| buffer = tmplt; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren´t we leaking tmplt here ? I am not sure why we need the |
||
| return fp; | ||
| } | ||
|
|
||
| int open_temp_file(StringView filename) | ||
| { | ||
| char buffer[PATH_MAX]; | ||
| String buffer; | ||
| return open_temp_file(filename, buffer); | ||
| } | ||
|
|
||
|
|
@@ -368,9 +380,9 @@ void make_directory(StringView dir, mode_t mode) | |
|
|
||
| void list_files(StringView dirname, FunctionRef<void (StringView, const struct stat&)> callback) | ||
| { | ||
| char buffer[PATH_MAX+1]; | ||
| format_to(buffer, "{}", dirname); | ||
| DIR* dir = opendir(dirname.empty() ? "./" : buffer); | ||
| String buffer; | ||
| buffer = format("{}", dirname); | ||
| DIR* dir = opendir(dirname.empty() ? "./" : buffer.c_str()); | ||
| if (not dir) | ||
| return; | ||
|
|
||
|
|
@@ -384,12 +396,12 @@ void list_files(StringView dirname, FunctionRef<void (StringView, const struct s | |
|
|
||
| struct stat st; | ||
| auto fmt_str = (dirname.empty() or dirname.back() == '/') ? "{}{}" : "{}/{}"; | ||
| format_to(buffer, fmt_str, dirname, filename); | ||
| if (stat(buffer, &st) != 0) | ||
| buffer = format(fmt_str, dirname, filename); | ||
| if (stat(buffer.c_str(), &st) != 0) | ||
| continue; | ||
|
|
||
| if (S_ISDIR(st.st_mode)) | ||
| filename = format_to(buffer, "{}/", filename); | ||
| filename = format(buffer.c_str(), "{}/", filename); | ||
| callback(filename, st); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,8 +46,8 @@ template<bool force_blocking = false> | |
| void write(int fd, StringView data); | ||
| void write_to_file(StringView filename, StringView data); | ||
| int create_file(const char* filename); | ||
| int open_temp_file(StringView filename, String &tmpFile); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we do not use camel case for parameters in kakoune, it should be |
||
| int open_temp_file(StringView filename); | ||
| int open_temp_file(StringView filename, char (&buffer)[PATH_MAX]); | ||
|
|
||
| struct MappedFile | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kakoune moved away to a custom
UniquePtrimplementation for compilation speed reasons, it does not support custom deleters as we did not have actual uses, but in this specific case aOnScopeEnd free{[&] { free(res); };would probably do the trick.