From 98cfa47c7437da0cf3fbb89aec9f38ea70d0a5de Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Thu, 19 Mar 2026 20:07:57 +0100 Subject: acquire-item: Fix up the error message on committing aborted transaction --- apt-pkg/acquire-item.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 21ed7b242..ca649a4b8 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -1334,7 +1334,7 @@ void pkgAcqMetaBase::CommitTransaction() switch (TransactionManager->State) { case TransactionStarted: break; - case TransactionAbort: _error->Fatal("Transaction %s was already committed and is now aborted", TransactionManager->Target.URI.c_str()); return; + case TransactionAbort: _error->Fatal("Transaction %s was already aborted and is now committed", TransactionManager->Target.URI.c_str()); return; case TransactionCommit: _error->Fatal("Transaction %s was already committed and is again committed", TransactionManager->Target.URI.c_str()); return; } TransactionManager->State = TransactionCommit; -- cgit v1.2.3-70-g09d2 From dcc690d7e08f6d54fc10ee372510875a41ec9a3b Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Thu, 19 Mar 2026 20:13:55 +0100 Subject: pkgAcqMetaClearSig: Abort transaction when pkgAcquire::Run has been cancelled Ongoing Run can be cancelled by returning false from ::Pulse(). In this case the items would still be called pkgAcquire::Item::Finished() as usual, causing pkgAcqMetaClearSig to commit the incomplete transaction anyway as at that point it's still Started and has no errors. Add a pkgAcquire::Item::Cancelled() method and use it in pkgAcqMetaClearSig to abort the transaction. Closes: #1078608 --- apt-pkg/acquire-item.cc | 10 ++++++++++ apt-pkg/acquire-item.h | 4 ++++ apt-pkg/acquire.cc | 4 ++++ 3 files changed, 18 insertions(+) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index ca649a4b8..458868bec 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -868,6 +868,10 @@ void pkgAcquire::Item::RemoveAlternativeSite(std::string const &AltUriStr)/*{{{* std::string pkgAcquire::Item::ShortDesc() const /*{{{*/ { return DescURI(); +} + /*}}}*/ +void pkgAcquire::Item::Cancelled() /*{{{*/ +{ } /*}}}*/ void pkgAcquire::Item::Finished() /*{{{*/ @@ -2006,6 +2010,12 @@ string pkgAcqMetaClearSig::Custom600Headers() const return Header; } /*}}}*/ +void pkgAcqMetaClearSig::Cancelled() /*{{{*/ +{ + if (TransactionManager->State == TransactionStarted) + TransactionManager->AbortTransaction(); +} + /*}}}*/ void pkgAcqMetaClearSig::Finished() /*{{{*/ { if(_config->FindB("Debug::Acquire::Transaction", false) == true) diff --git a/apt-pkg/acquire-item.h b/apt-pkg/acquire-item.h index 5861d48be..1182e415e 100644 --- a/apt-pkg/acquire-item.h +++ b/apt-pkg/acquire-item.h @@ -253,6 +253,9 @@ class APT_PUBLIC pkgAcquire::Item : public WeakPointable /*{{{*/ */ virtual std::string ShortDesc() const; + /** \brief Invoked by the worker when the download is cancelled before completion. */ + virtual void Cancelled(); + /** \brief Invoked by the worker when the download is completely done. */ virtual void Finished(); @@ -575,6 +578,7 @@ class APT_HIDDEN pkgAcqMetaClearSig final : public pkgAcqMetaIndex bool VerifyDone(std::string const &Message, pkgAcquire::MethodConfig const *Cnf) override; void Done(std::string const &Message, HashStringList const &Hashes, pkgAcquire::MethodConfig const *Cnf) override; + void Cancelled() override; void Finished() override; /** \brief Starts downloading the individual index files. diff --git a/apt-pkg/acquire.cc b/apt-pkg/acquire.cc index 95b6391cd..62d477f95 100644 --- a/apt-pkg/acquire.cc +++ b/apt-pkg/acquire.cc @@ -794,6 +794,10 @@ stop: for (Queue *I = Queues; I != 0; I = I->Next) I->Shutdown(false); + if (WasCancelled) + for (ItemIterator I = Items.begin(); I != Items.end(); ++I) + (*I)->Cancelled(); + // Shut down the items for (auto &Item : Items) Item->Finished(); -- cgit v1.2.3-70-g09d2 From 244bf4d107d7f17eb7a21b036717a161618387ae Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Thu, 19 Mar 2026 20:20:01 +0100 Subject: pkgAcqMetaBase: Commit InRelease after other transaction items If apt update is interrupted during transaction commit, the system may end up with updated InRelease that does not match the other list files, which can cause apt to believe that the lists are already up-to-date when they are in fact not. Closes: #1078608 --- apt-pkg/acquire-item.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'apt-pkg') diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc index 458868bec..b77bccc9d 100644 --- a/apt-pkg/acquire-item.cc +++ b/apt-pkg/acquire-item.cc @@ -1348,8 +1348,12 @@ void pkgAcqMetaBase::CommitTransaction() for (std::vector::iterator I = Transaction.begin(); I != Transaction.end(); ++I) { - (*I)->TransactionState(TransactionCommit); + if (*I != this) + (*I)->TransactionState(TransactionCommit); } + // commit ourselves last to not end up with fresh InRelease + // that doesn't match other files when killed mid-commit + TransactionState(TransactionCommit); Transaction.clear(); } /*}}}*/ -- cgit v1.2.3-70-g09d2