ckiss

KISS in C
git clone git://bvnf.space/ckiss.git
Log | Files | Refs | README | LICENSE

download.c (1328B)


      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
#include <stdio.h>
#include <unistd.h>
#include "utils.h"
#include "actions.h"
#include "pkg.h"

int
git_download(struct source *s, struct env *e) {
    return 0;
}

int
http_download(struct source *s, struct env *e) {
    if (access(s->cachefile, F_OK) == 0) {
        mylog2("cached", s->cachefile);
        return 0;
    }
    /* TODO: this only works once! need to copy e->get, not modify it. */
    size_t i;
    for (i = 0; i < 6; i++) {
        if (e->get[i] == NULL)
            break;
    }
    if (i > 5) die2(e->get[0], "too many args");
    e->get[i++] = s->cachefile;
    e->get[i++] = s->remote;
    e->get[i] = NULL;

    return run(e->get);
}

int
download(int argc, char **argv, struct env *e) {
    if (argc < 2)
        die2("download", "need a package(s)");

    for (int i = 1; i < argc; i++) {
        struct pkg *p = pkg_parse_sources(argv[i], e);
        for (size_t j = 0; j < p->n; j++) {
            switch (p->s[j]->type) {
                case SRC_GIT:
                    git_download(p->s[j], e);
                    break;
                case SRC_HTTP:
                    http_download(p->s[j], e);
                    break;
                case SRC_FILE: /* FALLTHROUGH */
                default:
                    break;
            }
        }
        pkg_free(p);
    }
    return 0;
}