Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg_numdeps: to return the number of dependencies of a given pkg pkg_resolvdeps: to find wether or not a dependency is already installed new add command unfinished
- Loading branch information
Showing
7 changed files
with
132 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include <stdio.h> | ||
#include <pkg.h> | ||
#include <stdbool.h> | ||
#include <err.h> | ||
|
||
#include "add.h" | ||
|
||
void | ||
usage_add(void) | ||
{ | ||
fprintf(stderr, "add ... <pkg-name>\n" | ||
"add\n"); | ||
} | ||
|
||
int | ||
exec_add(int argc, char **argv) | ||
{ | ||
struct pkgdb *db; | ||
struct pkgdb_it *it; | ||
struct pkg *pkg; | ||
struct pkg *p; | ||
struct pkg **deps; | ||
int ret = 0; | ||
|
||
bool installed = false; | ||
|
||
int numdeps, i; | ||
|
||
if (argc != 2) | ||
return (-1); | ||
|
||
if (pkg_open(argv[1], &pkg, 0) != 0) { | ||
return (-1); | ||
} | ||
|
||
if (pkgdb_open(&db) == -1) { | ||
pkgdb_warn(db); | ||
return (-1); | ||
} | ||
|
||
/* check if already installed */ | ||
if ((it = pkgdb_query(db, pkg_name(pkg), MATCH_EXACT)) == NULL) { | ||
pkgdb_warn(db); | ||
return (-1); | ||
} | ||
|
||
pkg_new(&p); | ||
|
||
if (pkgdb_it_next_pkg(it, &p, PKG_BASIC) == 0) { | ||
installed = true; | ||
} | ||
|
||
|
||
if (installed) { | ||
err(1, "%s is already installed\n", pkg_name(pkg)); | ||
} | ||
|
||
|
||
if ((numdeps = pkg_numdeps(pkg)) > 0) { | ||
pkg_resolvdeps(pkg, db); | ||
|
||
deps = pkg_deps(pkg); | ||
for (i = 0; deps[i] != NULL; i++) { | ||
if (pkg_type(deps[i]) == PKG_NOTFOUND) { | ||
warnx("%s-%s: unresolved dependency %s-%s", pkg_name(pkg), pkg_version(pkg), pkg_name(deps[i]), pkg_version(deps[i])); | ||
ret = 1; | ||
} | ||
} | ||
} | ||
|
||
if (ret != 0) | ||
return (ret); | ||
|
||
|
||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef _ADD_H | ||
#define _ADD_H | ||
|
||
int exec_add(int, char **); | ||
void usage_add(void); | ||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters