From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from re-prd-fep-045.btinternet.com (mailomta8-re.btinternet.com [213.120.69.101]) by sourceware.org (Postfix) with ESMTPS id 61B30385E02F for ; Fri, 8 Mar 2024 18:36:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 61B30385E02F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dronecode.org.uk Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dronecode.org.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 61B30385E02F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=213.120.69.101 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709922987; cv=none; b=r8QyYjHhtX70l4UoAJZNWGKZWejZpaxzu4MTX+YMZZkyEgWKiDUZ9XXwYgsOfytaMFGQNew7WSEobnCex5w+Eu94sRhOle5x0bvHiqH4DMR+IleVBv5KJLgR788g1tHq7BYdufuBH0k+qYUdkPB11RHlHcM8BKtgenLH6V6SNYk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709922987; c=relaxed/simple; bh=LKMCql0KQ9PDWmnIVa9tdFmQDDhUbAL2fkdpEwkCwJ0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=YVDjhO+Tl11yEPZ6YLUikDDJueSZEc3N4jYDIbmHuv8QDyLoH90mvoV+jFuDHIErYHf3tXLPklT/nOeLdFJwCY0a1WCDL71QNRqR7epo4nTS8A85vpNMiuc4/oOOhRLlo8BTFLqTTcrgkbs1V9SeLXHjV+0XMbdrdqPAtJtdqUo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from re-prd-rgout-004.btmx-prd.synchronoss.net ([10.2.54.7]) by re-prd-fep-045.btinternet.com with ESMTP id <20240308183623.TNYX21611.re-prd-fep-045.btinternet.com@re-prd-rgout-004.btmx-prd.synchronoss.net>; Fri, 8 Mar 2024 18:36:23 +0000 Authentication-Results: btinternet.com; none X-SNCR-Rigid: 6577B87C0AB06AB4 X-Originating-IP: [81.153.98.185] X-OWM-Source-IP: 81.153.98.185 X-OWM-Env-Sender: jon.turney@dronecode.org.uk X-VadeSecure-score: verdict=clean score=0/300, class=clean X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvledrieehgdduudegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecunecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheplfhonhcuvfhurhhnvgihuceojhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukheqnecuggftrfgrthhtvghrnhepudevleegtdduudeltedugeeuhefgteegkeeuhfeukeetkeduteekvdfgiefguddvnecuffhomhgrihhnpehgnhhurdhorhhgnecukfhppeekuddrudehfedrleekrddukeehnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehhvghloheplhhotggrlhhhohhsthdrlhhotggrlhguohhmrghinhdpihhnvghtpeekuddrudehfedrleekrddukeehpdhmrghilhhfrhhomhepjhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukhdpnhgspghrtghpthhtohepvddprhgtphhtthhopegthihgfihinhdqrghpphhssegthihgfihinhdrtghomhdprhgtphhtthhopehjohhnrdhtuhhrnhgvhiesughrohhnvggtohguvgdrohhrghdruhhkpdhrvghvkffrpehhohhsthekuddqudehfedqleekqddukeehrdhrrghnghgvkeduqdduheefrdgsthgtvghnthhrrghlphhluhhsrdgtohhmpdgruhhthhgpuhhsvghrpehjohhnthhurhhnvgihsegsthhi nhhtvghrnhgvthdrtghomhdpghgvohfkrfepifeupdfovfetjfhoshhtpehrvgdqphhrugdqrhhgohhuthdqtddtge X-RazorGate-Vade-Verdict: clean 0 X-RazorGate-Vade-Classification: clean Received: from localhost.localdomain (81.153.98.185) by re-prd-rgout-004.btmx-prd.synchronoss.net (authenticated as jonturney@btinternet.com) id 6577B87C0AB06AB4; Fri, 8 Mar 2024 18:36:23 +0000 From: Jon Turney To: cygwin-apps@cygwin.com Cc: Jon Turney Subject: [PATCH setup 13/16] Split out hash checking progress reporting Date: Fri, 8 Mar 2024 18:34:32 +0000 Message-ID: <20240308183440.4263-14-jon.turney@dronecode.org.uk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240308183440.4263-1-jon.turney@dronecode.org.uk> References: <20240308183440.4263-1-jon.turney@dronecode.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --- Feedback.h | 4 ++++ Makefile.am | 2 ++ choose.cc | 4 +++- cli/CliFeedback.h | 5 +++++ cli/CliHashCheckFeedback.cc | 30 ++++++++++++++++++++++++++++++ download.cc | 24 ++++++++++++------------ download.h | 6 +++--- gui/GuiFeedback.h | 5 +++++ gui/GuiHashCheckFeedback.cc | 34 ++++++++++++++++++++++++++++++++++ install.cc | 4 +++- package_db.cc | 6 +++--- package_db.h | 3 ++- package_meta.cc | 10 +++++----- package_meta.h | 5 +++-- package_source.cc | 33 ++++++++++----------------------- package_source.h | 8 +++++--- 16 files changed, 129 insertions(+), 54 deletions(-) create mode 100644 cli/CliHashCheckFeedback.cc create mode 100644 gui/GuiHashCheckFeedback.cc diff --git a/Feedback.h b/Feedback.h index 8f603a6..4db7c4a 100644 --- a/Feedback.h +++ b/Feedback.h @@ -47,6 +47,10 @@ public: virtual void fetch_finish (int total_bytes) = 0; virtual void fetch_fatal (const char *filename, const char *err) = 0; + // hash checking + virtual void hash_init (const char *hashalg, const std::string &url) = 0; + virtual void hash_progress (int bytes, int total_bytes) = 0; + // virtual HWND owner () = 0; }; diff --git a/Makefile.am b/Makefile.am index f257e3a..def20a4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -67,6 +67,7 @@ inilint_SOURCES = \ filemanip.h \ cli/CliParseFeedback.cc \ cli/CliGetUrlFeedback.cc \ + cli/CliHashCheckFeedback.cc \ cli/CliFeedback.h \ LogSingleton.cc \ LogSingleton.h \ @@ -186,6 +187,7 @@ endif gui/GuiGetNetAuth.h \ gui/GuiGetUrlFeedback.cc \ gui/GuiFeedback.h \ + gui/GuiHashCheckFeedback.cc \ ini.cc \ ini.h \ IniDBBuilder.h \ diff --git a/choose.cc b/choose.cc index 8deab87..451b390 100644 --- a/choose.cc +++ b/choose.cc @@ -50,6 +50,7 @@ #include "package_meta.h" #include "threebar.h" +#include "gui/GuiFeedback.h" #include "Generic.h" #include "ControlAdjuster.h" #include "prereq.h" @@ -317,9 +318,10 @@ void ChooserPage::OnActivate() { SetBusy(); + GuiFeedback feedback(GetHWND()); packagedb db; - db.prep(); + db.prep(feedback); if (!activated) { diff --git a/cli/CliFeedback.h b/cli/CliFeedback.h index 3bcc23c..cb59650 100644 --- a/cli/CliFeedback.h +++ b/cli/CliFeedback.h @@ -48,6 +48,11 @@ private: unsigned int last_tics; unsigned int start_tics; + // hash checking +public: + void hash_init (const char *hashalg, const std::string &url); + void hash_progress (int bytes, int total_bytes); + // owner public: HWND owner () { return NULL; } diff --git a/cli/CliHashCheckFeedback.cc b/cli/CliHashCheckFeedback.cc new file mode 100644 index 0000000..f5df9fc --- /dev/null +++ b/cli/CliHashCheckFeedback.cc @@ -0,0 +1,30 @@ +/* + * + * 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. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + */ + +#include "cli/CliFeedback.h" +#include "resource.h" +#include "String++.h" +#include + +void +CliFeedback::hash_init(const char *hashalg, const std::string &shortname) +{ + std::wstring fmt = LoadStringW(IDS_PROGRESS_CHECKING_HASH); + std::wstring s = format(fmt, hashalg, shortname.c_str()); + std::cout << wstring_to_string(s) << std::endl; +} + +void +CliFeedback::hash_progress(int bytes, int total_bytes) +{ + std::cout << bytes << "/" << total_bytes << "\r"; +} diff --git a/download.cc b/download.cc index 02fd484..fbe36e5 100644 --- a/download.cc +++ b/download.cc @@ -52,14 +52,14 @@ extern ThreeBarProgressPage Progress; // user chooses to delete the file; otherwise throw an exception. static bool validateCachedPackage (const std::string& fullname, packagesource & pkgsource, - HWND owner, bool check_hash, bool check_size) + Feedback &feedback, bool check_hash, bool check_size) { try { if (check_size) pkgsource.check_size_and_cache (fullname); if (check_hash) - pkgsource.check_hash (); + pkgsource.check_hash (feedback); return true; } catch (Exception *e) @@ -69,7 +69,7 @@ validateCachedPackage (const std::string& fullname, packagesource & pkgsource, if (strncmp (filename, "file://", 7) == 0) filename += 7; if (e->errNo() == APPERR_CORRUPT_PACKAGE - && yesno (owner, IDS_QUERY_CORRUPT, filename) == IDYES) + && yesno (feedback.owner(), IDS_QUERY_CORRUPT, filename) == IDYES) remove (filename); else throw e; @@ -80,8 +80,8 @@ validateCachedPackage (const std::string& fullname, packagesource & pkgsource, /* 0 if not cached; may throw exception if validation fails. */ int -check_for_cached (packagesource & pkgsource, HWND owner, bool mirror_mode, - bool check_hash) +check_for_cached (packagesource & pkgsource, Feedback &feedback, + bool mirror_mode, bool check_hash) { /* If the packagesource doesn't have a filename, it can't possibly be in the cache */ @@ -105,7 +105,7 @@ check_for_cached (packagesource & pkgsource, HWND owner, bool mirror_mode, // Already found one, which we can assume to have the right size. if (pkgsource.Cached()) { - if (validateCachedPackage (pkgsource.Cached(), pkgsource, owner, + if (validateCachedPackage (pkgsource.Cached(), pkgsource, feedback, check_hash, false)) return 1; // If we get here, pkgsource.Cached() was corrupt and deleted. @@ -117,7 +117,7 @@ check_for_cached (packagesource & pkgsource, HWND owner, bool mirror_mode, */ if (io_stream::exists (fullname)) { - if (validateCachedPackage (fullname, pkgsource, owner, check_hash, true)) + if (validateCachedPackage (fullname, pkgsource, feedback, check_hash, true)) return 1; // If we get here, fullname was corrupt and deleted, but it // might have been cached. @@ -134,7 +134,7 @@ check_for_cached (packagesource & pkgsource, HWND owner, bool mirror_mode, pkgsource.Canonical (); if (io_stream::exists(fullname)) { - if (validateCachedPackage (fullname, pkgsource, owner, check_hash, + if (validateCachedPackage (fullname, pkgsource, feedback, check_hash, true)) return 1; // If we get here, fullname was corrupt and deleted, but it @@ -151,7 +151,7 @@ download_one (packagesource & pkgsource, Feedback &feedback) { try { - if (check_for_cached (pkgsource, feedback.owner())) + if (check_for_cached (pkgsource, feedback)) return 0; } catch (Exception * e) @@ -190,7 +190,7 @@ download_one (packagesource & pkgsource, Feedback &feedback) remove (local.c_str()); rename ((local + ".tmp").c_str(), local.c_str()); pkgsource.check_size_and_cache ("file://" + local); - pkgsource.check_hash (); + pkgsource.check_hash (feedback); Log (LOG_PLAIN) << "Downloaded " << local << endLog; success = 1; // FIXME: move the downloaded file to the @@ -277,6 +277,7 @@ do_download_thread (HINSTANCE h, HWND owner) int errors = 0; download_failures.clear (); + GuiFeedback feedback(owner); Progress.SetText1 (IDS_PROGRESS_CHECKING); Progress.SetText2 (""); Progress.SetText3 (""); @@ -294,7 +295,7 @@ do_download_thread (HINSTANCE h, HWND owner) try { - if (!check_for_cached (*version.source(), owner)) + if (!check_for_cached (*version.source(), feedback)) total_download_bytes += version.source()->size; } catch (Exception * e) @@ -308,7 +309,6 @@ do_download_thread (HINSTANCE h, HWND owner) Progress.SetBar2(std::distance(t.begin(), i) + 1, t.size()); } - GuiFeedback feedback(owner); feedback.fetch_set_total_length(total_download_bytes); /* and do the download. FIXME: This here we assign a new name for the cached version diff --git a/download.h b/download.h index 9f4cb8e..3f65153 100644 --- a/download.h +++ b/download.h @@ -16,10 +16,10 @@ #ifndef SETUP_DOWNLOAD_H #define SETUP_DOWNLOAD_H -#include "win32.h" +#include "Feedback.h" class packagesource; -int check_for_cached (packagesource & pkgsource, HWND owner, - bool mirror_mode = false, bool check_hash = true); +int check_for_cached (packagesource & pkgsource, Feedback &feedback, + bool mirror_mode = false, bool check_hash = true); #endif /* SETUP_DOWNLOAD_H */ diff --git a/gui/GuiFeedback.h b/gui/GuiFeedback.h index 1dcd42f..7ac0c80 100644 --- a/gui/GuiFeedback.h +++ b/gui/GuiFeedback.h @@ -55,6 +55,11 @@ private: long long int total_download_bytes_sofar = 0; DWORD start_tics; + // hash checking +public: + void hash_init (const char *hashalg, const std::string &url); + void hash_progress (int bytes, int total_bytes); + public: // owner HWND owner () { return owner_window; } diff --git a/gui/GuiHashCheckFeedback.cc b/gui/GuiHashCheckFeedback.cc new file mode 100644 index 0000000..a0b4c57 --- /dev/null +++ b/gui/GuiHashCheckFeedback.cc @@ -0,0 +1,34 @@ +/* + * + * 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. + * + * A copy of the GNU General Public License can be found at + * http://www.gnu.org/ + * + */ + +#include "gui/GuiFeedback.h" +#include "resource.h" +#include "threebar.h" +#include "String++.h" + +extern ThreeBarProgressPage Progress; + +void +GuiFeedback::hash_init(const char *hashalg, const std::string &shortname) +{ + std::wstring fmt = LoadStringW(IDS_PROGRESS_CHECKING_HASH); + std::wstring s = format(fmt, hashalg, shortname.c_str()); + Progress.SetText1(s.c_str()); + Progress.SetText4(IDS_PROGRESS_PROGRESS); + Progress.SetBar1(0); +} + +void +GuiFeedback::hash_progress(int bytes, int total_bytes) +{ + Progress.SetBar1(bytes, total_bytes); +} diff --git a/install.cc b/install.cc index 001529b..578ff7f 100644 --- a/install.cc +++ b/install.cc @@ -62,6 +62,7 @@ #include "threebar.h" #include "Exception.h" #include "processlist.h" +#include "gui/GuiFeedback.h" extern ThreeBarProgressPage Progress; @@ -805,6 +806,7 @@ static void do_install_thread (HINSTANCE h, HWND owner) { int i; + GuiFeedback feedback(owner); num_installs = 0, num_uninstalls = 0; rebootneeded = false; @@ -870,7 +872,7 @@ do_install_thread (HINSTANCE h, HWND owner) { try { - (*version.source ()).check_hash (); + (*version.source ()).check_hash (feedback); } catch (Exception *e) { diff --git a/package_db.cc b/package_db.cc index 26ecc3c..244b6bb 100644 --- a/package_db.cc +++ b/package_db.cc @@ -752,7 +752,7 @@ packagedb::fixup_source_package_ids() } void -packagedb::prep() +packagedb::prep(Feedback &feedback) { /* make packagedb ready for use for chooser */ if (prepped) @@ -767,8 +767,8 @@ packagedb::prep() /* XXX: this needs to be broken out somewhere where it can do progress reporting, as it can take a long time... */ - if (source == IDC_SOURCE_DOWNLOAD || source ==IDC_SOURCE_LOCALDIR) - packagemeta::ScanDownloadedFiles (MirrorOption); + if (source == IDC_SOURCE_DOWNLOAD || source == IDC_SOURCE_LOCALDIR) + packagemeta::ScanDownloadedFiles (MirrorOption, feedback); setExistence (); fillMissingCategory (); diff --git a/package_db.h b/package_db.h index 3886bf2..c3c2b05 100644 --- a/package_db.h +++ b/package_db.h @@ -23,6 +23,7 @@ class packagemeta; class io_stream; class PackageSpecification; +class Feedback; typedef enum { PackageDB_Install, @@ -67,7 +68,7 @@ public: void init(); /* 0 on success */ int flush (); - void prep(); + void prep(Feedback &); /* Set the database to a "no changes requested" state. */ void noChanges (); diff --git a/package_meta.cc b/package_meta.cc index 3daa970..0c5e2f5 100644 --- a/package_meta.cc +++ b/package_meta.cc @@ -833,7 +833,7 @@ packagemeta::logSelectionStatus() const /* scan for local copies of package */ bool -packagemeta::scan (const packageversion &pkg, bool mirror_mode) +packagemeta::scan (const packageversion &pkg, bool mirror_mode, Feedback &feedback) { /* empty version */ if (!pkg) @@ -841,7 +841,7 @@ packagemeta::scan (const packageversion &pkg, bool mirror_mode) try { - if (!check_for_cached (*(pkg.source ()), NULL, mirror_mode, false) + if (!check_for_cached (*(pkg.source ()), feedback, mirror_mode, false) && ::source == IDC_SOURCE_LOCALDIR) return false; } @@ -859,7 +859,7 @@ packagemeta::scan (const packageversion &pkg, bool mirror_mode) } void -packagemeta::ScanDownloadedFiles (bool mirror_mode) +packagemeta::ScanDownloadedFiles (bool mirror_mode, Feedback &feedback) { /* Look at every known package, in all the known mirror dirs, * and fill in the Cached attribute if it exists. @@ -877,10 +877,10 @@ packagemeta::ScanDownloadedFiles (bool mirror_mode) && (*i != pkg.installed || pkg.installed == pkg.curr || pkg.installed == pkg.exp); - bool accessible = scan (*i, lazy_scan); + bool accessible = scan (*i, lazy_scan, feedback); packageversion foo = *i; packageversion pkgsrcver = foo.sourcePackage (); - bool src_accessible = scan (pkgsrcver, lazy_scan); + bool src_accessible = scan (pkgsrcver, lazy_scan, feedback); /* For local installs, if there is no src and no bin, the version * is unavailable diff --git a/package_meta.h b/package_meta.h index fee385b..896d848 100644 --- a/package_meta.h +++ b/package_meta.h @@ -19,6 +19,7 @@ class SolvableVersion; typedef SolvableVersion packageversion; class packagemeta; +class Feedback; #include #include @@ -34,7 +35,7 @@ typedef std::pair > Category; class packagemeta { public: - static void ScanDownloadedFiles (bool); + static void ScanDownloadedFiles (bool, Feedback&); packagemeta (packagemeta const &); packagemeta (const std::string& pkgname) : name (pkgname), user_picked (false), @@ -162,7 +163,7 @@ protected: private: std::string trustLabel(packageversion const &) const; std::vector