aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGregory Anders <greg@gpanders.com>2021-08-19 20:34:43 -0600
committerGregory Anders <greg@gpanders.com>2021-08-27 10:34:44 -0600
commit460019366e58e1bcd42959f76494e38bd895e762 (patch)
treef172338dbb176d3ff4bec6e8af639a4b6221a117 /src
parent32024787b6b1ef39c23bda1653c23b5dfbde9e81 (diff)
downloadrneovim-460019366e58e1bcd42959f76494e38bd895e762.tar.gz
rneovim-460019366e58e1bcd42959f76494e38bd895e762.tar.bz2
rneovim-460019366e58e1bcd42959f76494e38bd895e762.zip
feat: defaults: auto-create backup dir
Copy the behavior of 'undodir' and create the last specified directory in the 'backupdir' option if it doesn't exist. Use trailing slashes for 'backupdir' as well as 'viewdir' and 'undodir' by default. Note that 'undodir' always behaves as though it has the trailing slashes, regardless of whether or not they are present. They are added to the default option value to minimize surprise. The '.' value in 'backupdir' is kept because the default behavior for backups is solely to have a backup if the save of the main file to disk fails. As soon as that save is completed the backup file is removed, so generally there is no need to put them in a central location. Co-authored by: murphy66 <murphy66@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/nvim/fileio.c18
-rw-r--r--src/nvim/option.c8
2 files changed, 22 insertions, 4 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 3d058e1d09..5099b3e812 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -2689,6 +2689,15 @@ buf_write(
* Isolate one directory name, using an entry in 'bdir'.
*/
(void)copy_option_part(&dirp, IObuff, IOSIZE, ",");
+ if (*dirp == NUL && !os_isdir(IObuff)) {
+ int ret;
+ char *failed_dir;
+ if ((ret = os_mkdir_recurse((char *)IObuff, 0755, &failed_dir)) != 0) {
+ EMSG3(_("E303: Unable to create directory \"%s\" for backup file: %s"),
+ failed_dir, os_strerror(ret));
+ xfree(failed_dir);
+ }
+ }
p = IObuff + STRLEN(IObuff);
if (after_pathsep((char *)IObuff, (char *)p) && p[-1] == p[-2]) {
// Ends with '//', Use Full path
@@ -2841,6 +2850,15 @@ nobackup:
* Isolate one directory name and make the backup file name.
*/
(void)copy_option_part(&dirp, IObuff, IOSIZE, ",");
+ if (*dirp == NUL && !os_isdir(IObuff)) {
+ int ret;
+ char *failed_dir;
+ if ((ret = os_mkdir_recurse((char *)IObuff, 0755, &failed_dir)) != 0) {
+ EMSG3(_("E303: Unable to create directory \"%s\" for backup file: %s"),
+ failed_dir, os_strerror(ret));
+ xfree(failed_dir);
+ }
+ }
p = IObuff + STRLEN(IObuff);
if (after_pathsep((char *)IObuff, (char *)p) && p[-1] == p[-2]) {
// path ends with '//', use full path
diff --git a/src/nvim/option.c b/src/nvim/option.c
index f7635fe5ec..d11bbc8ecc 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -483,17 +483,17 @@ void set_init_1(bool clean_arg)
#endif
false);
- char *backupdir = stdpaths_user_data_subpath("backup", 0, true);
+ char *backupdir = stdpaths_user_data_subpath("backup", 2, true);
const size_t backupdir_len = strlen(backupdir);
backupdir = xrealloc(backupdir, backupdir_len + 3);
memmove(backupdir + 2, backupdir, backupdir_len + 1);
memmove(backupdir, ".,", 2);
- set_string_default("viewdir", stdpaths_user_data_subpath("view", 0, true),
- true);
set_string_default("backupdir", backupdir, true);
+ set_string_default("viewdir", stdpaths_user_data_subpath("view", 2, true),
+ true);
set_string_default("directory", stdpaths_user_data_subpath("swap", 2, true),
true);
- set_string_default("undodir", stdpaths_user_data_subpath("undo", 0, true),
+ set_string_default("undodir", stdpaths_user_data_subpath("undo", 2, true),
true);
// Set default for &runtimepath. All necessary expansions are performed in
// this function.