diff options
| author | 2019-01-30 20:59:39 +0530 | |
|---|---|---|
| committer | 2019-01-30 20:59:39 +0530 | |
| commit | 2324e8e3e75c4aff1672afb3cbc377de1977e71c (patch) | |
| tree | 328ec354515557f4a868509dcd3c4ae4c957752e | |
| parent | 0fb49390dfd8242eae32c3db1970d30173c4bc4d (diff) | |
| download | nnn-2324e8e3e75c4aff1672afb3cbc377de1977e71c.tar.gz | |
Add an api to check if copying possible
| -rw-r--r-- | src/nnn.c | 40 |
1 files changed, 24 insertions, 16 deletions
@@ -855,6 +855,29 @@ static bool showcplist() return TRUE; } +static bool cpsafe() +{ + /* Fail if copy file path not generated */ + if (!g_cppath[0]) { + printmsg("copy file not found"); + return FALSE; + } + + /* Warn if selection not completed */ + if (cfg.copymode) { + printmsg("finish selection first"); + return FALSE; + } + + /* Fail if copy file path isn't accessible */ + if (access(g_cppath, R_OK) == -1) { + printmsg("empty selection list"); + return FALSE; + } + + return TRUE; +} + /* Initialize curses mode */ static bool initcurses(void) { @@ -3423,23 +3446,8 @@ nochange: case SEL_MV: case SEL_RMMUL: { - /* Fail if copy file path not generated */ - if (!g_cppath[0]) { - printmsg("copy file not found"); - goto nochange; - } - - /* Warn if selection not completed */ - if (cfg.copymode) { - printmsg("finish selection first"); + if (!cpsafe()) goto nochange; - } - - /* Fail if copy file path isn't accessible */ - if (access(g_cppath, R_OK) == -1) { - printmsg("empty selection list"); - goto nochange; - } if (sel == SEL_CP) { snprintf(g_buf, CMD_LEN_MAX, |