-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
89 lines (71 loc) · 1.65 KB
/
main.c
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Main //
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include "main.h"
#include "sqlite.h"
#include "utils.h"
#include "options.h"
/*
* Function to check database
*/
static int check_db(char *db_path) {
struct stat buf;
if(stat(db_path, &buf) == -1)
if(errno == ENOENT)
return 1;
return 0;
}
pkg_t* get_pkgs(pkg_t *pkg) {
pkg_t* pkgs = get_pkg_from_db(DB_PATH, pkg);
if(!pkgs)
return NULL;
return pkgs;
}
int show_pkg(pkg_t *pkg) {
if(!pkg)
return -1;
printf("\tpkg->name = %s\n", pkg->name);
printf("\tpkg->version = %s\n", pkg->version);
printf("\tpkg->descr = %s\n", pkg->descr);
printf("\tpkg->license = %s\n", pkg->license);
printf("\tpkg->btime = %s\n", pkg->btime);
printf("\tpkg->itime = %s\n", pkg->itime);
printf("\n");
return 0;
}
int install_pkg(pkg_t *pkg, char *filename) {
if(!pkg->name || !pkg->version) {
fprintf(stderr, "ABORT! No name and version of package!\n");
return 1;
}
if(!filename) {
fprintf(stderr, "ABORT! No package to install. Use -f <pkg_file>\n");
return 1;
}
if(extract_pkg(filename, "/tmp/pkgmgr")) {
fprintf(stderr, "Extract function returned an error\n");
return 1;
}
add_pkg_to_db(DB_PATH, pkg);
return 0;
}
int del_pkg(pkg_t *pkg) {
if(!pkg->name) {
fprintf(stderr, "ABORT! No name and version of package!\n");
return 1;
}
del_pkg_from_db(DB_PATH, pkg);
return 0;
}
int main(int argc, char **argv) {
if(check_db(DB_PATH))
if(create_table(DB_PATH))
exit(1);
parse_opts(argc, argv);
return 0;
}