From c84bda4f1ca790e69483ef1e74b6d52be951d429 Mon Sep 17 00:00:00 2001
From: ticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Date: Mon, 15 Dec 2008 00:16:50 -0500
Subject: opkg: add some error codes to libopkg

git-svn-id: http://opkg.googlecode.com/svn/trunk@107 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
---
(limited to 'libopkg')

diff --git a/libopkg/opkg.c b/libopkg/opkg.c
index 0c1985d..1875b13 100644
--- a/libopkg/opkg.c
+++ b/libopkg/opkg.c
@@ -378,14 +378,14 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call
   if (old)
   {
     /* XXX: Error: Package is already installed. */
-    return 1;
+    return OPKG_PACKAGE_ALREADY_INSTALLED;
   }
 
   new = pkg_hash_fetch_best_installation_candidate_by_name(opkg->conf, package_name);
   if (!new)
   {
     /* XXX: Error: Could not find package to install */
-    return 1;
+    return OPKG_PACKAGE_NOT_FOUND;
   }
 
   new->state_flag |= SF_USER;
@@ -403,7 +403,7 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call
   {
     /* XXX: Error: Could not satisfy dependencies */
     pkg_vec_free (deps);
-    return 1;
+    return OPKG_DEPENDANCIES_FAILED;
   }
 
   /* insert the package we are installing so that we download it */
@@ -427,7 +427,7 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call
     if (pkg->src == NULL)
     {
       /* XXX: Error: Package not available from any configured src */
-      return 1;
+      return OPKG_PACKAGE_NOT_AVAILABLE;
     }
 
     sprintf_alloc(&url, "%s/%s", pkg->src->value, pkg->filename);
@@ -515,7 +515,7 @@ opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_callb
   if (pkg == NULL)
   {
     /* XXX: Error: Package not installed. */
-    return 1;
+    return OPKG_PACKAGE_NOT_INSTALLED;
   }
 
   pdata.action = OPKG_REMOVE;
@@ -526,7 +526,7 @@ opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_callb
   if (pkg->state_status == SS_NOT_INSTALLED)
   {
     /* XXX:  Error: Package seems to be not installed (STATUS = NOT_INSTALLED). */
-    return 1;
+    return OPKG_PACKAGE_NOT_INSTALLED;
   }
   progress (pdata, 25);
 
@@ -577,7 +577,7 @@ opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_call
     if (pkg == NULL)
     {
       /* XXX: Error: Package not installed in default_dest */
-      return 1;
+      return OPKG_PACKAGE_NOT_INSTALLED;
     }
   }
   else
@@ -589,7 +589,7 @@ opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_call
   if (!pkg)
   {
     /* XXX: Error: Package not installed */
-    return 1;
+    return OPKG_PACKAGE_NOT_INSTALLED;
   }
 
   pdata.action = OPKG_INSTALL;
@@ -652,7 +652,7 @@ int
 opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callback, void *user_data)
 {
   char *tmp;
-  int err;
+  int err, result = 0;
   char *lists_dir;
   pkg_src_list_elt_t *iter;
   pkg_src_t *src;
@@ -762,6 +762,7 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
     if (err)
     {
       /* XXX: Error: download error */
+      result = OPKG_DOWNLOAD_FAILED;
     }
     free (url);
 
@@ -815,7 +816,7 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
   free (tmp);
   free (lists_dir);
 
-  return 0;
+  return result;
 }
 
 
diff --git a/libopkg/opkg.h b/libopkg/opkg.h
index 73f18c9..d2a5bd0 100644
--- a/libopkg/opkg.h
+++ b/libopkg/opkg.h
@@ -32,6 +32,18 @@ enum _opkg_action_t
   OPKG_DOWNLOAD
 };
 
+enum _opkg_error_code_t
+{
+  OPKG_NO_ERROR,
+  OPKG_UNKNOWN_ERROR,
+  OPKG_DOWNLOAD_FAILED,
+  OPKG_DEPENDANCIES_FAILED,
+  OPKG_PACKAGE_ALREADY_INSTALLED,
+  OPKG_PACKAGE_NOT_AVAILABLE,
+  OPKG_PACKAGE_NOT_FOUND,
+  OPKG_PACKAGE_NOT_INSTALLED
+};
+
 struct _opkg_package_t
 {
   char *name;
--
cgit v0.9.1