From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Tue, 6 Jul 2021 13:53:17 +0300 (MSK) From: Ivan Zakharyaschev To: ALT Linux Team development discussions In-Reply-To: <20210630135439.GA7599@altlinux.org> Message-ID: References: <20210630135439.GA7599@altlinux.org> User-Agent: Alpine 2.20 (LFD 67 2015-01-07) MIME-Version: 1.0 Content-Type: multipart/mixed; BOUNDARY="1807885841-1316312123-1625568797=:22813" Subject: Re: [devel] PATCH for apt: custom callbacks X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Jul 2021 10:53:17 -0000 Archived-At: List-Archive: List-Post: This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1807885841-1316312123-1625568797=:22813 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Hello! On Wed, 30 Jun 2021, Dmitry V. Levin wrote: > On Wed, Jun 30, 2021 at 04:09:40PM +0300, Ivan Zakharyaschev wrote: > > Предлагается патч на apt (API), добавляющий custom callbacks. > > > > После чтения в общих чертах у меня не появилось замечаний по архитектуре > > (а также оформлению, стилю: git show --check; отдельные места, где > > возможны разные стилистические решения вполне соответствуют окружающему > > коду, а enforced style guide у нас отсутствует). > > > > apt имеет свой тип для callback-ов, особенности rpm скрыты, что > > соответствует общему подходу в apt. "Переводом" для rpm занимается функция > > pkgRPMLibPM::customCallback из apt-pkg/rpm/rpmpm.{h,cc}: > > Кажется, апстрим apt-rpm (когда он ещё был) сильно переписал этот код по > сравнению с тем, что есть у нас. Но лучше проверить, это может быть > ложная память. Это правда. Для начала заметим эти коммиты: $ git --no-pager log -S rpmShowProgress apt-rpm/master commit 521c705aaff16ce8df5418d7a94fee4dc523cc8b Author: pmatilai Date: Fri May 26 15:58:30 2006 +0000 - add repackage progress callbacks - report full progress, erasures included - still NeedsWork (tm) commit b6c71b30209f52af6fe7f4ae75744905fa3a5d79 Author: pmatilai Date: Thu May 25 13:14:44 2006 +0000 - always use our own progress meter with internal pm - show arch for packages in progress (to clarify multilib situations) commit 7142d7fe26e117310b31a0f38a2e74e0bdc05618 Author: pmatilai Date: Mon Jan 16 23:10:47 2006 +0000 - initial import of revision 374 from cnc У меня есть ещё в точности та же (по патчам) история apt-rpm, но получше оформленная, которую я нашёл на github (как описано в spec-файле); ещё graft-ы через replace на неё, так что дальше мне будет удобнее её исследовать, и там другие номера у коммитов: $ git --no-pager log -S rpmShowProgress apt-rpm@github/master ^gears/sisyphus commit a5de6ef3b8f156ddfdff8a5b110803bb7c362844 Author: Panu Matilainen Date: Fri May 26 15:58:30 2006 +0000 - add repackage progress callbacks - report full progress, erasures included - still NeedsWork (tm) commit 7a4bf4fae645462b27fbfbde940a98039eb7e045 Author: Panu Matilainen Date: Thu May 25 13:14:44 2006 +0000 - always use our own progress meter with internal pm - show arch for packages in progress (to clarify multilib situations) Подробности про код: $ git --no-pager log -S rpmShowProgress apt-rpm@github/master ^gears/sisyphus --reverse -p commit 7a4bf4fae645462b27fbfbde940a98039eb7e045 Author: Panu Matilainen Date: Thu May 25 13:14:44 2006 +0000 - always use our own progress meter with internal pm - show arch for packages in progress (to clarify multilib situations) diff --git a/apt-pkg/rpm/rpmpm.cc b/apt-pkg/rpm/rpmpm.cc index 13b0131f6..5df695b6c 100644 --- a/apt-pkg/rpm/rpmpm.cc +++ b/apt-pkg/rpm/rpmpm.cc @@ -36,7 +36,6 @@ #if RPM_VERSION >= 0x040100 #include -#define packagesTotal rpmcliPackagesTotal #else #define rpmpsPrint(a,b) rpmProblemSetPrint(a,b) #define rpmpsFree(a) rpmProblemSetFree(a) @@ -44,9 +43,9 @@ #if RPM_VERSION < 0x040000 #define rpmtransFlags int #define rpmprobFilterFlags int -#include "rpmshowprogress.h" #endif #endif +#include "rpmshowprogress.h" // RPMPM::pkgRPMPM - Constructor /*{{{*/ // --------------------------------------------------------------------- @@ -874,11 +873,11 @@ bool pkgRPMLibPM::Process(vector &install, probFilter |= rpmtsFilterFlags(TS); rpmtsSetFlags(TS, (rpmtransFlags)(rpmtsFlags(TS) | tsFlags)); rpmtsClean(TS); - rc = rpmtsSetNotifyCallback(TS, rpmShowProgress, (void *)notifyFlags); + rc = rpmtsSetNotifyCallback(TS, rpmpmShowProgress, (void *)notifyFlags); rc = rpmtsRun(TS, NULL, (rpmprobFilterFlags)probFilter); probs = rpmtsProblems(TS); #else - rc = rpmRunTransactions(TS, rpmShowProgress, (void *)notifyFlags, NULL, + rc = rpmRunTransactions(TS, rpmpmShowProgress, (void *)notifyFlags, NULL, &probs, (rpmtransFlags)tsFlags, (rpmprobFilterFlags)probFilter); #endif diff --git a/apt-pkg/rpm/rpmshowprogress.h b/apt-pkg/rpm/rpmshowprogress.h index ddc26a63d..41dd3fae8 100644 --- a/apt-pkg/rpm/rpmshowprogress.h +++ b/apt-pkg/rpm/rpmshowprogress.h @@ -46,12 +46,20 @@ static void printHash(const unsigned long amount, const unsigned long total) } } -void * rpmShowProgress(const Header h, +#if RPM_VERSION < 0x040000 +void * rpmpmShowProgress(const Header h, +#else +void * rpmpmShowProgress(const void * arg, +#endif const rpmCallbackType what, const unsigned long amount, const unsigned long total, const void * pkgKey, void * data) { +#if RPM_VERSION >= 0x040000 + Header h = (Header) arg; +#endif + char * s; int flags = (int) ((long)data); void * rc = NULL; @@ -81,7 +89,7 @@ void * rpmShowProgress(const Header h, if (h == NULL || !(flags & INSTALL_LABEL)) break; if (flags & INSTALL_HASH) { - s = headerSprintf(h, "%{NAME}", + s = headerSprintf(h, "%{NAME}.%{ARCH}", rpmTagTable, rpmHeaderFormats, NULL); if (isatty (STDOUT_FILENO)) fprintf(stdout, "%4d:%-23.23s", progressCurrent + 1, s); @@ -91,7 +99,7 @@ void * rpmShowProgress(const Header h, free(s); s = NULL; } else { - s = headerSprintf(h, "%{NAME}-%{VERSION}-%{RELEASE}", + s = headerSprintf(h, "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}", rpmTagTable, rpmHeaderFormats, NULL); fprintf(stdout, "%s\n", s); (void) fflush(stdout); commit a5de6ef3b8f156ddfdff8a5b110803bb7c362844 Author: Panu Matilainen Date: Fri May 26 15:58:30 2006 +0000 - add repackage progress callbacks - report full progress, erasures included - still NeedsWork (tm) diff --git a/apt-pkg/rpm/rpmpm.cc b/apt-pkg/rpm/rpmpm.cc index 5df695b6c..ffdcd70a6 100644 --- a/apt-pkg/rpm/rpmpm.cc +++ b/apt-pkg/rpm/rpmpm.cc @@ -808,9 +808,9 @@ bool pkgRPMLibPM::Process(vector &install, if (_config->FindI("quiet",0) >= 1) notifyFlags |= INSTALL_LABEL; - else if (Interactive == true) + else if (Interactive == true) notifyFlags |= INSTALL_LABEL | INSTALL_HASH; - else + else notifyFlags |= INSTALL_LABEL | INSTALL_PERCENT; if (uninstall.empty() == false) @@ -820,8 +820,10 @@ bool pkgRPMLibPM::Process(vector &install, if (upgrade.empty() == false) AddToTransaction(Item::RPMUpgrade, upgrade); - // Setup the gauge used by rpmShowProgress. - packagesTotal = install.size()+upgrade.size(); + // FIXME: This ain't right because most things show up in upgrade + // even if they're really just installs, and repackaging isn't taken + // into account either. + packagesTotal = install.size() + upgrade.size() * 2 + uninstall.size(); #if RPM_VERSION >= 0x040100 if (_config->FindB("RPM::NoDeps", false) == false) { Здесь имя функции заменилось на rpmpmShowProgress; поищем дальше по нему: $ git --no-pager log -S rpmpmShowProgress apt-rpm@github/master ^gears/sisyphus --reverse --stat -p commit 7a4bf4fae645462b27fbfbde940a98039eb7e045 Author: Panu Matilainen Date: Thu May 25 13:14:44 2006 +0000 - always use our own progress meter with internal pm - show arch for packages in progress (to clarify multilib situations) --- apt-pkg/rpm/rpmpm.cc | 7 +++---- apt-pkg/rpm/rpmshowprogress.h | 14 +++++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/apt-pkg/rpm/rpmpm.cc b/apt-pkg/rpm/rpmpm.cc index 13b0131f6..5df695b6c 100644 --- a/apt-pkg/rpm/rpmpm.cc +++ b/apt-pkg/rpm/rpmpm.cc @@ -36,7 +36,6 @@ #if RPM_VERSION >= 0x040100 #include -#define packagesTotal rpmcliPackagesTotal #else #define rpmpsPrint(a,b) rpmProblemSetPrint(a,b) #define rpmpsFree(a) rpmProblemSetFree(a) @@ -44,9 +43,9 @@ #if RPM_VERSION < 0x040000 #define rpmtransFlags int #define rpmprobFilterFlags int -#include "rpmshowprogress.h" #endif #endif +#include "rpmshowprogress.h" // RPMPM::pkgRPMPM - Constructor /*{{{*/ // --------------------------------------------------------------------- @@ -874,11 +873,11 @@ bool pkgRPMLibPM::Process(vector &install, probFilter |= rpmtsFilterFlags(TS); rpmtsSetFlags(TS, (rpmtransFlags)(rpmtsFlags(TS) | tsFlags)); rpmtsClean(TS); - rc = rpmtsSetNotifyCallback(TS, rpmShowProgress, (void *)notifyFlags); + rc = rpmtsSetNotifyCallback(TS, rpmpmShowProgress, (void *)notifyFlags); rc = rpmtsRun(TS, NULL, (rpmprobFilterFlags)probFilter); probs = rpmtsProblems(TS); #else - rc = rpmRunTransactions(TS, rpmShowProgress, (void *)notifyFlags, NULL, + rc = rpmRunTransactions(TS, rpmpmShowProgress, (void *)notifyFlags, NULL, &probs, (rpmtransFlags)tsFlags, (rpmprobFilterFlags)probFilter); #endif diff --git a/apt-pkg/rpm/rpmshowprogress.h b/apt-pkg/rpm/rpmshowprogress.h index ddc26a63d..41dd3fae8 100644 --- a/apt-pkg/rpm/rpmshowprogress.h +++ b/apt-pkg/rpm/rpmshowprogress.h @@ -46,12 +46,20 @@ static void printHash(const unsigned long amount, const unsigned long total) } } -void * rpmShowProgress(const Header h, +#if RPM_VERSION < 0x040000 +void * rpmpmShowProgress(const Header h, +#else +void * rpmpmShowProgress(const void * arg, +#endif const rpmCallbackType what, const unsigned long amount, const unsigned long total, const void * pkgKey, void * data) { +#if RPM_VERSION >= 0x040000 + Header h = (Header) arg; +#endif + char * s; int flags = (int) ((long)data); void * rc = NULL; @@ -81,7 +89,7 @@ void * rpmShowProgress(const Header h, if (h == NULL || !(flags & INSTALL_LABEL)) break; if (flags & INSTALL_HASH) { - s = headerSprintf(h, "%{NAME}", + s = headerSprintf(h, "%{NAME}.%{ARCH}", rpmTagTable, rpmHeaderFormats, NULL); if (isatty (STDOUT_FILENO)) fprintf(stdout, "%4d:%-23.23s", progressCurrent + 1, s); @@ -91,7 +99,7 @@ void * rpmShowProgress(const Header h, free(s); s = NULL; } else { - s = headerSprintf(h, "%{NAME}-%{VERSION}-%{RELEASE}", + s = headerSprintf(h, "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}", rpmTagTable, rpmHeaderFormats, NULL); fprintf(stdout, "%s\n", s); (void) fflush(stdout); commit 8b1651fb32c7b93a0cd8454896f818343d2dda12 Author: Panu Matilainen Date: Thu May 25 13:31:38 2006 +0000 - move showprogress implementation out of the header file so that changes dont trigger rebuilding the whole dang thing --- apt-pkg/rpm/rpmshowprogress.cc | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) diff --git a/apt-pkg/rpm/rpmshowprogress.cc b/apt-pkg/rpm/rpmshowprogress.cc new file mode 100644 index 000000000..ccae011d7 --- /dev/null +++ b/apt-pkg/rpm/rpmshowprogress.cc @@ -0,0 +1,152 @@ + +#include +#include +#include + +#include "rpmshowprogress.h" +// +// This code was originally from rpm 4.0.3. +// +static void printHash(const unsigned long amount, const unsigned long total) +{ + int hashesNeeded; + int hashesTotal = 50; + + if (isatty (STDOUT_FILENO)) + hashesTotal = 44; + + if (hashesPrinted != hashesTotal) { + hashesNeeded = (int)(hashesTotal*(total?(((float)amount)/total):1)); + while (hashesNeeded > hashesPrinted) { + if (isatty (STDOUT_FILENO)) { + int i; + for (i = 0; i < hashesPrinted; i++) (void) putchar ('#'); + for (; i < hashesTotal; i++) (void) putchar (' '); + fprintf(stdout, "(%3d%%)", + (int)(100 * (total ? (((float) amount) / total) : 1))); + for (i = 0; i < (hashesTotal + 6); i++) (void) putchar ('\b'); + } else + fprintf(stdout, "#"); + + hashesPrinted++; + } + (void) fflush(stdout); + hashesPrinted = hashesNeeded; + + if (hashesPrinted == hashesTotal) { + int i; + progressCurrent++; + if (isatty(STDOUT_FILENO)) { + for (i = 1; i < hashesPrinted; i++) (void) putchar ('#'); + fprintf(stdout, " [%3d%%]", (int)(100 * (progressTotal ? + (((float) progressCurrent) / progressTotal) : 1))); + } + fprintf(stdout, "\n"); + } + (void) fflush(stdout); + } +} + +#if RPM_VERSION < 0x040000 +void * rpmpmShowProgress(const Header h, +#else +void * rpmpmShowProgress(const void * arg, +#endif + const rpmCallbackType what, + const unsigned long amount, + const unsigned long total, + const void * pkgKey, void * data) +{ +#if RPM_VERSION >= 0x040000 + Header h = (Header) arg; +#endif + + char * s; + int flags = (int) ((long)data); + void * rc = NULL; + const char * filename = (const char *) pkgKey; + static FD_t fd = NULL; + + switch (what) { + case RPMCALLBACK_INST_OPEN_FILE: + if (filename == NULL || filename[0] == '\0') + return NULL; + fd = Fopen(filename, "r.ufdio"); + if (fd) + fd = fdLink(fd, "persist (showProgress)"); + return fd; + /*@notreached@*/ break; + + case RPMCALLBACK_INST_CLOSE_FILE: + fd = fdFree(fd, "persist (showProgress)"); + if (fd) { + (void) Fclose(fd); + fd = NULL; + } + break; + + case RPMCALLBACK_INST_START: + hashesPrinted = 0; + if (h == NULL || !(flags & INSTALL_LABEL)) + break; + if (flags & INSTALL_HASH) { + s = headerSprintf(h, "%{NAME}.%{ARCH}", + rpmTagTable, rpmHeaderFormats, NULL); + if (isatty (STDOUT_FILENO)) + fprintf(stdout, "%4d:%-23.23s", progressCurrent + 1, s); + else + fprintf(stdout, "%-28.28s", s); + (void) fflush(stdout); + free(s); + s = NULL; + } else { + s = headerSprintf(h, "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}", + rpmTagTable, rpmHeaderFormats, NULL); + fprintf(stdout, "%s\n", s); + (void) fflush(stdout); + free(s); + s = NULL; + } + break; + + case RPMCALLBACK_TRANS_PROGRESS: + case RPMCALLBACK_INST_PROGRESS: + if (flags & INSTALL_PERCENT) + fprintf(stdout, "%%%% %f\n", (double) (total + ? ((((float) amount) / total) * 100) + : 100.0)); + else if (flags & INSTALL_HASH) + printHash(amount, total); + (void) fflush(stdout); + break; + + case RPMCALLBACK_TRANS_START: + hashesPrinted = 0; + progressTotal = 1; + progressCurrent = 0; + if (!(flags & INSTALL_LABEL)) + break; + if (flags & INSTALL_HASH) + fprintf(stdout, "%-28s", _("Preparing...")); + else + fprintf(stdout, "%s\n", _("Preparing...")); + (void) fflush(stdout); + break; + + case RPMCALLBACK_TRANS_STOP: + if (flags & INSTALL_HASH) + printHash(1, 1); /* Fixes "preparing..." progress bar */ + progressTotal = packagesTotal; + progressCurrent = 0; + break; + + case RPMCALLBACK_UNINST_PROGRESS: + case RPMCALLBACK_UNINST_START: + case RPMCALLBACK_UNINST_STOP: + /* ignore */ + break; + } + + return rc; +} + commit 8f940eff2b3061c3a80e8e92ef0cf0ba4c9deb02 Author: Panu Matilainen Date: Sat Feb 24 15:25:52 2007 +0200 - beginnings of install progress API --- apt-pkg/rpm/rpmpm.cc | 21 ++++++++------- apt-pkg/rpm/rpmshowprogress.cc | 227 ------------------------------------------------------------------------------------------------------------------------------------------------------------- apt-pkg/rpm/rpmshowprogress.h | 17 ------------ 3 files changed, 11 insertions(+), 254 deletions(-) diff --git a/apt-pkg/rpm/rpmpm.cc b/apt-pkg/rpm/rpmpm.cc index 61044bd57..91eeb3027 100644 --- a/apt-pkg/rpm/rpmpm.cc +++ b/apt-pkg/rpm/rpmpm.cc @@ -45,7 +45,9 @@ #define rpmprobFilterFlags int #endif #endif -#include "rpmshowprogress.h" +#include "rpmcallback.h" + +extern int packagesTotal; // RPMPM::pkgRPMPM - Constructor /*{{{*/ // --------------------------------------------------------------------- @@ -236,7 +238,7 @@ bool pkgRPMPM::RunScriptsWithPkgs(const char *Cnf) // RPMPM::Go - Run the sequence /*{{{*/ // --------------------------------------------------------------------- /* This globs the operations and calls rpm */ -bool pkgRPMPM::Go() +bool pkgRPMPM::Go(InstProgress &Prog) { if (List.empty() == true) return true; @@ -339,7 +341,7 @@ bool pkgRPMPM::Go() } #endif - if (Process(install, upgrade, uninstall) == false) + if (Process(Prog, install, upgrade, uninstall) == false) Ret = false; #ifdef APT_WITH_LUA @@ -638,7 +640,8 @@ bool pkgRPMExtPM::ExecRPM(Item::RPMOps op, vector &files) return true; } -bool pkgRPMExtPM::Process(vector &install, +bool pkgRPMExtPM::Process(InstProgress &Prog, + vector &install, vector &upgrade, vector &uninstall) { @@ -742,7 +745,8 @@ bool pkgRPMLibPM::AddToTransaction(Item::RPMOps op, vector &files) return true; } -bool pkgRPMLibPM::Process(vector &install, +bool pkgRPMLibPM::Process(InstProgress &Prog, + vector &install, vector &upgrade, vector &uninstall) { @@ -887,13 +891,12 @@ bool pkgRPMLibPM::Process(vector &install, goto exit; } - cout << _("Committing changes...") << endl << flush; - + Prog.OverallProgress(0, 1, 1, "Committing changes..."); #if RPM_VERSION >= 0x040100 probFilter |= rpmtsFilterFlags(TS); rpmtsSetFlags(TS, (rpmtransFlags)(rpmtsFlags(TS) | tsFlags)); rpmtsClean(TS); - rc = rpmtsSetNotifyCallback(TS, rpmpmShowProgress, (void *)notifyFlags); + rc = rpmtsSetNotifyCallback(TS, rpmCallback, &Prog); rc = rpmtsRun(TS, NULL, (rpmprobFilterFlags)probFilter); probs = rpmtsProblems(TS); #else @@ -910,8 +913,6 @@ bool pkgRPMLibPM::Process(vector &install, Success = true; if (rc < 0) _error->Warning(_("Some errors occurred while running transaction")); - else if (Interactive == true) - cout << _("Done.") << endl; } rpmpsFree(probs); diff --git a/apt-pkg/rpm/rpmshowprogress.cc b/apt-pkg/rpm/rpmshowprogress.cc deleted file mode 100644 index d3d61eb6a..000000000 --- a/apt-pkg/rpm/rpmshowprogress.cc +++ /dev/null @@ -1,227 +0,0 @@ - -#include -#include -#include - -#include "rpmshowprogress.h" - -static int hashesTotal = 0; -static int hashesCurrent = 0; -static int progressCurrent = 0; -static int progressTotal = 0; - -int packagesTotal; - -static void printHash(const unsigned long amount, const unsigned long total) -{ - int hashesNeeded; - - hashesTotal = (isatty (STDOUT_FILENO) ? 44 : 50); - - if (hashesCurrent != hashesTotal) { - float pct = (total ? (((float) amount) / total) : 1.0); - hashesNeeded = (int) ((hashesTotal * pct) + 0.5); - while (hashesNeeded > hashesCurrent) { - if (isatty (STDOUT_FILENO)) { - int i; - for (i = 0; i < hashesCurrent; i++) - (void) putchar ('#'); - for (; i < hashesTotal; i++) - (void) putchar (' '); - fprintf(stdout, "(%3d%%)", (int)((100 * pct) + 0.5)); - for (i = 0; i < (hashesTotal + 6); i++) - (void) putchar ('\b'); - } else - fprintf(stdout, "#"); - - hashesCurrent++; - } - (void) fflush(stdout); - - if (hashesCurrent == hashesTotal) { - int i; - progressCurrent++; - if (isatty(STDOUT_FILENO)) { - for (i = 1; i < hashesCurrent; i++) - (void) putchar ('#'); - pct = (progressTotal - ? (((float) progressCurrent) / progressTotal) - : 1); - fprintf(stdout, " [%3d%%]", (int)((100 * pct) + 0.5)); - } - fprintf(stdout, "\n"); - } - (void) fflush(stdout); - } -} - -#if RPM_VERSION < 0x040000 -void * rpmpmShowProgress(const Header h, -#else -void * rpmpmShowProgress(const void * arg, -#endif - const rpmCallbackType what, -#if RPM_VERSION >= 0x040405 - const unsigned long long amount, - const unsigned long long total, -#else - const unsigned long amount, - const unsigned long total, -#endif - const void * pkgKey, void * data) - -{ -#if RPM_VERSION >= 0x040000 - Header h = (Header) arg; -#endif - - char * s; - int flags = (int) ((long)data); - void * rc = NULL; - const char * filename = (const char *) pkgKey; - static FD_t fd = NULL; - static rpmCallbackType state; - static bool repackage; - - switch (what) { - case RPMCALLBACK_INST_OPEN_FILE: - if (filename == NULL || filename[0] == '\0') - return NULL; - fd = Fopen(filename, "r.ufdio"); - if (fd) - fd = fdLink(fd, "persist (showProgress)"); - return fd; - /*@notreached@*/ break; - - case RPMCALLBACK_INST_CLOSE_FILE: - fd = fdFree(fd, "persist (showProgress)"); - if (fd) { - (void) Fclose(fd); - fd = NULL; - } - break; - - case RPMCALLBACK_INST_START: - hashesCurrent = 0; - if (h == NULL || !(flags & INSTALL_LABEL)) - break; - - if (state != what && repackage == false) { - state = what; - fprintf(stdout, "%s\n", _("Installing / Updating...")); - (void) fflush(stdout); - } - - if (flags & INSTALL_HASH) { - s = headerSprintf(h, "%{NAME}.%{ARCH}", - rpmTagTable, rpmHeaderFormats, NULL); - if (isatty (STDOUT_FILENO)) - fprintf(stdout, "%4d:%-23.23s", progressCurrent + 1, s); - else - fprintf(stdout, "%-28.28s", s); - (void) fflush(stdout); - free(s); - s = NULL; - } else { - s = headerSprintf(h, "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}", - rpmTagTable, rpmHeaderFormats, NULL); - fprintf(stdout, "%s\n", s); - (void) fflush(stdout); - free(s); - s = NULL; - } - break; - - case RPMCALLBACK_TRANS_PROGRESS: - case RPMCALLBACK_INST_PROGRESS: - if (flags & INSTALL_PERCENT) - fprintf(stdout, "%%%% %f\n", (double) (total - ? ((((float) amount) / total) * 100) - : 100.0)); - else if (flags & INSTALL_HASH) - printHash(amount, total); - (void) fflush(stdout); - break; - - case RPMCALLBACK_TRANS_START: - state = what; - repackage = false; - hashesCurrent = 0; - progressTotal = 1; - progressCurrent = 0; - if (!(flags & INSTALL_LABEL)) - break; - if (flags & INSTALL_HASH) - fprintf(stdout, "%-28s", _("Preparing...")); - else - fprintf(stdout, "%s\n", _("Preparing...")); - (void) fflush(stdout); - break; - - case RPMCALLBACK_TRANS_STOP: - if (flags & INSTALL_HASH) - printHash(1, 1); /* Fixes "preparing..." progress bar */ - progressTotal = packagesTotal; - progressCurrent = 0; - break; - - case RPMCALLBACK_REPACKAGE_START: - hashesCurrent = 0; - progressCurrent = 0; - repackage = true; - if (!(flags & INSTALL_LABEL)) - break; - if (flags & INSTALL_HASH) - fprintf(stdout, "%-28s\n", _("Repackaging...")); - else - fprintf(stdout, "%s\n", _("Repackaging...")); - (void) fflush(stdout); - break; - - case RPMCALLBACK_REPACKAGE_PROGRESS: - if (amount && (flags & INSTALL_HASH)) - printHash(1, 1); /* Fixes "preparing..." progress bar */ - break; - - case RPMCALLBACK_REPACKAGE_STOP: - progressTotal = total; - progressCurrent = total; - if (flags & INSTALL_HASH) - printHash(1, 1); /* Fixes "preparing..." progress bar */ - progressTotal = packagesTotal; - repackage = false; - break; - - case RPMCALLBACK_UNINST_PROGRESS: - break; - case RPMCALLBACK_UNINST_START: - hashesCurrent = 0; - if (!(flags & INSTALL_LABEL)) - break; - if (state != what) { - state = what; - fprintf(stdout, "%s\n", _("Removing / Cleaning up...")); - (void) fflush(stdout); - } - break; - - case RPMCALLBACK_UNINST_STOP: - if (h == NULL || !(flags & INSTALL_LABEL)) - break; - s = headerSprintf(h, "%{NAME}.%{ARCH}", rpmTagTable, rpmHeaderFormats, NULL); - if (flags & INSTALL_HASH) { - fprintf(stdout, "%4d:%-23.23s", progressCurrent + 1, s); - printHash(1, 1); - } else { - fprintf(stdout, "%-28.28s", s); - } - fflush(stdout); - s = NULL; - break; - default: // Fall through - break; - } - - return rc; -} - diff --git a/apt-pkg/rpm/rpmshowprogress.h b/apt-pkg/rpm/rpmshowprogress.h deleted file mode 100644 index 9c33f962e..000000000 --- a/apt-pkg/rpm/rpmshowprogress.h +++ /dev/null @@ -1,17 +0,0 @@ - -extern int packagesTotal; - -#if RPM_VERSION < 0x040000 -void * rpmpmShowProgress(const Header h, -#else -void * rpmpmShowProgress(const void * arg, -#endif - const rpmCallbackType what, -#if RPM_VERSION >= 0x040405 - const unsigned long long amount, - const unsigned long long total, -#else - const unsigned long amount, - const unsigned long total, -#endif - const void * pkgKey, void * data); commit fa650dbfb5757dceffb269cbd0c34d2e2e44ef7e Author: Panu Matilainen Date: Mon Mar 5 23:39:29 2007 +0200 - More progress meter work. Broken in various entertaining ways at the moment - Unbreak API by allowing DoInstall() to create "compatibility" progress meters. Compatibility inteded mostly for Synaptic, which has dirrrrrrrrrty hacks that break the pkgPackageManager class protections, invalidating our compat hacks. Oh well... --- apt-pkg/rpm/rpmpm.cc | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/apt-pkg/rpm/rpmpm.cc b/apt-pkg/rpm/rpmpm.cc index 91eeb3027..f7ab343d9 100644 --- a/apt-pkg/rpm/rpmpm.cc +++ b/apt-pkg/rpm/rpmpm.cc @@ -238,7 +238,7 @@ bool pkgRPMPM::RunScriptsWithPkgs(const char *Cnf) // RPMPM::Go - Run the sequence /*{{{*/ // --------------------------------------------------------------------- /* This globs the operations and calls rpm */ -bool pkgRPMPM::Go(InstProgress &Prog) +bool pkgRPMPM::Go() { if (List.empty() == true) return true; @@ -341,7 +341,7 @@ bool pkgRPMPM::Go(InstProgress &Prog) } #endif - if (Process(Prog, install, upgrade, uninstall) == false) + if (Process(install, upgrade, uninstall) == false) Ret = false; #ifdef APT_WITH_LUA @@ -640,10 +640,9 @@ bool pkgRPMExtPM::ExecRPM(Item::RPMOps op, vector &files) return true; } -bool pkgRPMExtPM::Process(InstProgress &Prog, - vector &install, - vector &upgrade, - vector &uninstall) +bool pkgRPMExtPM::Process(vector &install, + vector &upgrade, + vector &uninstall) { if (uninstall.empty() == false) ExecRPM(Item::RPMErase, uninstall); @@ -745,8 +744,7 @@ bool pkgRPMLibPM::AddToTransaction(Item::RPMOps op, vector &files) return true; } -bool pkgRPMLibPM::Process(InstProgress &Prog, - vector &install, +bool pkgRPMLibPM::Process(vector &install, vector &upgrade, vector &uninstall) { @@ -832,7 +830,8 @@ bool pkgRPMLibPM::Process(InstProgress &Prog, if (upgrade.empty() == false) AddToTransaction(Item::RPMUpgrade, upgrade); - packagesTotal = 0; + // XXX temp stuff.. + int packagesTotal = 0; // Figure out exactly how many rpm operations we're going to process, // repackages and all. int repackage = (tsFlags & RPMTRANS_FLAG_REPACKAGE) ? 1 : 0; @@ -891,16 +890,16 @@ bool pkgRPMLibPM::Process(InstProgress &Prog, goto exit; } - Prog.OverallProgress(0, 1, 1, "Committing changes..."); + Progress->OverallProgress(0, 1, 1, "Committing changes..."); #if RPM_VERSION >= 0x040100 probFilter |= rpmtsFilterFlags(TS); rpmtsSetFlags(TS, (rpmtransFlags)(rpmtsFlags(TS) | tsFlags)); rpmtsClean(TS); - rc = rpmtsSetNotifyCallback(TS, rpmCallback, &Prog); + rc = rpmtsSetNotifyCallback(TS, rpmCallback, Progress); rc = rpmtsRun(TS, NULL, (rpmprobFilterFlags)probFilter); probs = rpmtsProblems(TS); #else - rc = rpmRunTransactions(TS, rpmpmShowProgress, (void *)notifyFlags, NULL, + rc = rpmRunTransactions(TS, rpmCallback, Progress, NULL, &probs, (rpmtransFlags)tsFlags, (rpmprobFilterFlags)probFilter); #endif rpmpmShowProgress заменяется на rpmCallback. Поищем по нему: $ git --no-pager log -S rpmCallback apt-rpm@github/master ^gears/sisyphus --reverse --stat --pickaxe-all commit 8b1651fb32c7b93a0cd8454896f818343d2dda12 Author: Panu Matilainen Date: Thu May 25 13:31:38 2006 +0000 - move showprogress implementation out of the header file so that changes dont trigger rebuilding the whole dang thing apt-pkg/Makefile.am | 1 + apt-pkg/Makefile.in | 22 ++++++++++++++-------- apt-pkg/rpm/rpmshowprogress.cc | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ apt-pkg/rpm/rpmshowprogress.h | 140 +++----------------------------------------------------------------------------------------------------------------------------------------- 4 files changed, 170 insertions(+), 145 deletions(-) commit a1a543f32bff361343759d08a85661a69f748726 Author: Panu Matilainen Date: Thu May 25 14:15:26 2006 +0000 - initial erasure callbacks apt-pkg/rpm/rpmshowprogress.cc | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) commit 8f940eff2b3061c3a80e8e92ef0cf0ba4c9deb02 Author: Panu Matilainen Date: Sat Feb 24 15:25:52 2007 +0200 - beginnings of install progress API apt-pkg/Makefile.am | 4 +-- apt-pkg/Makefile.in | 17 ++++++------ apt-pkg/contrib/progress.cc | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ apt-pkg/contrib/progress.h | 27 +++++++++++++++++++ apt-pkg/packagemanager.cc | 4 +-- apt-pkg/packagemanager.h | 5 ++-- apt-pkg/rpm/rpmpm.cc | 21 ++++++++------- apt-pkg/rpm/rpmpm.h | 11 +++++--- apt-pkg/rpm/rpmshowprogress.cc | 227 ------------------------------------------------------------------------------------------------------------------------------------------------------------- apt-pkg/rpm/rpmshowprogress.h | 17 ------------ cmdline/apt-get.cc | 6 +++-- cmdline/apt-shell.cc | 6 +++-- 12 files changed, 153 insertions(+), 277 deletions(-) commit a6b3e3642cd9635a887d8f56b3275684e8602c4a Author: Panu Matilainen Date: Mon Feb 26 08:53:20 2007 +0200 - remember to add rpmcallback files to git, duh apt-pkg/rpm/rpmcallback.cc | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ apt-pkg/rpm/rpmcallback.h | 20 ++++++++++++++++++++ 2 files changed, 150 insertions(+) commit fa650dbfb5757dceffb269cbd0c34d2e2e44ef7e Author: Panu Matilainen Date: Mon Mar 5 23:39:29 2007 +0200 - More progress meter work. Broken in various entertaining ways at the moment - Unbreak API by allowing DoInstall() to create "compatibility" progress meters. Compatibility inteded mostly for Synaptic, which has dirrrrrrrrrty hacks that break the pkgPackageManager class protections, invalidating our compat hacks. Oh well... apt-pkg/contrib/progress.cc | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------- apt-pkg/contrib/progress.h | 51 +++++++++++++++++++++++++++++++++++++-------------- apt-pkg/packagemanager.cc | 18 ++++++++++++++++-- apt-pkg/packagemanager.h | 6 ++++-- apt-pkg/rpm/rpmcallback.cc | 70 ++++++++++++++++++++++++++++++++++++++++++++++------------------------ apt-pkg/rpm/rpmpm.cc | 23 +++++++++++------------ apt-pkg/rpm/rpmpm.h | 23 ++++++++++------------- cmdline/apt-get.cc | 6 ++---- cmdline/apt-shell.cc | 6 ++---- 9 files changed, 195 insertions(+), 137 deletions(-) commit 882ff480abef8ebf88398335a7392db85272cf4a Author: Panu Matilainen Date: Sun Jun 8 09:16:24 2008 +0300 Use raptFoo types as necessary in rpmhandler & friends apt-pkg/rpm/aptcallback.cc | 4 ++-- apt-pkg/rpm/aptcallback.h | 11 +++-------- apt-pkg/rpm/rpmhandler.cc | 42 ++++++++++++++++++------------------------ apt-pkg/rpm/rpmhandler.h | 5 +++-- apt-pkg/rpm/rpmversion.cc | 5 +++-- 5 files changed, 29 insertions(+), 38 deletions(-) commit 502243cccdf802d31e998afb679e02bb56e48f43 Author: Panu Matilainen Date: Tue Nov 23 21:45:28 2010 +0200 Rip out support for RPM v3. Time to let go of something... apt-pkg/rpm/aptcallback.cc | 6 ------ apt-pkg/rpm/aptcallback.h | 4 ---- apt-pkg/rpm/raptheader.cc | 2 -- apt-pkg/rpm/rpmhandler.cc | 45 +-------------------------------------------- apt-pkg/rpm/rpmhandler.h | 2 -- apt-pkg/rpm/rpmpm.cc | 28 ---------------------------- apt-pkg/rpm/rpmpm.h | 3 --- tools/genpkglist.cc | 2 -- tools/gensrclist.cc | 2 -- 9 files changed, 1 insertion(+), 93 deletions(-) commit 8c88e2177a7b29cc36eca603eef0937116c514c0 Author: Panu Matilainen Date: Thu Apr 7 18:25:48 2011 +0300 Chainsaw support for rpm < 4.6.0 out for real apt-pkg/rpm/raptheader.cc | 73 +------------------------------------------------------------------------ apt-pkg/rpm/raptheader.h | 4 ---- apt-pkg/rpm/rapttypes.h | 18 ------------------ apt-pkg/rpm/rpmhandler.cc | 126 ++---------------------------------------------------------------------------------------------------------------------------- apt-pkg/rpm/rpmhandler.h | 6 ------ apt-pkg/rpm/rpmpackagedata.cc | 2 -- apt-pkg/rpm/rpmpm.cc | 89 +++++------------------------------------------------------------------------------------ apt-pkg/rpm/rpmpm.h | 7 ------- apt-pkg/rpm/rpmsystem.cc | 11 ----------- apt-pkg/rpm/rpmversion.cc | 10 ---------- configure.ac | 27 ++------------------------- tools/genpkglist.cc | 13 ------------- tools/gensrclist.cc | 16 ---------------- 13 files changed, 10 insertions(+), 392 deletions(-) Тут можно заметить, основные релефантные файлы такие, можно по ним историю отфильтровать: $ git --no-pager log --oneline apt-rpm@github/master -- apt-pkg/{contrib/progress\*,apt-pkg/rpm/rpmcallback\*} 462c64e8d Add bunch of missing includes to fix build with gcc 4.7 ae1584ad3 progress.cc (OpProgress::CheckChange): optimize redundant gettimeofday() calls f51e0bac4 Remove all interface/implementation #pragmas - hardly useful, eliminated from debian apt too d16036df4 Remove bogus semicolons in inline method definitions (Bernhard Rosenkränzer) f7db55202 Preliminaries for quiet option in progress class 32a76471d Silly install progress cosmetics c4da25f05 Don't call installprogress Done() from destructor, not a very good idea to begin with and causes crash n burn in some situations (rhbz#419811). Since rpm doesn't issue "all done" callback, manually call Done() after transaction finishes. c782c159b Explicitly include where needed, in gcc 4.3 no longer automatically includes it. 5f5fe0a6f - more descriptive progress messages - make more space for package nevra info in hash progress meter e3089a009 - working install, remove and upgrade progress .. kinda ef49b0639 - progress meter cosmetics fa650dbfb - More progress meter work. Broken in various entertaining ways at the moment - Unbreak API by allowing DoInstall() to create "compatibility" progress meters. Compatibility inteded mostly for Synaptic, which has dirrrrrrrrrty hacks that break the pkgPackageManager class protections, invalidating our compat hacks. Oh well... 11c8ba548 - show package name when upgrading/removing - remove debug junk 8f940eff2 - beginnings of install progress API fffc37671 - various "cosmetics" cleanups to shut up gcc complaints on higher warning levels (Ralf) 794485f9c - fix opening *.cc and *.h files in proper C++ mode in xemacs as well (Ville Skyttä) c27ced7a9 Merging apt-rpm 0.5.5cnc1 over upstream APT in development trunk. А у нас в истории это место трогается вот где: $ git --no-pager log --oneline gears/sisyphus -- {apt/,}apt-pkg/{contrib/progress\*,apt-pkg/rpm/rpmcallback\*} 4baf89c7a optimize: Avoid copying objects (Might affect ABI; but tiny visible API changes) 1e8f85a1c Remove bogus semicolons in inline method definitions (Bernhard Rosenkränzer) 1a3583734 API changes: Use 'override' keyword 4597a9c3d Remove all interface/implementation #pragmas 702382b05 Fix remaining whitespace issues 2bcb8712b Strip trailing whitespaces b9f992810 Eliminate apt subdirectory 6f66568cc Revert a 0.5.15lorg2-alt70 helpful stylistic change to be applied later: "Use 'override' keyword" 093aa4083 Revert a 0.5.15lorg2-alt70 optimization change to be rebased over other cleanup: "Avoid copying objects" 8dfa25bde Revert a 0.5.15lorg2-alt70 change, which is too rude: "Support large files" 297a12d92 (refs/ATTIC/fix-longlong0_/BASE) Support large files c742cecda (refs/ATTIC/avoid-copy_/REVIEW-BASE) Avoid copying objects ec437de01 Use 'override' keyword b631357d8 (for Emacs) add apt/.dir-locals.el; remove unknown mode specifications in files 79b66f684 Apply apt-0.5.15lorg2-alt-lfs.patch 6bbc09c43 Apply apt-0.5.15lorg2-alt-gcc4.3.patch 321234252 (tag: 0.5.5cnc1-alt3) 0.5.5cnc1-alt3 e3ad0ef69 (tag: 0.3.19cnc55-alt3) 0.3.19cnc55-alt3 У меня сложилось представление (может быть, я ошибаюсь), что там не две разные функции rpmShowProgress vs rpmCallback используются, а один путь, и особая обработка прогресса предполагается что будет реализовываться через расширение класса OpProgress из contrib/progress.h. -- Best regards, Ivan --1807885841-1316312123-1625568797=:22813--