diff options
author | ZyX <kp-pav@yandex.ru> | 2015-10-29 01:24:04 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2015-10-29 19:34:26 +0300 |
commit | ffdf9399ba0a3f1b90bde6f4a3c489a879a01358 (patch) | |
tree | 1d35a311a7ed39308cc7b0c404efcc7e9e64f234 /src | |
parent | d99941777dbaca1719223961174df5e01b1ac444 (diff) | |
download | rneovim-ffdf9399ba0a3f1b90bde6f4a3c489a879a01358.tar.gz rneovim-ffdf9399ba0a3f1b90bde6f4a3c489a879a01358.tar.bz2 rneovim-ffdf9399ba0a3f1b90bde6f4a3c489a879a01358.zip |
undo: Automatically create undo directory if needed
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/undo.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 90f02645da..d8158bf7cd 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -644,7 +644,9 @@ void u_compute_hash(char_u *hash) /// be found. /// @param[in] reading If true, find the file to read by traversing all of the /// directories in &undodir. If false use the first -/// existing directory. +/// existing directory. If none of the directories in +/// &undodir option exist then last directory in the list +/// will be automatically created. /// /// @return [allocated] File name to read from/write to or NULL. char *u_get_undo_file_name(const char *const buf_ffname, const bool reading) @@ -690,7 +692,20 @@ char *u_get_undo_file_name(const char *const buf_ffname, const bool reading) memmove(tail + tail_len + 1, ".un~", sizeof(".un~")); } else { dir_name[dir_len] = NUL; - if (os_isdir((char_u *)dir_name)) { + bool has_directory = os_isdir((char_u *)dir_name); + if (!has_directory && *dirp == NUL && !reading) { + // Last directory in the list does not exist, create it. + int ret; + char *failed_dir; + if ((ret = os_mkdir_recurse(dir_name, 0755, &failed_dir)) != 0) { + EMSG3(_("E926: Unable to create directory \"%s\" for undo file: %s"), + failed_dir, os_strerror(ret)); + xfree(failed_dir); + } else { + has_directory = true; + } + } + if (has_directory) { if (munged_name == NULL) { munged_name = xstrdup(ffname); for (char *p = munged_name; *p != NUL; mb_ptr_adv(p)) { |