socsvn commit: r257121 - soc2013/mattbw/backend/actions

mattbw at FreeBSD.org mattbw at FreeBSD.org
Sun Sep 8 12:30:31 UTC 2013


Author: mattbw
Date: Sun Sep  8 12:30:30 2013
New Revision: 257121
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=257121

Log:
  Only update repositories which are enabled.
  

Modified:
  soc2013/mattbw/backend/actions/refresh_cache.c

Modified: soc2013/mattbw/backend/actions/refresh_cache.c
==============================================================================
--- soc2013/mattbw/backend/actions/refresh_cache.c	Sun Sep  8 11:35:56 2013	(r257120)
+++ soc2013/mattbw/backend/actions/refresh_cache.c	Sun Sep  8 12:30:30 2013	(r257121)
@@ -44,9 +44,10 @@
  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <assert.h>		/* assert */
 #include <glib.h>		/* gboolean */
 #include <stdbool.h>		/* bool, true, false */
 #include "../pk-backend.h"	/* pk..., Pk... */
@@ -57,37 +58,65 @@
 #include "../query.h"		/* query_... */
 #include "../utils.h"		/* STATUS, ERR */
 
+static bool	update_repo(struct pkg_repo *repo, bool force);
+
 /*
- * The thread that performs a RefreshCache operation. Should be invoked
- * by the pk_backend_refresh_cache hook.
+ * The thread that performs a RefreshCache operation. Should be invoked by
+ * the pk_backend_refresh_cache hook.
  */
 gboolean
 refresh_cache_thread(PkBackend *backend)
 {
+	bool		success;
 	gboolean	force;
-	int		err;
 	struct pkg_repo *repo;
 
-	err = EPKG_FATAL;
+	assert(backend != NULL);
 
 	STATUS(backend, PK_STATUS_ENUM_QUERY);
 
 	force = pk_backend_get_bool(backend, "force");
 
 	repo = NULL;
-	while (pkg_repos(&repo) == EPKG_OK) {
-		err = pkg_update(repo, force);
-		/* Intentionally silence already-up-to-date errors. */
-		if (err == EPKG_UPTODATE)
-			err = EPKG_OK;
-		else if (err != EPKG_OK) {
-			ERR(backend,
-			    PK_ERROR_ENUM_REPO_NOT_AVAILABLE,
-			    "could not update repo");
+	success = true;
+	while (success) {
+		int		err;
+
+		err = pkg_repos(&repo);
+		if (err == EPKG_OK) {
+			success = update_repo(repo, force);
+		} else {
+			/* Did we run out of repos? */
+			success = (err == EPKG_END);
 			break;
 		}
 	}
 
+	if (!success) {
+		ERR(backend,
+		    PK_ERROR_ENUM_REPO_NOT_AVAILABLE,
+		    "Repository update failed.");
+	}
 	pk_backend_finished(backend);
-	return (err == EPKG_OK) ? TRUE : FALSE;
+	return success ? TRUE : FALSE;
+}
+
+static bool
+update_repo(struct pkg_repo *repo, bool force)
+{
+	bool		success;
+
+	assert(repo != NULL);
+
+	/* Claim success if we don't need to update the repo. */
+	success = true;
+
+	/* Don't update disabled repositories. */
+	if (pkg_repo_enabled(repo)) {
+		int		err;
+
+		err = pkg_update(repo, force);
+		success = (err == EPKG_OK || err == EPKG_UPTODATE);
+	}
+	return success;
 }


More information about the svn-soc-all mailing list