Exemple #1
0
static inline int
install_packages(list_t *list, const char *dir, int verbose) {
  if (!list || !dir) return 0;

  list_node_t *node;
  list_iterator_t *it = list_iterator_new(list, LIST_HEAD);
  while ((node = list_iterator_next(it))) {
    clib_package_dependency_t *dep = node->val;
    char *slug = clib_package_slug(dep->author, dep->name, dep->version);
    clib_package_t *pkg = clib_package_new_from_slug(slug, verbose);

    free(slug);

    if (NULL == pkg) {
      return -1;
    }

    int rc = clib_package_install(pkg, dir, verbose);
    clib_package_free(pkg);
    if (-1 == rc) {
      list_iterator_destroy(it);
      return -1;
    }
  }

  list_iterator_destroy(it);
  return 0;
}
Exemple #2
0
static inline int
install_packages(list_t *list, const char *dir, int verbose) {
  list_node_t *node = NULL;
  list_iterator_t *iterator = NULL;
  int rc = -1;

  if (!list || !dir) goto cleanup;

  iterator = list_iterator_new(list, LIST_HEAD);
  if (NULL == iterator) goto cleanup;

  while ((node = list_iterator_next(iterator))) {
    clib_package_dependency_t *dep = NULL;
    char *slug = NULL;
    clib_package_t *pkg = NULL;
    int error = 1;

    dep = (clib_package_dependency_t *) node->val;
    slug = clib_package_slug(dep->author, dep->name, dep->version);
    if (NULL == slug) goto loop_cleanup;

    pkg = clib_package_new_from_slug(slug, verbose);
    if (NULL == pkg) goto loop_cleanup;

    if (-1 == clib_package_install(pkg, dir, verbose)) goto loop_cleanup;

    error = 0;

  loop_cleanup:
    if (slug) free(slug);
    if (pkg) clib_package_free(pkg);
    if (error) {
      list_iterator_destroy(iterator);
      iterator = NULL;
      rc = -1;
      goto cleanup;
    }
  }

  rc = 0;

cleanup:
  if (iterator) list_iterator_destroy(iterator);
  return rc;
}
Exemple #3
0
static int
install_package(const char *slug) {
  int rc;

  clib_package_t *pkg = clib_package_new_from_slug(slug, opts.verbose);
  if (NULL == pkg) return -1;

  if (pkg->install) {
    rc = executable(pkg);
    goto done;
  }

  rc = clib_package_install(pkg, opts.dir, opts.verbose);
  if (0 == rc && opts.dev) {
    rc = clib_package_install_development(pkg, opts.dir, opts.verbose);
  }

done:
  clib_package_free(pkg);
  return rc;
}
#include "describe/describe.h"
#include "rimraf/rimraf.h"
#include "fs/fs.h"
#include "clib-package.h"


describe("clib_package_install", {
  it("should return -1 when given a bad package", {
    assert(-1 == clib_package_install(NULL, "./deps", 0));
  });

  it("should install the pkg in its own directory", {
    clib_package_t *pkg = clib_package_new_from_slug("stephenmathieson/[email protected]", 0);
    assert(pkg);
    assert(0 == clib_package_install(pkg, "./test/fixtures/", 0));
    assert(0 == fs_exists("./test/fixtures/"));
    assert(0 == fs_exists("./test/fixtures/case"));
    clib_package_free(pkg);
    rimraf("./test/fixtures/");
  });

  it("should install the package's package.json", {
    clib_package_t *pkg = clib_package_new_from_slug("stephenmathieson/[email protected]", 0);
    assert(pkg);
    assert(0 == clib_package_install(pkg, "./test/fixtures/", 0));
    assert(0 == fs_exists("./test/fixtures/case/package.json"));
    clib_package_free(pkg);
    rimraf("./test/fixtures/");
  });