From aa0d78815004ae6b0c4a42b0e024f5c4ef555ae2 Mon Sep 17 00:00:00 2001 From: dacctal Date: Sun, 24 May 2026 10:23:38 +0000 Subject: c rewrite --- src/fetch_src.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/fetch_src.c (limited to 'src/fetch_src.c') 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 +#include +#include +#include +#include +#include + +#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 -- cgit v1.2.3