diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2022-08-25 16:58:38 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2022-08-26 04:05:02 +0200 |
commit | 532b3ae9b5cd8609237e04db768cc1f750d8631d (patch) | |
tree | f65253a6ce9970d1d93e6bb6c65758d6fa98373a /src/file.c | |
parent | cmake: ignore unused parameters for now (diff) | |
download | cimple-532b3ae9b5cd8609237e04db768cc1f750d8631d.tar.gz cimple-532b3ae9b5cd8609237e04db768cc1f750d8631d.zip |
add some more code
This adds a basic "worker" program.
You can now do something like
./server &
./worker &
./client ci_run URL REV
and the server should pass a message to worker, after which it should
clone the repository at URL, checkout REV, and try to run the CI script.
It's extremely unfinished: I need to sort out the graceful shutdown, how
the server manages workers, etc.
Diffstat (limited to '')
-rw-r--r-- | src/file.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/file.c b/src/file.c new file mode 100644 index 0000000..ede640b --- /dev/null +++ b/src/file.c @@ -0,0 +1,61 @@ +#include "file.h" +#include "log.h" + +#include <ftw.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <unistd.h> + +static int unlink_cb(const char *fpath, const struct stat *, int, struct FTW *) +{ + int ret = 0; + + ret = remove(fpath); + if (ret < 0) { + print_errno("remove"); + return ret; + } + + return ret; +} + +int rm_rf(const char *dir) +{ + print_log("Recursively removing directory: %s\n", dir); + return nftw(dir, unlink_cb, 64, FTW_DEPTH | FTW_PHYS); +} + +int my_chdir(const char *dir, char **old) +{ + int ret = 0; + + if (old) { + *old = get_current_dir_name(); + if (!*old) { + print_errno("get_current_dir_name"); + return -1; + } + } + + ret = chdir(dir); + if (ret < 0) { + print_errno("chdir"); + goto free_old; + } + + return ret; + +free_old: + if (old) + free(*old); + + return ret; +} + +int file_exists(const char *path) +{ + struct stat stat; + int ret = lstat(path, &stat); + return !ret && S_ISREG(stat.st_mode); +} |