diff options
| author | dacctal <dacctal@symlinx.net> | 2026-05-24 10:23:38 +0000 |
|---|---|---|
| committer | dacctal <dacctal@symlinx.net> | 2026-05-24 10:23:38 +0000 |
| commit | aa0d78815004ae6b0c4a42b0e024f5c4ef555ae2 (patch) | |
| tree | 62f97b4c5acfdb98003568466f878fbd3d6b9dfb /src/fetch_src.c | |
| parent | 83d471f2c1d1b1fa6be51f41e4f1c36ab19d7094 (diff) | |
c rewrite
Diffstat (limited to 'src/fetch_src.c')
| -rw-r--r-- | src/fetch_src.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/fetch_src.c b/src/fetch_src.c new file mode 100644 index 0000000..044ef12 --- /dev/null +++ b/src/fetch_src.c @@ -0,0 +1,44 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/stat.h> +#include <ftw.h> +#include <unistd.h> + +#include "fetch_src.h" +#include "fetch_git.h" +#include "vars.h" + +static int remove_tree(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) { + (void)sb; + (void)ftwbuf; + if (typeflag == FTW_F || typeflag == FTW_SL) { + unlink(fpath); + } else if (typeflag == FTW_DP) { + rmdir(fpath); + } + return 0; +} + +void fetch_src(Pkg pkg) { + printf("%starget source directory: %s\n", print_pkgit, pkg.src); + + if (file_exists(pkg.src)) { + printf("%s%s already exists. deleting...\n", print_pkgit, pkg.src); + nftw(pkg.src, remove_tree, 64, FTW_DEPTH | FTW_PHYS); + } + + if (strcmp(pkg.url, "") == 0) { + printf("%screating directory %s...\n", print_pkgit, pkg.src); + mkdir_p(pkg.src); + return; + } + + if (fetch_git(pkg) == 0) { + printf("%scloned into %s...\n", print_pkgit, pkg.src); + return; + } + + printf("%sno fetch methods worked.\n", print_error); + exit(EXIT_FAILURE); +}
\ No newline at end of file |
