SOURCES: PackageKit-poldek.patch (NEW) - poldek backend
megabajt
megabajt at pld-linux.org
Fri Feb 29 14:47:21 CET 2008
Author: megabajt Date: Fri Feb 29 13:47:21 2008 GMT
Module: SOURCES Tag: HEAD
---- Log message:
- poldek backend
---- Files affected:
SOURCES:
PackageKit-poldek.patch (NONE -> 1.1) (NEW)
---- Diffs:
================================================================
Index: SOURCES/PackageKit-poldek.patch
diff -u /dev/null SOURCES/PackageKit-poldek.patch:1.1
--- /dev/null Fri Feb 29 14:47:21 2008
+++ SOURCES/PackageKit-poldek.patch Fri Feb 29 14:47:16 2008
@@ -0,0 +1,1933 @@
+diff -urN PackageKit-0.1.8/backends/Makefile.am PackageKit-0.1.8.new/backends/Makefile.am
+--- PackageKit-0.1.8/backends/Makefile.am 2008-02-17 23:47:49.000000000 +0100
++++ PackageKit-0.1.8.new/backends/Makefile.am 2008-02-29 14:33:49.000000000 +0100
+@@ -44,6 +44,10 @@
+ SUBDIRS += pisi
+ endif
+
++if BACKEND_TYPE_POLDEK
++SUBDIRS += poldek
++endif
++
+ if BACKEND_TYPE_ZYPP
+ SUBDIRS += zypp
+ endif
+diff -urN PackageKit-0.1.8/backends/poldek/Makefile.am PackageKit-0.1.8.new/backends/poldek/Makefile.am
+--- PackageKit-0.1.8/backends/poldek/Makefile.am 1970-01-01 01:00:00.000000000 +0100
++++ PackageKit-0.1.8.new/backends/poldek/Makefile.am 2008-02-29 14:33:49.000000000 +0100
+@@ -0,0 +1,6 @@
++plugindir = $(PK_PLUGIN_DIR)
++plugin_LTLIBRARIES = libpk_backend_poldek.la
++libpk_backend_poldek_la_SOURCES = pk-backend-poldek.c
++libpk_backend_poldek_la_LIBADD = $(PK_PLUGIN_LIBS) $(POLDEK_LIBS)
++libpk_backend_poldek_la_LDFLAGS = -module -avoid-version
++libpk_backend_poldek_la_CFLAGS = $(PK_PLUGIN_CFLAGS) $(POLDEK_CFLAGS)
+\ Brak znaku nowej linii na końcu pliku
+diff -urN PackageKit-0.1.8/backends/poldek/pk-backend-poldek.c PackageKit-0.1.8.new/backends/poldek/pk-backend-poldek.c
+--- PackageKit-0.1.8/backends/poldek/pk-backend-poldek.c 1970-01-01 01:00:00.000000000 +0100
++++ PackageKit-0.1.8.new/backends/poldek/pk-backend-poldek.c 2008-02-29 14:24:32.000000000 +0100
+@@ -0,0 +1,1846 @@
++/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
++ *
++ * Copyright (C) 2008 Marcin Banasiak <megabajt at pld-linux.org>
++ *
++ * Licensed under the GNU General Public License Version 2
++ *
++ * This program is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 2 of the License, or
++ * (at your option) any later version.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, write to the Free Software
++ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
++ */
++
++#include <pk-backend.h>
++#include <pk-backend-thread.h>
++#include <pk-network.h>
++
++#include <log.h>
++#include <capreq.h>
++#include <poldek.h>
++#include <poclidek/poclidek.h>
++#include <pkgdir/pkgdir.h>
++#include <pkgdir/source.h>
++#include <pkgu.h>
++#include <pkgfl.h>
++#include <pkgmisc.h>
++#include <pm/pm.h>
++#include <vfile/vfile.h>
++
++static gchar* poldek_pkg_evr (const struct pkg *pkg);
++static void poldek_backend_package (const struct pkg *pkg, gint status);
++static long do_get_bytes_to_download (const struct poldek_ts *ts, const gchar *mark);
++
++enum {
++ PROGRESS_ENUM_INSTALL,
++ PROGRESS_ENUM_REFRESH_CACHE
++};
++
++enum {
++ SEARCH_ENUM_NAME,
++ SEARCH_ENUM_GROUP,
++ SEARCH_ENUM_DETAILS,
++ SEARCH_ENUM_FILE
++};
++
++typedef struct {
++ gboolean installed;
++ gboolean notinstalled;
++ gboolean devel;
++ gboolean notdevel;
++ gboolean gui;
++ gboolean notgui;
++} FilterData;
++
++typedef struct {
++ gint mode;
++ FilterData *fd;
++ gchar *search;
++} SearchData;
++
++/* used by get_depends and get_requires */
++typedef struct {
++ gchar *package_id;
++ gboolean recursive;
++} DepsData;
++
++typedef struct {
++ gchar *package_id;
++ gboolean allow_deps;
++} RemoveData;
++
++typedef struct {
++ gint mode;
++ gint step; // current step
++
++ /* Numer of sources to update. It's used only by refresh cache,
++ * as each source can have multiple files to download. I don't
++ * know how to get numer of files which will be downloaded. */
++ gint nsources;
++
++ long bytesget;
++ long bytesdownload;
++
++ gint percentage;
++ gint subpercentage;
++} PercentageData;
++
++/* used by install / update */
++typedef struct {
++ PercentageData *pd;
++ gchar *package_id;
++} InstallData;
++
++typedef struct {
++ InstallData *idata;
++ RemoveData *rdata;
++} TsConfirmData;
++
++/* global variables */
++static PkBackendThread *thread;
++static PkNetwork *network;
++
++static gint verbose = 1;
++static gint ref = 0;
++
++static struct poldek_ctx *ctx = NULL;
++static struct poclidek_ctx *cctx = NULL;
++
++/**
++ * poldek_get_bytes_to_download:
++ *
++ * Returns: bytes to download
++ */
++static long
++poldek_get_bytes_to_download (const struct poldek_ts *ts)
++{
++ long bytes = 0;
++
++ bytes += do_get_bytes_to_download (ts, "I");
++ bytes += do_get_bytes_to_download (ts, "D");
++
++ return bytes;
++}
++
++static long
++do_get_bytes_to_download (const struct poldek_ts *ts, const gchar *mark)
++{
++ tn_array *pkgs = NULL;
++ gint i;
++ long bytes = 0;
++
++ pkgs = poldek_ts_get_summary (ts, mark);
++
++ if (pkgs) {
++ for (i = 0; i < n_array_size (pkgs); i++) {
++ struct pkg *pkg = n_array_nth (pkgs, i);
++ gchar path[1024];
++
++ if (pkg->pkgdir && (vf_url_type (pkg->pkgdir->path) & VFURL_REMOTE)) {
++ if (pkg_localpath (pkg, path, sizeof(path), ts->cachedir)) {
++ if (access(path, R_OK) != 0) {
++ bytes += pkg->fsize;
++ } else {
++ if (!pm_verify_signature(ts->pmctx, path, PKGVERIFY_MD)) {
++ bytes += pkg->fsize;
++ }
++ }
++ }
++ }
++ }
++ n_array_free (pkgs);
++ }
++
++ return bytes;
++}
++
++
++
++/**
++ * FIXME: better refresh_cache progress
++ * VF_PROGRESS
++ */
++static void*
++poldek_vf_progress_new (void *data, const gchar *label)
++{
++ PercentageData *bar = (PercentageData*) data;
++ if (bar->mode == PROGRESS_ENUM_INSTALL) {
++ gchar *filename = g_path_get_basename (label), *pkgname, *command;
++ struct poclidek_rcmd *rcmd;
++ tn_array *pkgs = NULL;
++ struct pkg *pkg = NULL;
++
++ pkgname = g_strndup (filename, (sizeof(gchar)*strlen(filename)-4));
++
++ command = g_strdup_printf ("cd /all-avail; ls -q %s", pkgname);
++
++ rcmd = poclidek_rcmd_new (cctx, NULL);
++ poclidek_rcmd_execline (rcmd, command);
++ pkgs = poclidek_rcmd_get_packages (rcmd);
++
++ if (pkgs) {
++ pkg = n_array_nth (pkgs, 0);
++
++ poldek_backend_package (pkg, PK_INFO_ENUM_DOWNLOADING);
++ }
++
++ poclidek_rcmd_free (rcmd);
++
++ g_free (pkgname);
++ g_free (filename);
++ }
++ return bar;
++}
++
++static void
++poldek_vf_progress (void *bar, long total, long amount)
++{
++ PercentageData *pd = (PercentageData*) bar;
++ gint tmp_subpercentage;
++ PkBackend *backend;
++
++ backend = pk_backend_thread_get_backend (thread);
++
++ tmp_subpercentage = (gint)(((float)amount / (float)total) * 100);
++
++ if (pd->mode == PROGRESS_ENUM_REFRESH_CACHE) {
++ if (tmp_subpercentage >= pd->subpercentage) {
++ if (pd->step - 1 == 0)
++ pd->percentage = 1;
++ else
++ pd->percentage = (gint)(((pd->step - 1) / pd->nsources) * 100);
++
++ pd->subpercentage = tmp_subpercentage;
++ } else {
++ if (pd->step == pd->nsources) {
++ pd->percentage = 100;
++ } else {
++ pd->percentage = (gint)(((float)pd->step / (float)pd->nsources) * 100);
++ }
++
++ pd->subpercentage = 100;
++ }
++ } else {
++ if (tmp_subpercentage >= pd->subpercentage) {
++ pd->percentage = (gint)(((float)(pd->bytesget + amount) / (float)pd->bytesdownload) * 100);
++ pd->subpercentage = tmp_subpercentage;
++ } else {
++ pd->bytesget += total;
++ pd->subpercentage = 100;
++ }
++ }
++ pk_backend_set_percentage (backend, pd->percentage);
++ pk_backend_set_sub_percentage (backend, pd->subpercentage);
++}
++
++static void
++poldek_vf_progress_reset (void *bar)
++{
++ PercentageData *pd = (PercentageData*) bar;
++
++ pd->subpercentage = 0;
++}
++
++/**
++ * ts_confirm:
++ * Returns Yes - 1
++ * No - 0
++ */
++static int
++ts_confirm (void *data, struct poldek_ts *ts)
++{
++ tn_array *ipkgs = NULL, *dpkgs = NULL, *rpkgs = NULL, *upkgs = NULL;
++ TsConfirmData *tsd = (TsConfirmData *)data;
++ gint i = 0, j = 0, result = 1;
++
++ ipkgs = poldek_ts_get_summary (ts, "I");
++ dpkgs = poldek_ts_get_summary (ts, "D");
++ rpkgs = poldek_ts_get_summary (ts, "R");
++
++ switch (poldek_ts_get_type (ts)) {
++ case POLDEK_TS_TYPE_INSTALL:
++ upkgs = n_array_new (2, NULL, NULL);
++
++ tsd->idata->pd->step = 0;
++ tsd->idata->pd->bytesdownload = poldek_get_bytes_to_download (ts);
++
++ if (rpkgs) {
++ for (i = 0; i < n_array_size (ipkgs); i++) {
++ struct pkg *ipkg = n_array_nth (ipkgs, i);
++
++ for (j = 0; j < n_array_size (rpkgs); j++) {
++ struct pkg *rpkg = n_array_nth (rpkgs, j);
++
++ if (pkg_cmp_name (ipkg, rpkg) == 0) {
++ n_array_push (upkgs, pkg_link (rpkg));
++ break;
++ }
++ }
++
++ }
++
++ if (dpkgs) {
++ for (i = 0; i < n_array_size (dpkgs); i++) {
++ struct pkg *dpkg = n_array_nth (dpkgs, i);
++
++ for (j = 0; j < n_array_size (rpkgs); j++) {
++ struct pkg *rpkg = n_array_nth (rpkgs, j);
++
++ if (pkg_cmp_name (dpkg, rpkg) == 0) {
++ n_array_push (upkgs, pkg_link (rpkg));
++ break;
++ }
++ }
++ }
++ }
++ }
++
++ if (rpkgs) {
++ for (i = 0; i < n_array_size (rpkgs); i++) {
++ struct pkg *rpkg = n_array_nth (rpkgs, i);
++ gboolean canprint = TRUE;
++
++ for (j = 0; j < n_array_size (upkgs); j++) {
++ struct pkg *upkg = n_array_nth (upkgs, j);
++
++ if (pkg_cmp_name (upkg, rpkg) == 0) {
++ canprint = FALSE;
++ break;
++ }
++ }
++ if (canprint)
++ poldek_backend_package (rpkg, PK_INFO_ENUM_REMOVING);
++ }
++ }
++
++ if (dpkgs) {
++ for (i = 0; i < n_array_size (dpkgs); i++) {
++ struct pkg *dpkg = n_array_nth (dpkgs, i);
++ gboolean canprint = TRUE;
++
++ for (j = 0; j < n_array_size (upkgs); j++) {
++ struct pkg *upkg = n_array_nth (upkgs, j);
++
++ if (pkg_cmp_name (upkg, dpkg) == 0) {
++ canprint = FALSE;
++ break;
++ }
++ }
++ if (canprint)
++ poldek_backend_package (dpkg, PK_INFO_ENUM_INSTALLING);
++ }
++ }
++
++ if (ipkgs) {
++ for (i = 0; i < n_array_size (ipkgs); i++) {
++ struct pkg *ipkg = n_array_nth (ipkgs, i);
++ gboolean canprint = TRUE;
++
++ for (j = 0; j < n_array_size (upkgs); j++) {
++ struct pkg *upkg = n_array_nth (upkgs, j);
++
++ if (pkg_cmp_name (upkg, ipkg) == 0) {
++ canprint = FALSE;
++ break;
++ }
++ }
++ if (canprint)
++ poldek_backend_package (ipkg, PK_INFO_ENUM_INSTALLING);
++ }
++ }
++
++ for (i = 0; i < n_array_size (upkgs); i++) {
++ struct pkg *upkg = n_array_nth (upkgs, i);
++
++ poldek_backend_package (upkg, PK_INFO_ENUM_UPDATING);
++ }
++
++ n_array_free (upkgs);
++
++ break;
++ case POLDEK_TS_TYPE_UNINSTALL:
++ if (dpkgs) {
++ if ((tsd->rdata->allow_deps == FALSE) && (n_array_size (dpkgs) > 0)) {
++ result = 0;
++ break;
++ }
++
++ for (i = 0; i < n_array_size (dpkgs); i++) {
++ struct pkg *pkg = n_array_nth (dpkgs, i);
++
++ poldek_backend_package (pkg, PK_INFO_ENUM_REMOVING);
++ }
++ }
++
++ if (rpkgs) {
++ for (i = 0; i < n_array_size (rpkgs); i++) {
++ struct pkg *pkg = n_array_nth (rpkgs, i);
++
++ poldek_backend_package (pkg, PK_INFO_ENUM_REMOVING);
++ }
++ }
++
++ break;
++ }
++
++ if (ipkgs)
++ n_array_free (ipkgs);
++
++ if (dpkgs)
++ n_array_free (dpkgs);
++
++ if (rpkgs)
++ n_array_free (rpkgs);
++
++ return result;
++}
++
++/**
++ * setup_vf_progress:
++ */
++static void
++setup_vf_progress (struct vf_progress *vf_progress, PercentageData *pd)
++{
++ vf_progress->data = pd;
++ vf_progress->new = poldek_vf_progress_new;
++ vf_progress->progress = poldek_vf_progress;
++ vf_progress->reset = poldek_vf_progress_reset;
++ vf_progress->free = NULL;
++
++ vfile_configure (VFILE_CONF_VERBOSE, &verbose);
++ poldek_configure (ctx, POLDEK_CONF_VFILEPROGRESS, vf_progress);
++}
++
++static gint
++pkg_cmp_name_evr_rev_recno (const struct pkg *p1, const struct pkg *p2) {
++ register gint rc;
++
++ if ((rc = pkg_cmp_name_evr_rev (p1, p2)) == 0)
++ rc = -(p1->recno - p2->recno);
++
++ return rc;
++}
++
++/**
++ * poldek_pkg_evr:
++ */
++static gchar*
++poldek_pkg_evr (const struct pkg *pkg)
++{
++ if (pkg->epoch == 0)
++ return g_strdup_printf ("%s-%s", pkg->ver, pkg->rel);
++ else
++ return g_strdup_printf ("%d:%s-%s", pkg->epoch, pkg->ver, pkg->rel);
++}
++
++static gchar*
++poldek_get_vr_from_package_id_evr (const gchar *evr)
++{
++ gchar **sections, *result;
++
++ sections = g_strsplit (evr, ":", 2);
++
++ if (sections[1])
++ result = g_strdup (sections[1]);
++ else
++ result = g_strdup (evr);
++
++ g_strfreev (sections);
++
++ return result;
++}
++
++/**
++ * poldek_get_nvra_from_package_id:
++ */
++static gchar*
++poldek_get_nvra_from_package_id (const gchar* package_id)
++{
++ PkPackageId *pi;
++ gchar *vr, *result;
++
++ pi = pk_package_id_new_from_string (package_id);
++ vr = poldek_get_vr_from_package_id_evr (pi->version);
++
++ result = g_strdup_printf ("%s-%s.%s", pi->name, vr, pi->arch);
++
++ g_free (vr);
++ pk_package_id_free (pi);
++
++ return result;
++}
++
++/**
++ * poldek_get_installed_packages:
++ */
++static tn_array*
++poldek_get_installed_packages (void)
++{
++ struct poclidek_rcmd *rcmd = NULL;
++ tn_array *arr = NULL;
++
++ rcmd = poclidek_rcmd_new (cctx, NULL);
++ poclidek_rcmd_execline (rcmd, "cd /installed; ls -q *");
++
++ arr = poclidek_rcmd_get_packages (rcmd);
++
++ poclidek_rcmd_free (rcmd);
++
++ return arr;
++}
++
++/**
++ * do_requires:
++ */
++static void
++do_requires (tn_array *installed, tn_array *available, tn_array *requires, struct pkg *pkg, gboolean recursive)
++{
++ gint i;
++
++ for (i = 0; i < n_array_size (installed); i++) {
++ struct pkg *ipkg = n_array_nth (installed, i);
++ int j;
++
++ /* skip when there is no reqs */
++ if (!ipkg->reqs)
++ continue;
++
++ for (j = 0; j < n_array_size (ipkg->reqs); j++) {
++ struct capreq *req = n_array_nth (ipkg->reqs, j);
++
++ if (capreq_is_rpmlib (req))
++ continue;
++ else if (capreq_is_file (req))
++ continue;
++
++ if (pkg_satisfies_req (pkg, req, 1)) {
++ n_array_push (requires, pkg_link (ipkg));
++ break;
++ }
++ }
++ }
++ for (i = 0; i < n_array_size (available); i++) {
++ struct pkg *apkg = n_array_nth (available, i);
++ int j;
++
++ if (!apkg->reqs)
++ continue;
++
++ for (j = 0; j < n_array_size (apkg->reqs); j++) {
++ struct capreq *req = n_array_nth (apkg->reqs, j);
++
++ if (capreq_is_rpmlib (req))
++ continue;
++ else if (capreq_is_file (req))
++ continue;
++
++ if (pkg_satisfies_req (pkg, req, 1)) {
++ int k, res = -1;
++ for (k = 0; k < n_array_size (requires); k++) {
++ struct pkg *p = n_array_nth (requires, k);
++
++ if (pkg_cmp_name_evr_rev (apkg, p) == 0) {
++ res = k;
++ break;
++ }
++ }
++
++ if (res == -1) {
++ n_array_push (requires, pkg_link (apkg));
++ }
++ break;
++ }
++ }
++ }
<<Diff was trimmed, longer than 597 lines>>
More information about the pld-cvs-commit
mailing list