Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Implement availability to display list of all locked packages with lock command
Andrej Zverev committed 11 years ago
commit cbdde18955674f348bcd28e354047d25ddb8bdaf
parent 332fed5
3 files changed +47 -3
modified docs/pkg-lock.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd April 18, 2014
+
.Dd May 10, 2014
.Dt PKG-LOCK 8
.Os
.Sh NAME
@@ -74,6 +74,8 @@ The following options are supported by
.Bl -tag -width F1
.It Fl a
Lock or unlock all installed packages.
+
.It Fl l
+
List of all locked packages.
.It Fl C
Make the standard or the regular expression
.Fl ( x )
modified src/lock.c
@@ -48,7 +48,7 @@ void
usage_lock(void)
{
	fprintf(stderr, "Usage: pkg lock [-qy] [-Cgix] <pkg-name>\n");
-
	fprintf(stderr, "       pkg lock [-qy] -a\n");
+
	fprintf(stderr, "       pkg lock [-qy] -al\n");
	fprintf(stderr, "       pkg unlock [-qy] [-Cgix] <pkg-name>\n");
	fprintf(stderr, "       pkg unlock [-qy] -a\n");
	fprintf(stderr, "For more information see 'pkg help lock'.\n");
@@ -106,6 +106,38 @@ exec_unlock(int argc, char **argv)
	return (exec_lock_unlock(argc, argv, UNLOCK));
}

+
int 
+
list_locked()
+
{
+
        struct pkgdb *db = NULL;
+
        struct pkgdb_it *it = NULL;
+
        struct pkg *pkg = NULL;
+
        const char *pkg_name, *pkg_version;
+
 
+
	if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK)
+
		return (EX_IOERR);
+
                        
+
	if (pkgdb_obtain_lock(db, PKGDB_LOCK_READONLY, 0, 0) != EPKG_OK) {
+
		pkgdb_close(db);
+
		warnx("Cannot get a read lock on a database, it is locked by another process");
+
		return (EX_TEMPFAIL);
+
	}
+

+
	if ((it = pkgdb_query(db, " where locked=1", MATCH_CONDITION)) == NULL) {
+
		pkgdb_close(db);
+
		return (EX_UNAVAILABLE);
+
	}
+

+
	while (pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC) == EPKG_OK) {
+
		pkg_get(pkg, PKG_NAME, &pkg_name, PKG_VERSION, &pkg_version);
+
                printf("%s-%s\n", pkg_name, pkg_version);
+
	}
+
	pkgdb_release_lock(db, PKGDB_LOCK_READONLY);
+
	pkgdb_close(db);
+
	return (EX_OK);
+

+
}
+

static int
exec_lock_unlock(int argc, char **argv, enum action action)
{
@@ -125,11 +157,20 @@ exec_lock_unlock(int argc, char **argv, enum action action)
                pkg_object_bool(pkg_config_get("CASE_SENSITIVE_MATCH"))
                );

-
	while ((ch = getopt(argc, argv, "aCgiqxy")) != -1) {
+
	while ((ch = getopt(argc, argv, "alCgiqxy")) != -1) {
		switch (ch) {
		case 'a':
			match = MATCH_ALL;
			break;
+
		case 'l':
+
			if (action == LOCK) {
+
				exitcode = list_locked();
+
				return exitcode;
+
			} else {
+
				warnx("list of locked packages useless with unlock command");
+
				return (EX_USAGE);
+
			}
+

		case 'C':
			pkgdb_set_case_sensitivity(true);
			break;
modified src/pkgcli.h
@@ -87,6 +87,7 @@ void usage_plugins(void);
/* pkg lock */
int exec_lock(int, char **);
int exec_unlock(int, char **);
+
int list_locked();
void usage_lock(void);

/* pkg query */