]> git.draconx.ca Git - upkg.git/commitdiff
package: Make the VFS directly open the package file.
authorNick Bowler <nbowler@draconx.ca>
Tue, 8 Dec 2009 05:54:58 +0000 (00:54 -0500)
committerNick Bowler <nbowler@draconx.ca>
Tue, 8 Dec 2009 05:54:58 +0000 (00:54 -0500)
This is in preparation for moving the package search mechanism to the
VFS, as it nicely allows us to ensure that candidate packages actually
open successfully.

src/uobject/package.c
src/uobject/vfs.c
src/uobject/vfs.h

index af4ebb3f929cd82c7f6441f9bc8f8d78029fcd06..2da23b3fc63383e781523cc1e8604e10c4890553 100644 (file)
@@ -87,15 +87,9 @@ static gboolean u_pkg_load(GTypeModule *m)
 {
        struct upkg_priv *priv = U_PKG_GET_PRIV(m);
        int (*init_func)(GTypeModule *);
-       const char *file;
 
-       file = u_pkg_vfs_lookup(m->name);
-       if (file) {
-               U_PKG(m)->pkg = upkg_fopen(file);
-               if (!U_PKG(m)->pkg) {
-                       return FALSE;
-               }
-       }
+       /* Ignore failure here until we get rid of native-only packages. */
+       U_PKG(m)->pkg = u_pkg_vfs_open_by_name(m->name);
 
        priv->native = lt_dlopenext(m->name);
        if (priv->native) {
index 5465144d2826b561854e9c00e4b0bb9a001908a2..fcbb3e51c273ac407078dea406a3aa25c9b909f1 100644 (file)
@@ -23,6 +23,7 @@
 #include <strings.h>
 
 #include <uobject/vfs.h>
+#include <upkg.h>
 #include <ltdl.h>
 
 #include "avl.h"
@@ -123,17 +124,17 @@ void u_pkg_vfs_del_local(const char *name)
        free(item);
 }
 
-const char *u_pkg_vfs_lookup(const char *name)
+struct upkg *u_pkg_vfs_open_by_name(const char *name)
 {
        struct local_pkg spec = { .name = (char *)name }, *item;
 
-       if (!local_tree)
+       if (!initialized)
                return NULL;
 
        item = avl_find(local_tree, &spec);
-       if (!item)
-               return NULL;
-       return item->file;
+       if (item)
+               return upkg_fopen(item->file);
+       return NULL;
 }
 
 int u_pkg_vfs_init(void)
index d986aeca3907900aaa005f1289a4d083db7c5552..bc835a782294137018e5f6f0c3e6a8327d0bb416 100644 (file)
@@ -18,6 +18,8 @@
 #ifndef U_OBJECT_VFS_H_
 #define U_OBJECT_VFS_H_
 
+#include <upkg.h>
+
 /*
  * Insert a local package to the VFS.  A "local package" is an explicit
  * association of a name to a file, and thus can be located outside the normal
@@ -35,9 +37,23 @@ const char *u_pkg_vfs_add_local(const char *name, const char *file);
 void u_pkg_vfs_del_local(const char *name);
 
 /*
- * Find a package by name in the VFS.  Names are case-insensitive.
+ * Opens a package file by name.  First, local packages are searched for a
+ * match.  If a local match is found, the global search path is never
+ * consulted.  If no local match is found, the directories in the global search
+ * path are examined, in order.
+ *
+ * When searching the global search path, the first file found which both
+ * matches the given name and can be opened successfully is used.  A file
+ * foo.EXT matches the name if foo is equal to name (without regard to case)
+ * and EXT is one of u, utx, uax, umx or unr.  If multiple extensions
+ * are valid, they are tried in this order.
+ *
+ * Note that the particular file extension used does not make any difference
+ * as to what sort of objects can be contained in a package.
+ *
+ * Returns the opened package on success, or NULL on failure.
  */
-const char *u_pkg_vfs_lookup(const char *name);
+struct upkg *u_pkg_vfs_open_by_name(const char *name);
 
 /*
  * Initialize the UObject VFS system.  Returns 0 on success, -1 otherwise.