]> Sergey Matveev's repositories - nnn.git/commitdiff
Clean up plugin handling code
authorArun Prakash Jana <engineerarun@gmail.com>
Sat, 19 Oct 2019 01:30:04 +0000 (07:00 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sat, 19 Oct 2019 01:30:04 +0000 (07:00 +0530)
src/nnn.c

index 91343d94c8d89c9a2b778f7199996c06f5729212..89ab55ac3325186b5cba51489897bdf3e3f6a24b 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -3264,6 +3264,27 @@ static void show_help(const char *path)
        unlink(g_tmpfpath);
 }
 
+static bool run_selected_plugin(char *path, const char *file, char *newpath, char *rundir, char *runfile, char *lastname)
+{
+       if ((cfg.runctx != cfg.curctx)
+           /* Must be in plugin directory to select plugin */
+           || (strcmp(path, plugindir) != 0))
+               return FALSE;
+
+       mkpath(path, file, newpath);
+       /* Copy to path so we can return back to earlier dir */
+       xstrlcpy(path, rundir, PATH_MAX);
+       if (runfile[0]) {
+               xstrlcpy(lastname, runfile, NAME_MAX);
+               spawn(newpath, lastname, path, path, F_NORMAL);
+               runfile[0] = '\0';
+       } else
+               spawn(newpath, NULL, path, path, F_NORMAL);
+       rundir[0] = '\0';
+       cfg.runplugin = 0;
+       return TRUE;
+}
+
 static int sum_bsizes(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
 {
        (void) fpath;
@@ -4029,22 +4050,8 @@ nochange:
 
                                /* Handle plugin selection mode */
                                if (cfg.runplugin) {
-                                       if (!plugindir || (cfg.runctx != cfg.curctx)
-                                           /* Must be in plugin directory to select plugin */
-                                           || (strcmp(path, plugindir) != 0))
+                                       if (!run_selected_plugin(path, dents[cur].name, newpath, rundir, runfile, lastname))
                                                continue;
-
-                                       mkpath(path, dents[cur].name, newpath);
-                                       /* Copy to path so we can return back to earlier dir */
-                                       xstrlcpy(path, rundir, PATH_MAX);
-                                       if (runfile[0]) {
-                                               xstrlcpy(lastname, runfile, NAME_MAX);
-                                               spawn(newpath, lastname, path, path, F_NORMAL);
-                                               runfile[0] = '\0';
-                                       } else
-                                               spawn(newpath, NULL, path, path, F_NORMAL);
-                                       rundir[0] = '\0';
-                                       cfg.runplugin = 0;
                                        setdirwatch();
                                        goto begin;
                                }
@@ -4841,20 +4848,12 @@ nochange:
                                break;
                        case SEL_PLUGKEY: // fallthrough
                        case SEL_PLUGIN:
-                               if (!plugindir) {
-                                       printwait("plugins dir missing", &presel);
-                                       goto nochange;
-                               }
-
-                               if (stat(plugindir, &sb) == -1) {
+                               /* Check if directory is accessible */
+                               if (!xdiraccess(plugindir)) {
                                        printwarn(&presel);
                                        goto nochange;
                                }
 
-                               /* Must be a directory */
-                               if (!S_ISDIR(sb.st_mode))
-                                       break;
-
                                if (sel == SEL_PLUGKEY)
                                {
                                        r = get_input("");
@@ -4889,10 +4888,6 @@ nochange:
                                        break;
                                }
 
-                               /* Check if directory is accessible */
-                               if (!xdiraccess(plugindir))
-                                       goto nochange;
-
                                xstrlcpy(rundir, path, PATH_MAX);
                                xstrlcpy(path, plugindir, PATH_MAX);
                                if (ndents)