|
50 | 50 | #include "lib/strutil.h" // utf string functions
|
51 | 51 | #include "lib/fileloc.h"
|
52 | 52 | #include "lib/lock.h"
|
53 |
| -#include "lib/util.h" // tilde_expand() |
| 53 | +#include "lib/util.h" // tilde_expand(), x_basename() |
54 | 54 | #include "lib/vfs/vfs.h"
|
55 | 55 | #include "lib/widget.h"
|
56 | 56 | #include "lib/event.h" // mc_event_raise()
|
@@ -763,6 +763,49 @@ editcmd_dialog_raw_key_query_cb (Widget *w, Widget *sender, widget_msg_t msg, in
|
763 | 763 | }
|
764 | 764 | }
|
765 | 765 |
|
| 766 | +/* --------------------------------------------------------------------------------------------- */ |
| 767 | + |
| 768 | +static gboolean |
| 769 | +editcmd_check_and_create_user_syntax_directory (const vfs_path_t *user_syntax_file_vpath) |
| 770 | +{ |
| 771 | + gboolean ret; |
| 772 | + struct stat st; |
| 773 | + |
| 774 | + ret = mc_stat (user_syntax_file_vpath, &st) == 0; |
| 775 | + if (!ret) |
| 776 | + { |
| 777 | + // file doesn't exist -- check why |
| 778 | + const char *user_syntax_file_path = vfs_path_as_str (user_syntax_file_vpath); |
| 779 | + |
| 780 | + // check directory |
| 781 | + const char *user_syntax_file_basename = x_basename (user_syntax_file_path); |
| 782 | + char *user_syntax_dir; |
| 783 | + vfs_path_t *user_syntax_vpath; |
| 784 | + |
| 785 | + user_syntax_dir = |
| 786 | + g_strndup (user_syntax_file_path, user_syntax_file_basename - user_syntax_file_path); |
| 787 | + user_syntax_vpath = vfs_path_from_str (user_syntax_dir); |
| 788 | + |
| 789 | + ret = mc_stat (user_syntax_vpath, &st) == 0; |
| 790 | + if (!ret) |
| 791 | + ret = mc_mkdir (user_syntax_vpath, 0700) == 0; |
| 792 | + else if (!S_ISDIR (st.st_mode)) |
| 793 | + { |
| 794 | + ret = FALSE; |
| 795 | + // set for file_error_message() |
| 796 | + errno = EEXIST; |
| 797 | + } |
| 798 | + |
| 799 | + if (!ret) |
| 800 | + file_error_message (_ ("Cannot create directory\n%s"), user_syntax_dir); |
| 801 | + |
| 802 | + vfs_path_free (user_syntax_vpath, TRUE); |
| 803 | + g_free (user_syntax_dir); |
| 804 | + } |
| 805 | + |
| 806 | + return ret; |
| 807 | +} |
| 808 | + |
766 | 809 | /* --------------------------------------------------------------------------------------------- */
|
767 | 810 | /*** public functions ****************************************************************************/
|
768 | 811 | /* --------------------------------------------------------------------------------------------- */
|
@@ -1146,9 +1189,14 @@ edit_load_syntax_file (WDialog *h)
|
1146 | 1189 | vfs_path_t *user_syntax_file_vpath;
|
1147 | 1190 |
|
1148 | 1191 | user_syntax_file_vpath = mc_config_get_full_vpath (EDIT_SYNTAX_FILE);
|
1149 |
| - check_for_default (extdir_vpath, user_syntax_file_vpath); |
1150 |
| - edit_arg_init (&arg, user_syntax_file_vpath, 0); |
1151 |
| - ret = edit_load_file_from_filename (h, &arg); |
| 1192 | + |
| 1193 | + if (editcmd_check_and_create_user_syntax_directory (user_syntax_file_vpath)) |
| 1194 | + { |
| 1195 | + check_for_default (extdir_vpath, user_syntax_file_vpath); |
| 1196 | + edit_arg_init (&arg, user_syntax_file_vpath, 0); |
| 1197 | + ret = edit_load_file_from_filename (h, &arg); |
| 1198 | + } |
| 1199 | + |
1152 | 1200 | vfs_path_free (user_syntax_file_vpath, TRUE);
|
1153 | 1201 | }
|
1154 | 1202 | else if (dir == 1)
|
|
0 commit comments