From 95705e381b2256df902ae36f64167b882dba7548 Mon Sep 17 00:00:00 2001 From: Joursoir Date: Thu, 25 Aug 2022 19:38:00 +0300 Subject: tree: move printing error into check_sneaky_paths() Avoid repeating the same error messages. --- src/exec-cmd.c | 30 +++++++++--------------------- src/routines.c | 5 ++++- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/exec-cmd.c b/src/exec-cmd.c index 570bdb5..1bfc3ff 100644 --- a/src/exec-cmd.c +++ b/src/exec-cmd.c @@ -95,10 +95,8 @@ int cmd_insert(int argc, char *argv[]) } result = check_sneaky_paths(path); - if(result) { - print_error("Error: You have used forbidden paths\n"); + if(result) return 1; - } if(file_exist(path) == F_ISFILE) { if(!flag_force) { @@ -176,10 +174,8 @@ int cmd_edit(int argc, char *argv[]) } result = check_sneaky_paths(path); - if(result) { - print_error("Error: You have used forbidden paths\n"); + if(result) return 1; - } result = file_exist(path); if(result == F_NOEXIST) { @@ -304,10 +300,8 @@ int cmd_generate(int argc, char *argv[]) } result = check_sneaky_paths(path); - if(result) { - print_error("Error: You have used forbidden paths\n"); + if(result) return 1; - } result = file_exist(path); if(result == F_ISFILE) { @@ -351,10 +345,8 @@ int cmd_remove(int argc, char *argv[]) } result = check_sneaky_paths(path); - if(result) { - print_error("Error: You have used forbidden paths\n"); + if(result) return 1; - } result = file_exist(path); if(result == F_NOEXIST) { @@ -409,10 +401,9 @@ int cmd_move(int argc, char *argv[]) dbgprint("new-path = %s\n", new_path); result = check_sneaky_paths(old_path); - if(result) { - print_error("Error: You have used forbidden paths\n"); + if(result) return 1; - } + result = file_exist(old_path); if(result == F_NOEXIST) { print_error("Error: No such file exists\n"); @@ -420,10 +411,9 @@ int cmd_move(int argc, char *argv[]) } result = check_sneaky_paths(new_path); - if(result) { - print_error("Error: You have used forbidden paths\n"); + if(result) return 1; - } + result = file_exist(new_path); if(result != F_NOEXIST) { if(!flag_force) { @@ -506,10 +496,8 @@ int cmd_showtree(int argc, char *argv[]) const char *path = "."; if(argv[optind]) { result = check_sneaky_paths(argv[optind]); - if(result) { - print_error("Error: You have used forbidden paths\n"); + if(result) return 1; - } path = argv[optind]; } diff --git a/src/routines.c b/src/routines.c index 09916aa..21c569b 100644 --- a/src/routines.c +++ b/src/routines.c @@ -33,6 +33,7 @@ #if defined(DISPLAY) #include "r-x11.h" #endif +#include "output.h" #define NUMBER_ALLOWED_CHARS (10+26+26+8) @@ -72,8 +73,10 @@ int check_sneaky_paths(const char *path) int length = strlen(path), i; for(i = 1; i < length; i++) { - if(path[i-1] == '.' && path[i] == '.') + if(path[i-1] == '.' && path[i] == '.') { + print_error("Error: You have used forbidden paths\n"); return 1; + } } return 0; } -- cgit v1.2.3-18-g5258