kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit e74921222caacde7f1d713c06961bdff6b569ee6
parent f538e921721aa8fe677e3c72159b3c5428066f70
Author: Joris Vink <joris@coders.se>
Date:   Sun,  3 Aug 2014 15:30:53 +0200

Check if conf/appl.conf exists before continuing with build or run

Diffstat:
src/cli.c | 34++++++++++++++++++++++++++--------
1 file changed, 26 insertions(+), 8 deletions(-)

diff --git a/src/cli.c b/src/cli.c @@ -81,6 +81,7 @@ static void cli_link_library(void *); static void cli_compile_cfile(void *); static void cli_mkdir(const char *, int); static int cli_dir_exists(const char *); +static int cli_file_exists(const char *); static void cli_cleanup_files(const char *); static void cli_file_writef(int, const char *, ...); static void cli_file_open(const char *, int, int *); @@ -254,8 +255,8 @@ static void cli_build(int argc, char **argv) { struct cfile *cf; - char *static_path, *p, *obj_path, *cpath; char pwd[PATH_MAX], *src_path, *static_header; + char *static_path, *p, *obj_path, *cpath, *config; if (argc == 0) { if (getcwd(pwd, sizeof(pwd)) == NULL) @@ -274,15 +275,18 @@ cli_build(int argc, char **argv) cfiles_count = 0; TAILQ_INIT(&source_files); - (void)cli_vasprintf(&obj_path, "%s/.objs", rootdir); - if (!cli_dir_exists(obj_path)) - cli_mkdir(obj_path, 0755); - (void)cli_vasprintf(&src_path, "%s/src", rootdir); (void)cli_vasprintf(&static_path, "%s/static", rootdir); + (void)cli_vasprintf(&config, "%s/conf/%s.conf", rootdir, appl); (void)cli_vasprintf(&static_header, "%s/src/static.h", rootdir); - if (!cli_dir_exists(src_path)) - cli_fatal("%s doesn't appear to be an app", appl); + if (!cli_dir_exists(src_path) || !cli_file_exists(config)) + cli_fatal("%s doesn't appear to be a kore app", appl); + + free(config); + + (void)cli_vasprintf(&obj_path, "%s/.objs", rootdir); + if (!cli_dir_exists(obj_path)) + cli_mkdir(obj_path, 0755); (void)unlink(static_header); @@ -380,6 +384,20 @@ cli_mkdir(const char *fpath, int mode) } static int +cli_file_exists(const char *fpath) +{ + struct stat st; + + if (stat(fpath, &st) == -1) + return (0); + + if (!S_ISREG(st.st_mode)) + return (0); + + return (1); +} + +static int cli_dir_exists(const char *fpath) { struct stat st; @@ -818,7 +836,7 @@ cli_cleanup_files(const char *spath) printf("couldnt unlink %s\n", cf->fpath); } - if (rmdir(spath) == -1) + if (rmdir(spath) == -1 && errno != ENOENT) printf("couldn't rmdir %s\n", spath); }