Beispiel #1
0
static gboolean
pk_alpm_pkg_is_local (PkBackendJob *job, alpm_pkg_t *pkg)
{
	PkBackend *backend = pk_backend_job_get_backend (job);
	PkBackendAlpmPrivate *priv = pk_backend_get_user_data (backend);
	alpm_pkg_t *local;

	g_return_val_if_fail (pkg != NULL, FALSE);

	/* find an installed package with the same name */
	local = alpm_db_get_pkg (priv->localdb, alpm_pkg_get_name (pkg));
	if (local == NULL)
		return FALSE;

	/* make sure the installed version is the same */
	if (alpm_pkg_vercmp (alpm_pkg_get_version (local),
			     alpm_pkg_get_version (pkg)) != 0) {
		return FALSE;
	}

	/* make sure the installed arch is the same */
	if (g_strcmp0 (alpm_pkg_get_arch (local),
		       alpm_pkg_get_arch (pkg)) != 0) {
		return FALSE;
	}

	return TRUE;
}
static gchar *
alpm_pkg_build_urls (pmpkg_t *pkg)
{
	GString *string = g_string_new ("");
#ifdef ALPM_PACKAGE_URL
	const gchar *name, *arch, *repo, *url;
#else
	const gchar *url;
#endif

	g_return_val_if_fail (pkg != NULL, NULL);

	/* grab the URL of the package... */
	url = alpm_pkg_get_url (pkg);
	if (url != NULL) {
		g_string_append_printf (string, "%s;Package website;", url);
	}

#ifdef ALPM_PACKAGE_URL
	/* ... and construct the distro URL if possible */
	name = alpm_pkg_get_name (pkg);
	arch = alpm_pkg_get_arch (pkg);
	repo = alpm_db_get_name (alpm_pkg_get_db (pkg));

	g_string_append_printf (string, ALPM_PACKAGE_URL ";Distribution page;",
				repo, arch, name);
#endif

	g_string_truncate (string, string->len - 1);
	return g_string_free (string, FALSE);
}
Beispiel #3
0
static PyObject* pyalpm_pkg_str(PyObject *rawself) {
  AlpmPackage *self = (AlpmPackage *)rawself;
  return PyUnicode_FromFormat("alpm.Package(\"%s-%s-%s\")",
			      alpm_pkg_get_name(self->c_data),
			      alpm_pkg_get_version(self->c_data),
			      alpm_pkg_get_arch(self->c_data));
}
static gboolean
asb_package_alpm_open (AsbPackage *pkg, const gchar *filename, GError **error)
{
	AsbPackageAlpm *pkg_alpm = ASB_PACKAGE_ALPM (pkg);
	AsbPackageAlpmPrivate *priv = GET_PRIVATE (pkg_alpm);

	alpm_errno_t alpm_error;

	/* initialize the alpm library */
	priv->handle = alpm_initialize ("/", "/tmp", &alpm_error);
	if (priv->handle == NULL) {
		g_set_error (error,
		             ASB_PLUGIN_ERROR,
		             ASB_PLUGIN_ERROR_FAILED,
		             "libalpm initialization failed %s (%u) for %s",
		             alpm_strerror (alpm_error),
		             alpm_error,
		             filename);
		return FALSE;
	}

	/* open the package */
	if (alpm_pkg_load (priv->handle, filename, TRUE, 0, &priv->package) == -1) {
		g_set_error (error,
		             ASB_PLUGIN_ERROR,
		             ASB_PLUGIN_ERROR_FAILED,
		             "Failed to load package %s : %s (%u)",
		             filename,
		             alpm_strerror (alpm_errno (priv->handle)),
		             alpm_errno (priv->handle));
		alpm_release (priv->handle);
		return FALSE;
	}

	asb_package_set_name (pkg, alpm_pkg_get_name (priv->package));
	asb_package_set_url (pkg, alpm_pkg_get_url (priv->package));
	asb_package_set_arch (pkg, alpm_pkg_get_arch (priv->package));
	asb_package_alpm_ensure_version (pkg, error);

	return TRUE;
}
Beispiel #5
0
static alpm_list_t *check_arch(alpm_handle_t *handle, alpm_list_t *pkgs)
{
	alpm_list_t *i;
	alpm_list_t *invalid = NULL;

	const char *arch = handle->arch;
	if(!arch) {
		return NULL;
	}
	for(i = pkgs; i; i = i->next) {
		alpm_pkg_t *pkg = i->data;
		const char *pkgarch = alpm_pkg_get_arch(pkg);
		if(pkgarch && strcmp(pkgarch, arch) && strcmp(pkgarch, "any")) {
			char *string;
			const char *pkgname = pkg->name;
			const char *pkgver = pkg->version;
			size_t len = strlen(pkgname) + strlen(pkgver) + strlen(pkgarch) + 3;
			MALLOC(string, len, RET_ERR(handle, ALPM_ERR_MEMORY, invalid));
			sprintf(string, "%s-%s-%s", pkgname, pkgver, pkgarch);
			invalid = alpm_list_add(invalid, string);
		}
	}
	return invalid;
}
gchar *
alpm_pkg_build_id (alpm_pkg_t *pkg)
{
	const gchar *name, *version, *arch, *repo;

	g_return_val_if_fail (pkg != NULL, NULL);

	name = alpm_pkg_get_name (pkg);
	version = alpm_pkg_get_version (pkg);

	arch = alpm_pkg_get_arch (pkg);
	if (arch == NULL) {
		arch = "any";
	}

	/* TODO: check correctness */
	if (alpm_pkg_get_origin (pkg) == ALPM_PKG_FROM_SYNCDB) {
		repo = alpm_db_get_name (alpm_pkg_get_db (pkg));
	} else {
		repo = "installed";
	}

	return pk_package_id_build (name, version, arch, repo);
}
Beispiel #7
0
static int print_pkg(alpm_pkg_t *pkg, const char *format) {
  const char *f, *end;
  char fmt[64], buf[64];
  int len, out = 0;

  end = format + strlen(format);

  for (f = format; f < end; f++) {
    len = 0;
    if (*f == '%') {
      len = strspn(f + 1 + len, printf_flags);
      len += strspn(f + 1 + len, digits);
      snprintf(fmt, len + 3, "%ss", f);
      fmt[len + 1] = 's';
      f += len + 1;
      switch (*f) {
        /* simple attributes */
        case 'f': /* filename */
          out += printf(fmt, alpm_pkg_get_filename(pkg));
          break;
        case 'n': /* package name */
          out += printf(fmt, alpm_pkg_get_name(pkg));
          break;
        case 'v': /* version */
          out += printf(fmt, alpm_pkg_get_version(pkg));
          break;
        case 'd': /* description */
          out += printf(fmt, alpm_pkg_get_desc(pkg));
          break;
        case 'u': /* project url */
          out += printf(fmt, alpm_pkg_get_url(pkg));
          break;
        case 'p': /* packager name */
          out += printf(fmt, alpm_pkg_get_packager(pkg));
          break;
        case 's': /* md5sum */
          out += printf(fmt, alpm_pkg_get_md5sum(pkg));
          break;
        case 'a': /* architecutre */
          out += printf(fmt, alpm_pkg_get_arch(pkg));
          break;
        case 'i': /* has install scriptlet? */
          out += printf(fmt, alpm_pkg_has_scriptlet(pkg) ? "yes" : "no");
          break;
        case 'r': /* repo */
          out += printf(fmt, alpm_db_get_name(alpm_pkg_get_db(pkg)));
          break;
        case 'w': /* install reason */
          out += printf(fmt, alpm_pkg_get_reason(pkg) ? "dependency" : "explicit");
          break;
        case '!': /* result number */
          snprintf(buf, sizeof(buf), "%d", opt_pkgcounter++);
          out += printf(fmt, buf);
          break;
        case 'g': /* base64 gpg sig */
          out += printf(fmt, alpm_pkg_get_base64_sig(pkg));
          break;
        case 'h': /* sha256sum */
          out += printf(fmt, alpm_pkg_get_sha256sum(pkg));
          break;

        /* times */
        case 'b': /* build date */
          out += print_time(alpm_pkg_get_builddate(pkg));
          break;
        case 'l': /* install date */
          out += print_time(alpm_pkg_get_installdate(pkg));
          break;

        /* sizes */
        case 'k': /* download size */
          out += printf(fmt, size_to_string(alpm_pkg_get_size(pkg)));
          break;
        case 'm': /* install size */
          out += printf(fmt, size_to_string(alpm_pkg_get_isize(pkg)));
          break;

        /* lists */
        case 'F': /* files */
          out += print_filelist(alpm_pkg_get_files(pkg));
          break;
        case 'N': /* requiredby */
          out += print_list(alpm_pkg_compute_requiredby(pkg), NULL);
          break;
        case 'L': /* licenses */
          out += print_list(alpm_pkg_get_licenses(pkg), NULL);
          break;
        case 'G': /* groups */
          out += print_list(alpm_pkg_get_groups(pkg), NULL);
          break;
        case 'E': /* depends (shortdeps) */
          out += print_list(alpm_pkg_get_depends(pkg), (extractfn)alpm_dep_get_name);
          break;
        case 'D': /* depends */
          out += print_list(alpm_pkg_get_depends(pkg), (extractfn)alpm_dep_compute_string);
          break;
        case 'O': /* optdepends */
          out += print_list(alpm_pkg_get_optdepends(pkg), (extractfn)format_optdep);
          break;
        case 'o': /* optdepends (shortdeps) */
          out += print_list(alpm_pkg_get_optdepends(pkg), (extractfn)alpm_dep_get_name);
          break;
        case 'C': /* conflicts */
          out += print_list(alpm_pkg_get_conflicts(pkg), (extractfn)alpm_dep_get_name);
          break;
        case 'S': /* provides (shortdeps) */
          out += print_list(alpm_pkg_get_provides(pkg), (extractfn)alpm_dep_get_name);
          break;
        case 'P': /* provides */
          out += print_list(alpm_pkg_get_provides(pkg), (extractfn)alpm_dep_compute_string);
          break;
        case 'R': /* replaces */
          out += print_list(alpm_pkg_get_replaces(pkg), (extractfn)alpm_dep_get_name);
          break;
        case 'B': /* backup */
          out += print_list(alpm_pkg_get_backup(pkg), alpm_backup_get_name);
          break;
        case 'V': /* package validation */
          out += print_allocated_list(get_validation_method(pkg), NULL);
          break;
        case 'M': /* modified */
          out += print_allocated_list(get_modified_files(pkg), NULL);
          break;
        case '%':
          fputc('%', stdout);
          out++;
          break;
        default:
          fputc('?', stdout);
          out++;
          break;
      }
    } else if (*f == '\\') {
      char esc[3] = { f[0], f[1], '\0' };
      out += print_escaped(esc);
      ++f;
    } else {
      fputc(*f, stdout);
      out++;
    }
  }

  /* only print a delimeter if any package data was outputted */
  if (out > 0) {
    print_escaped(opt_delim);
  }

  return !out;
}
Beispiel #8
0
void pacman_pkgdump(pmpkg_t *pkg, enum pkgfrom_t from)
{
	static const char *datefmt = "%a %d %b %Y %I:%M:%S %p %Z";

	alpm_list_t *i, *results = NULL;
	pmdb_t *db;
	pmdepend_t *dep;
	pmpkgreason_t reason;

	int has_script;
	time_t inst_time;
	struct tm tm_st;

	char installdate[60];
	char builddate[60];

	db = alpm_pkg_get_db(pkg);
	if (!db) {
		return;
	}

	memset(&tm_st, 0, sizeof(struct tm));
	inst_time = alpm_pkg_get_builddate(pkg);
	localtime_r(&inst_time, &tm_st);
	strftime(builddate, 60, datefmt, &tm_st);

	/* Local pkg specific */
	if (from == PKG_FROM_LOCAL) {
		has_script = alpm_pkg_has_scriptlet(pkg);
		reason = alpm_pkg_get_reason(pkg);

		memset(&tm_st, 0, sizeof(struct tm));
		inst_time = alpm_pkg_get_installdate(pkg);
		localtime_r(&inst_time, &tm_st);
		strftime(installdate, 60, datefmt, &tm_st);
	}

	if (from == PKG_FROM_SYNC) {
		printf("%s%s ", color.bold, REPO);
		const char *repo = alpm_db_get_name(db);
		if (!strcmp(repo, "core")) {
			printf("%s", color.bred);
		} else if (!strcmp(repo, "extra")) {
			printf("%s", color.bgreen);
		} else {
			printf("%s", color.bmag);
		}

		printf("%s%s\n", repo, color.nocolor);
	}

	printf("%s%s%s %s%s%s\n", color.bold, NAME, color.nocolor,
		   color.bold, alpm_pkg_get_name(pkg), color.nocolor);
	printf("%s%s %s%s%s\n", color.bold, VERSION, color.bgreen,
		   alpm_pkg_get_version(pkg), color.nocolor);
	printf("%s%s %s%s%s\n", color.bold, URL, color.bcyan,
		   alpm_pkg_get_url(pkg), color.nocolor);

	print_list_prefix(alpm_pkg_get_licenses(pkg), LICENSES);
	print_list_prefix(alpm_pkg_get_groups(pkg), GROUPS);
	print_list_prefix(alpm_pkg_get_provides(pkg), PROVIDES);

	print_list_deps(alpm_pkg_get_depends(pkg), DEPS);
	print_list_break(alpm_pkg_get_optdepends(pkg), OPTDEPS);

	if (from == PKG_FROM_LOCAL) {
		results = alpm_pkg_compute_requiredby(pkg);
		print_list_prefix(results, REQBY);
	}

	print_list_prefix(alpm_pkg_get_conflicts(pkg), CONFLICTS);
	print_list_prefix(alpm_pkg_get_replaces(pkg), REPLACES);

	if (from == PKG_FROM_SYNC) {
		humanize_size(alpm_pkg_get_size(pkg), DLSZ);
	}

	humanize_size(alpm_pkg_get_isize(pkg), INSTSZ);
	printf("%s%s%s %s\n", color.bold, PKGER, color.nocolor,
		   alpm_pkg_get_packager(pkg));
	printf("%s%s%s %s\n", color.bold, ARCH, color.nocolor, alpm_pkg_get_arch(pkg));
	printf("%s%s%s %s\n", color.bold, BDATE, color.nocolor, builddate);

	if (from == PKG_FROM_LOCAL) {
		printf("%s%s%s %s\n", color.bold, IDATE, color.nocolor, installdate);

		printf("%s%s%s ", color.bold, REASON, color.nocolor);
		switch (reason) {
		case PM_PKG_REASON_EXPLICIT:
			printf("Explicitly installed");
			break;
		case PM_PKG_REASON_DEPEND:
			printf("Installed as a dependency for another package");
			break;
		default:
			printf("Unknown");
			break;
		}

		printf("\n");
		printf("%s%s%s %s\n", color.bold, SCRIPT, color.nocolor,
			   has_script ? "Yes" : "No");
	}

	if (from == PKG_FROM_SYNC) {
		printf("%s%s%s %s\n", color.bold, MD5SUM, color.nocolor,
			   alpm_pkg_get_md5sum(pkg));
	}

	printf("%s%s%s %s\n", color.bold, DESC, color.nocolor, alpm_pkg_get_desc(pkg));
	FREELIST(results);
}
Beispiel #9
0
/**
 * Display the details of a package.
 * Extra information entails 'required by' info for sync packages and backup
 * files info for local packages.
 * @param pkg package to display information for
 * @param from the type of package we are dealing with
 * @param extra should we show extra information
 */
void dump_pkg_full(alpm_pkg_t *pkg, int extra)
{
    unsigned short cols;
    time_t bdate, idate;
    alpm_pkgfrom_t from;
    double size;
    char bdatestr[50] = "", idatestr[50] = "";
    const char *label, *reason;
    alpm_list_t *validation = NULL, *requiredby = NULL, *optionalfor = NULL;

    from = alpm_pkg_get_origin(pkg);

    /* set variables here, do all output below */
    bdate = (time_t)alpm_pkg_get_builddate(pkg);
    if(bdate) {
        strftime(bdatestr, 50, "%c", localtime(&bdate));
    }
    idate = (time_t)alpm_pkg_get_installdate(pkg);
    if(idate) {
        strftime(idatestr, 50, "%c", localtime(&idate));
    }

    switch(alpm_pkg_get_reason(pkg)) {
    case ALPM_PKG_REASON_EXPLICIT:
        reason = _("Explicitly installed");
        break;
    case ALPM_PKG_REASON_DEPEND:
        reason = _("Installed as a dependency for another package");
        break;
    default:
        reason = _("Unknown");
        break;
    }

    alpm_pkgvalidation_t v = alpm_pkg_get_validation(pkg);
    if(v) {
        if(v & ALPM_PKG_VALIDATION_NONE) {
            validation = alpm_list_add(validation, _("None"));
        } else {
            if(v & ALPM_PKG_VALIDATION_MD5SUM) {
                validation = alpm_list_add(validation, _("MD5 Sum"));
            }
            if(v & ALPM_PKG_VALIDATION_SHA256SUM) {
                validation = alpm_list_add(validation, _("SHA256 Sum"));
            }
            if(v & ALPM_PKG_VALIDATION_SIGNATURE) {
                validation = alpm_list_add(validation, _("Signature"));
            }
        }
    } else {
        validation = alpm_list_add(validation, _("Unknown"));
    }

    if(extra || from == ALPM_PKG_FROM_LOCALDB) {
        /* compute this here so we don't get a pause in the middle of output */
        requiredby = alpm_pkg_compute_requiredby(pkg);
        optionalfor = alpm_pkg_compute_optionalfor(pkg);
    }

    cols = getcols(fileno(stdout));

    /* actual output */
    if(from == ALPM_PKG_FROM_SYNCDB) {
        string_display(_("Repository     :"),
                       alpm_db_get_name(alpm_pkg_get_db(pkg)), cols);
    }
    string_display(_("Name           :"), alpm_pkg_get_name(pkg), cols);
    string_display(_("Version        :"), alpm_pkg_get_version(pkg), cols);
    string_display(_("Description    :"), alpm_pkg_get_desc(pkg), cols);
    string_display(_("Architecture   :"), alpm_pkg_get_arch(pkg), cols);
    string_display(_("URL            :"), alpm_pkg_get_url(pkg), cols);
    list_display(_("Licenses       :"), alpm_pkg_get_licenses(pkg), cols);
    list_display(_("Groups         :"), alpm_pkg_get_groups(pkg), cols);
    deplist_display(_("Provides       :"), alpm_pkg_get_provides(pkg), cols);
    deplist_display(_("Depends On     :"), alpm_pkg_get_depends(pkg), cols);
    optdeplist_display(pkg, cols);

    if(extra || from == ALPM_PKG_FROM_LOCALDB) {
        list_display(_("Required By    :"), requiredby, cols);
        list_display(_("Optional For   :"), optionalfor, cols);
    }
    deplist_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg), cols);
    deplist_display(_("Replaces       :"), alpm_pkg_get_replaces(pkg), cols);

    size = humanize_size(alpm_pkg_get_size(pkg), '\0', 2, &label);
    if(from == ALPM_PKG_FROM_SYNCDB) {
        printf("%s%s%s %6.2f %s\n", config->colstr.title, _("Download Size  :"),
               config->colstr.nocolor, size, label);
    } else if(from == ALPM_PKG_FROM_FILE) {
        printf("%s%s%s %6.2f %s\n", config->colstr.title, _("Compressed Size:"),
               config->colstr.nocolor, size, label);
    } else {
        // autodetect size for "Installed Size"
        label = "\0";
    }

    size = humanize_size(alpm_pkg_get_isize(pkg), label[0], 2, &label);
    printf("%s%s%s %6.2f %s\n", config->colstr.title, _("Installed Size :"),
           config->colstr.nocolor, size, label);

    string_display(_("Packager       :"), alpm_pkg_get_packager(pkg), cols);
    string_display(_("Build Date     :"), bdatestr, cols);
    if(from == ALPM_PKG_FROM_LOCALDB) {
        string_display(_("Install Date   :"), idatestr, cols);
        string_display(_("Install Reason :"), reason, cols);
    }
    if(from == ALPM_PKG_FROM_FILE || from == ALPM_PKG_FROM_LOCALDB) {
        string_display(_("Install Script :"),
                       alpm_pkg_has_scriptlet(pkg) ?  _("Yes") : _("No"), cols);
    }

    if(from == ALPM_PKG_FROM_SYNCDB && extra) {
        const char *base64_sig = alpm_pkg_get_base64_sig(pkg);
        alpm_list_t *keys = NULL;
        if(base64_sig) {
            unsigned char *decoded_sigdata = NULL;
            size_t data_len;
            alpm_decode_signature(base64_sig, &decoded_sigdata, &data_len);
            alpm_extract_keyid(config->handle, alpm_pkg_get_name(pkg),
                               decoded_sigdata, data_len, &keys);
        } else {
            keys = alpm_list_add(keys, _("None"));
        }

        string_display(_("MD5 Sum        :"), alpm_pkg_get_md5sum(pkg), cols);
        string_display(_("SHA256 Sum     :"), alpm_pkg_get_sha256sum(pkg), cols);
        list_display(_("Signatures     :"), keys, cols);
    } else {
        list_display(_("Validated By   :"), validation, cols);
    }

    if(from == ALPM_PKG_FROM_FILE) {
        alpm_siglist_t siglist;
        int err = alpm_pkg_check_pgp_signature(pkg, &siglist);
        if(err && alpm_errno(config->handle) == ALPM_ERR_SIG_MISSING) {
            string_display(_("Signatures     :"), _("None"), cols);
        } else if(err) {
            string_display(_("Signatures     :"),
                           alpm_strerror(alpm_errno(config->handle)), cols);
        } else {
            signature_display(_("Signatures     :"), &siglist, cols);
        }
        alpm_siglist_cleanup(&siglist);
    }

    /* Print additional package info if info flag passed more than once */
    if(from == ALPM_PKG_FROM_LOCALDB && extra) {
        dump_pkg_backups(pkg);
    }

    /* final newline to separate packages */
    printf("\n");

    FREELIST(requiredby);
    alpm_list_free(validation);
}
Beispiel #10
0
			}
		}
	}

	if (string == NULL)
		return NULL;
	return g_string_free (string, FALSE);
}

static gchar **
pk_alpm_pkg_build_urls (alpm_pkg_t *pkg)
{
	gchar **urls = g_new0 (gchar *, 2);
	urls[0] = g_strdup_printf ("http://www.archlinux.org/packages/%s/%s/%s/",
				   alpm_db_get_name (alpm_pkg_get_db (pkg)),
				   alpm_pkg_get_arch (pkg),
				   alpm_pkg_get_name (pkg));
	return urls;
}

static gboolean
pk_alpm_pkg_same_pkgver (alpm_pkg_t *a, alpm_pkg_t *b)
{
	const gchar *version_a, *version_b, *last_a, *last_b;
	gsize length_a, length_b;

	g_return_val_if_fail (a != NULL, (b == NULL));
	g_return_val_if_fail (b != NULL, FALSE);

	version_a = alpm_pkg_get_version (a);
	version_b = alpm_pkg_get_version (b);