]> git.draconx.ca Git - upkg.git/blobdiff - src/upkg.c
uobject: Implement an interface for loading/unloading.
[upkg.git] / src / upkg.c
index ed6d4dfdeaf8a9844d51e4f22d3a6eda1912699d..87794cb6b1c3b6413e2d68383742a1b3c00e0b85 100644 (file)
@@ -28,6 +28,7 @@
 #include "module.h"
 #include "uobject.h"
 #include "exportable.h"
+#include "loadable.h"
 
 enum {
        MODE_INFO,
@@ -156,27 +157,39 @@ static int export(struct upkg *pkg, GObject *obj, unsigned idx)
        struct upkg_file *f = upkg_export_open(pkg, idx);
        char name[256];
        FILE *of;
-       int rc;
+       int rc = -1;
 
        if (u_object_deserialize(obj, f) != 0) {
-               return -1;
+               goto out;
        }
+
+       if (U_OBJECT_IS_LOADABLE(obj) && u_object_load(obj) != 0) {
+               goto out;
+       }
+
        u_object_export_name(obj, name, sizeof name);
 
        printf("exporting %s to %s\n", upkg_export_name(pkg, idx), name);
        of = fopen(name, "wb");
        if (!of) {
                perror(name);
-               return -1;
+               goto out;
        }
 
        rc = u_object_export(obj, of);
 
        if (fclose(of) != 0) {
                perror(name);
-               return -1;
+               rc = -1;
+               goto out;
+       }
+
+       if (U_OBJECT_IS_LOADABLE(obj)) {
+               u_object_unload(obj);
        }
 
+out:
+       upkg_export_close(f);
        return rc;
 }