[Midnightbsd-cvs] src [7381] trunk/lib/libmport: add a new public api for fetching indexes explicitly
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sun Nov 29 10:48:44 EST 2015
Revision: 7381
http://svnweb.midnightbsd.org/src/?rev=7381
Author: laffer1
Date: 2015-11-29 10:48:43 -0500 (Sun, 29 Nov 2015)
Log Message:
-----------
add a new public api for fetching indexes explicitly
Modified Paths:
--------------
trunk/lib/libmport/index.c
trunk/lib/libmport/mport.h
Modified: trunk/lib/libmport/index.c
===================================================================
--- trunk/lib/libmport/index.c 2015-11-29 03:51:46 UTC (rev 7380)
+++ trunk/lib/libmport/index.c 2015-11-29 15:48:43 UTC (rev 7381)
@@ -68,22 +68,7 @@
if (index_last_checked_recentish(mport))
return MPORT_OK;
- if (mport_fetch_index(mport) != MPORT_OK) {
- SET_ERROR(MPORT_ERR_WARN, "Could not fetch updated index; previous index used.");
- RETURN_CURRENT_ERROR;
- } else {
- if (mport_db_do(mport->db, "DETACH idx") != MPORT_OK)
- RETURN_CURRENT_ERROR;
-
- mport->flags &= ~MPORT_INST_HAVE_INDEX;
-
- if (mport_db_do(mport->db, "ATTACH %Q AS idx", MPORT_INDEX_FILE) != MPORT_OK)
- RETURN_CURRENT_ERROR;
-
- mport->flags |= MPORT_INST_HAVE_INDEX;
- if (index_update_last_checked(mport) != MPORT_OK)
- RETURN_CURRENT_ERROR;
- }
+ return mport_index_get(mport);
}
} else {
if (mport_fetch_bootstrap_index(mport) != MPORT_OK)
@@ -100,10 +85,48 @@
RETURN_CURRENT_ERROR;
}
- return MPORT_OK;
+ return (MPORT_OK);
}
+/**
+ * mport_index_load is typically preferred. This function is only used to force
+ * a download of the index manually by the user.
+ */
+MPORT_PUBLIC_API int
+mport_index_get(mportInstance *mport)
+{
+
+ if (!(mport->flags & MPORT_INST_HAVE_INDEX)) {
+ if (mport_fetch_bootstrap_index(mport) != MPORT_OK)
+ RETURN_CURRENT_ERROR;
+ } else {
+ if (mport_fetch_index(mport) != MPORT_OK) {
+ SET_ERROR(MPORT_ERR_WARN, "Could not fetch updated index; previous index used.");
+ RETURN_CURRENT_ERROR;
+ }
+ }
+
+ /* if we were already attached, reconnect refreshed index. */
+ if (mport->flags & MPORT_INST_HAVE_INDEX) {
+ if (mport_db_do(mport->db, "DETACH idx") != MPORT_OK)
+ RETURN_CURRENT_ERROR;
+
+ mport->flags &= ~MPORT_INST_HAVE_INDEX;
+
+ if (mport_db_do(mport->db, "ATTACH %Q AS idx", MPORT_INDEX_FILE) != MPORT_OK)
+ RETURN_CURRENT_ERROR;
+
+ mport->flags |= MPORT_INST_HAVE_INDEX;
+ }
+
+ if (index_update_last_checked(mport) != MPORT_OK)
+ RETURN_CURRENT_ERROR;
+
+ return (MPORT_OK);
+}
+
+
/* return 1 if the index is younger than the max age, 0 otherwise */
static int
index_is_recentish(void)
Modified: trunk/lib/libmport/mport.h
===================================================================
--- trunk/lib/libmport/mport.h 2015-11-29 03:51:46 UTC (rev 7380)
+++ trunk/lib/libmport/mport.h 2015-11-29 15:48:43 UTC (rev 7381)
@@ -140,6 +140,7 @@
} mportIndexEntry;
int mport_index_load(mportInstance *);
+int mport_index_get(mportInstance *);
int mport_index_lookup_pkgname(mportInstance *, const char *, mportIndexEntry ***);
int mport_index_search(mportInstance *, mportIndexEntry ***, const char *, ...);
void mport_index_entry_free_vec(mportIndexEntry **);
More information about the Midnightbsd-cvs
mailing list