Fix bugs causing arguments to not be passed to lua scripts 0.5.1
authorJ. Ali Harlow <ali@juiblex.co.uk>
Fri, 27 Jan 2012 08:12:19 +0000 (08:12 +0000)
committerJ. Ali Harlow <ali@juiblex.co.uk>
Fri, 27 Jan 2012 08:12:19 +0000 (08:12 +0000)
librazor/razor.c
librazor/root.c
librazor/util.c
src/test-driver.c

index 228fbf9..3056338 100644 (file)
@@ -237,6 +237,7 @@ razor_set_open(const char *filename, struct razor_atomic *atomic)
        }
 
        set->lock_fd = -1;
+       set->ref_count = 1;
        if (razor_set_bind_sections(set, atomic, filename)) {
                free(set);
                return NULL;
index edac683..81568b4 100644 (file)
@@ -87,7 +87,7 @@ razor_root_create(const char *root)
        struct stat buf;
        struct razor_set *set;
        struct razor_atomic *atomic;
-       char *path;
+       char *file, *path;
 
        assert (root != NULL);
 
@@ -109,22 +109,23 @@ razor_root_create(const char *root)
                return -1;
        }
 
-       path = razor_concat(root, razor_root_path, "/", system_repo_filename,
-                           NULL);
+       file = razor_concat(razor_root_path, "/", system_repo_filename, NULL);
+       path = razor_concat(root, file, NULL);
        retval = !stat(path, &buf);
-       free(path);
        if (retval) {
                fprintf(stderr,
                        "a razor install root is already initialized\n");
+               free(path);
+               free(file);
                return retval;
        }
 
        atomic = razor_atomic_open("Create initial package set");
-       path = razor_concat(razor_root_path, "/", system_repo_filename, NULL);
-       razor_atomic_make_dirs(atomic, root, path);
+       razor_atomic_make_dirs(atomic, root, file);
        set = razor_set_create();
        razor_set_write(set, atomic, path, RAZOR_SECTION_ALL);
        free(path);
+       free(file);
        retval = razor_atomic_commit(atomic);
        if (retval)
                fprintf(stderr, "could not write initial package set\n");
index 584c260..dba6b7a 100644 (file)
@@ -120,9 +120,11 @@ qsort_swap(void *p1, void *p2, size_t size)
 {
        char buffer[size];
 
-       memcpy(buffer, p1, size);
-       memcpy(p1, p2, size);
-       memcpy(p2, buffer, size);
+       if (p1 != p2) {
+               memcpy(buffer, p1, size);
+               memcpy(p1, p2, size);
+               memcpy(p2, buffer, size);
+       }
 }
 
 static void
@@ -226,7 +228,7 @@ void environment_add_variable(struct environment *env,
 void environment_set(struct environment *env)
 {
        int i, count;
-       char *s;
+       char *s, *t;
         uint32_t *r;
 
        if (!env->is_set) {
@@ -234,7 +236,14 @@ void environment_set(struct environment *env)
                r = (uint32_t *)env->vars.data;
                for (i = 0; i < count; i++) {
                        s = env->string_pool.data + *r++;
+#ifdef WIN32
                        putenv(s);
+#else
+                       t = strchr(s, '=');
+                       *t = '\0';
+                       setenv(s, t + 1, 1);
+                       *t = '=';
+#endif
                }
 
                env->is_set = 1;
@@ -252,11 +261,19 @@ void environment_unset(struct environment *env)
                r = (uint32_t *)env->vars.data;
                for (i = 0; i < count; i++) {
                        s = env->string_pool.data + *r++;
-                       t = strchr(s, '=') + 1;
+                       t = strchr(s, '=');
+#ifdef WIN32
+                       t++;
                        c = *t;
                        *t = '\0';
                        putenv(s);
                        *t = c;
+#else
+                       c = *t;
+                       *t = '\0';
+                       unsetenv(s);
+                       *t = c;
+#endif
                }
 
                env->is_set = 0;
index 160a3ad..d64c06e 100644 (file)
@@ -141,15 +141,15 @@ static void
 end_test(struct test_context *ctx)
 {
        if (ctx->system_set) {
-               razor_set_destroy(ctx->system_set);
+               razor_set_unref(ctx->system_set);
                ctx->system_set = NULL;
        }
        if (ctx->repo_set) {
-               razor_set_destroy(ctx->repo_set);
+               razor_set_unref(ctx->repo_set);
                ctx->repo_set = NULL;
        }
        if (ctx->result_set) {
-               razor_set_destroy(ctx->result_set);
+               razor_set_unref(ctx->result_set);
                ctx->result_set = NULL;
        }
        if (ctx->trans) {