-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.c
More file actions
137 lines (114 loc) · 2.75 KB
/
package.c
File metadata and controls
137 lines (114 loc) · 2.75 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// NurOS Ruzen42 2026 apg/package.c
// Last change: Feb 5
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "../include/apg/package.h"
#include "../include/util.h"
#include "../include/apg/archive.h"
#include "apg/json.h"
static const char *tmp_path = "/tmp/apg/";
struct package_metadata *
package_metadata_new(void)
{
struct package_metadata *meta = calloc(1, sizeof(*meta));
if (!meta) return NULL;
return meta;
}
struct package *
package_new(void)
{
// ReSharper disable once CppDFAMemoryLeak
struct package *pkg = calloc(1, sizeof(*pkg));
if (!pkg) return NULL;
pkg->meta = package_metadata_new();
if (!pkg->meta) {
free(pkg);
return NULL;
}
return pkg;
}
void
str_list_free(struct str_list *list)
{
if (!list) return;
free(list->items);
}
void
package_metadata_free(struct package_metadata *meta)
{
if (!meta) return;
free(meta->name);
free(meta->version);
free(meta->architecture);
free(meta->maintainer);
free(meta->license);
free(meta->homepage);
str_list_free(&meta->dependencies);
str_list_free(&meta->conflicts);
str_list_free(&meta->provides);
str_list_free(&meta->replaces);
str_list_free(&meta->tags);
free(meta);
}
void
package_free(struct package *pkg)
{
if (!pkg) return;
package_metadata_free(pkg->meta);
free((void *) pkg->pkg_path);
str_list_free(&pkg->package_files);
free(pkg);
}
bool
install_package(const struct package *pkg)
{
return install_package_in_root(pkg, "/");
}
bool
install_package_in_root(const struct package *pkg, const char *root_path)
{
log_two(INF, "Installing package into: ", root_path, stdout);
// signing will be there
char *real_tmp = concat_dirs(root_path, tmp_path);
create_dir(real_tmp);
free(real_tmp);
return true;
}
struct package *
parse_package(const char *path, const char *root_path)
{
struct package *pkg = package_new();
if (!pkg) return NULL;
pkg->pkg_path = realpath(path, NULL);
if (!pkg->pkg_path) {
package_free(pkg);
return NULL;
}
char *real_tmp = concat_dirs(root_path, tmp_path);
if (!real_tmp) {
package_free(pkg);
return NULL;
}
create_dir(real_tmp);
if (!unarchive_package_in_root(pkg, real_tmp)) {
free(real_tmp);
package_free(pkg);
return NULL;
}
char *meta_path = concat_dirs(real_tmp, "metadata.json");
free(real_tmp);
if (!meta_path) {
package_free(pkg);
return NULL;
}
package_metadata_free(pkg->meta);
pkg->meta = package_metadata_from_file(meta_path);
free(meta_path);
if (!pkg->meta) {
package_free(pkg);
return NULL;
}
return pkg;
}