diff --git a/app/src/command.c b/app/src/command.c index abaa223d..63afccb4 100644 --- a/app/src/command.c +++ b/app/src/command.c @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include #include "config.h" #include "common.h" @@ -202,3 +205,14 @@ process_check_success(process_t proc, const char *name) { } return true; } + +bool +is_regular_file(const char *path) { + struct stat path_stat; + int r = stat(path, &path_stat); + if (r) { + perror("stat"); + return false; + } + return S_ISREG(path_stat.st_mode); +} diff --git a/app/src/command.h b/app/src/command.h index edbc3fb8..9fc81c1c 100644 --- a/app/src/command.h +++ b/app/src/command.h @@ -85,4 +85,8 @@ process_check_success(process_t proc, const char *name); char * get_executable_path(void); +// returns true if the file exists and is not a directory +bool +is_regular_file(const char *path); + #endif diff --git a/app/src/server.c b/app/src/server.c index 90eb4c69..ff167aeb 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -67,7 +67,12 @@ get_server_path(void) { static bool push_server(const char *serial) { - process_t process = adb_push(serial, get_server_path(), DEVICE_SERVER_PATH); + const char *server_path = get_server_path(); + if (!is_regular_file(server_path)) { + LOGE("'%s' does not exist or is not a regular file\n", server_path); + return false; + } + process_t process = adb_push(serial, server_path, DEVICE_SERVER_PATH); return process_check_success(process, "adb push"); }