diff options
author | Michael Lingelbach <m.j.lbach@gmail.com> | 2021-01-16 12:14:59 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-16 21:14:59 +0100 |
commit | abbfaf286f26989b18377d4238f3cea9dc281149 (patch) | |
tree | acd6d74360e8751b3e5d9333a91326956501a892 /src | |
parent | 0fad952a2b7d90d2c3215e8e3c50ae62233e2158 (diff) | |
download | rneovim-abbfaf286f26989b18377d4238f3cea9dc281149.tar.gz rneovim-abbfaf286f26989b18377d4238f3cea9dc281149.tar.bz2 rneovim-abbfaf286f26989b18377d4238f3cea9dc281149.zip |
logs: make kXDGCacheHome if it doesn't exist (#13758)
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/log.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/nvim/log.c b/src/nvim/log.c index a90c95c034..98df2c799a 100644 --- a/src/nvim/log.c +++ b/src/nvim/log.c @@ -22,6 +22,7 @@ #include "nvim/os/time.h" #define LOG_FILE_ENV "NVIM_LOG_FILE" +#define LOGERR "E5010: " /// Cached location of the expanded log file path decided by log_path_init(). static char log_file_path[MAXPATHL + 1] = { 0 }; @@ -69,6 +70,19 @@ static bool log_path_init(void) || log_file_path[0] == '\0' || os_isdir((char_u *)log_file_path) || !log_try_create(log_file_path)) { + // Make kXDGCacheHome if it does not exist. + char *cachehome = get_xdg_home(kXDGCacheHome); + char *failed_dir = NULL; + if (!os_isdir((char_u *)cachehome)) { + int ret; + if ((ret = os_mkdir_recurse(cachehome, 0700, &failed_dir)) != 0) { + EMSG3(_(LOGERR "Failed to create directory %s " + "for writing logs: %s"), + failed_dir, os_strerror(ret)); + } + } + XFREE_CLEAR(failed_dir); + XFREE_CLEAR(cachehome); // Invalid $NVIM_LOG_FILE or failed to expand; fall back to default. char *defaultpath = stdpaths_user_cache_subpath("log"); size_t len = xstrlcpy(log_file_path, defaultpath, size); |