tLoad pack from either a tarball or a name - pm - barely a pack manager
(HTM) git clone git://z3bra.org/pm
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 953787c303624bcc096216c5ccf232cbadfe0b3c
(DIR) parent 07cdaa8ebcaebae5fb50e9b28b6977445418bd86
(HTM) Author: z3bra <willyatmailoodotorg>
Date: Sun, 19 Jun 2016 01:39:27 +0200
Load pack from either a tarball or a name
Loading a pack data structure can now be done either from a tarball, or from
an installed pack using its name only.
The only "real" change brough here is that one can now delete an install pack
by using a tarball as an argument as in,
# delete the pack this tarball would install
pm -d pm#1.0.tar.bz2
not *that* useful but the change strives for correctness/generality also.
Diffstat:
M pm.c | 25 ++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)
---
(DIR) diff --git a/pm.c b/pm.c
t@@ -214,21 +214,23 @@ pack_load_tarball(char *path)
struct pack *
pack_load_metadata(const char *datadir, char *name)
{
+ struct stat st;
struct pack *pack = NULL;
char tmp[PATH_MAX] = "";
+ snprintf(tmp, PATH_MAX, "%s/%s", datadir, name);
+
+ if (stat(tmp, &st) < 0)
+ return NULL;
+
if (!(pack = malloc(sizeof(struct pack)))) {
perror("malloc");
return NULL;
}
- pack->path = NULL;
- pack->name = NULL;
- pack->version = malloc(LINE_MAX);
-
- snprintf(tmp, PATH_MAX, "%s/%s", datadir, name);
- pack->path = strdup(tmp);
pack->name = strdup(name);
+ pack->path = strdup(tmp);
+ pack->version = malloc(LINE_MAX);
inspect_version(datadir, pack->name, pack->version);
return pack;
t@@ -244,13 +246,11 @@ pack_load(const char *datadir, char *path)
struct pack *p = NULL;
struct stat st;
- if (stat(path, &st) < 0) {
- perror(path);
- } else if (S_ISREG(st.st_mode)) {
+ if ((p = pack_load_metadata(datadir, path)) != NULL)
+ return p;
+
+ if (!stat(path, &st) && S_ISREG(st.st_mode))
p = pack_load_tarball(path);
- } else if (S_ISDIR(st.st_mode)) {
- p = pack_load_metadata(datadir, path);
- }
return p;
}
t@@ -775,7 +775,6 @@ delete(const char *rootfs, const char *datadir, char *name)
{
int r = 0;
struct pack *p = NULL;
- char tmp[PATH_MAX] = "";
if ((p = pack_load(datadir, name)) == NULL)
return ERR_PACK_LOAD;