aboutsummaryrefslogtreecommitdiff
path: root/src/repo.c
blob: 49d815ddc0808acfb113f69a60e4332709995518 (plain)
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
56
57
58
59
60
61
62
63
64
65
66
#include "repo.h"

#include "dirent.h"
#include "limits.h"
#include "malloc.h"
#include "package.h"
#include "stdio.h"
#include <lua.h>

int repo_check_package(pow_repo **repos, size_t repo_count, const char *query) {
  if (!repos) {
    printf("no repos defined in your config, please define them\n");

    return 1;
  }

  DIR *dp;
  struct dirent *ep;

  for (size_t i = 0; i < repo_count; i++) {
    char *package_path = malloc(PATH_MAX);

    if (!package_path) {
      printf("failed to allocate package_path, sizeof %zu\n", PATH_MAX);

      return 1;
    }

    int written =
        snprintf(package_path, PATH_MAX, "%s/%s", repos[i]->path, query);

    if (written >= PATH_MAX) {
      printf("something went seriously wrong. the path for the package %s is "
             "too long?\n",
             query);

      free(package_path);

      return 1;
    }

    dp = opendir(package_path);

    free(package_path);

    if (!dp) {
      continue;
    }

    printf("found package %s in repo %s\n", query, repos[i]->path);

    pow_package *pkg = malloc(sizeof(pow_package));

    package_open(pkg, "./testing/samurai/1.3.lua");

    printf("Name: %s\n"
           "Version: %s\n",
           pkg->name, pkg->version);

    package_close(pkg);

    closedir(dp);
  }

  return 0;
}