Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rpmcallback inst start stop #5

Open
wants to merge 2 commits into
base: transaction-item
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions dnf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ def _run_transaction(self, cb):
# particular element failed and if not, decide that is the
# case.
failed = [el for el in self._ts if el.Failed()]
if len(failed) > 0:
if failed:
for te in failed:
te_nevra = dnf.util._te_nevra(te)
for tsi in self._transaction:
Expand All @@ -995,6 +995,7 @@ def _run_transaction(self, cb):

errstring = _('Errors occurred during transaction.')
logger.debug(errstring)
self.history.end(rpmdbv)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It results that the transaction will ends twice.

else:
login = dnf.util.get_effective_login()
msg = _("Failed to obtain the transaction lock "
Expand All @@ -1005,7 +1006,7 @@ def _run_transaction(self, cb):
else:
if self._record_history():
herrors = [ucd(x) for x in errors]
self.history.end(rpmdbv, 2, errors=herrors)
self.history.end(rpmdbv)
Copy link
Owner

@j-mracek j-mracek Jun 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe here is a problem. First I would like to move self.history.end(rpmdbv) few lines bellow. Also I believe that in this case it is normal that some elements were not done.

        else:
            logger.critical(_("Transaction couldn't start:"))
            for e in errors:
                logger.critical(ucd(e[0]))  # should this be 'to_unicoded'?

            if self._record_history() and not self._ts.isTsFlagSet(rpm.RPMTRANS_FLAG_TEST):
                self.history.end(rpmdbv)
            msg = _("Could not run transaction.")
            raise dnf.exceptions.Error(msg)


logger.critical(_("Transaction couldn't start:"))
for e in errors:
Expand Down Expand Up @@ -1068,7 +1069,7 @@ def display_banner(pkg, count):
count = display_banner(tsi.pkg, count)

rpmdbv = rpmdb_sack._rpmdb_version()
self.history.end(rpmdbv, 0)
self.history.end(rpmdbv)

timer()
self._trans_success = True
Expand Down
16 changes: 10 additions & 6 deletions dnf/db/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,22 +486,26 @@ def _log_errors(self, errors):
self.swdb.log_error(self._tid, error)
'''

# TODO: rename to end_transaction?
def end(self, end_rpmdb_version="", return_code=0, errors=None):
assert return_code or not errors
# TODO: fix return_code
return_code = not bool(return_code)
def end(self, end_rpmdb_version="", return_code=None, errors=None):
if not hasattr(self, '_tid'):
return # Failed at beg() time

if return_code is None:
# return_code/state auto-detection
return_code = libdnf.transaction.TransactionState_DONE
for tsi in self.rpm:
if tsi.state == libdnf.transaction.TransactionItemState_ERROR:
return_code = libdnf.transaction.TransactionState_ERROR
break

for file_descriptor, line in self._output:
self.swdb.addConsoleOutputLine(file_descriptor, line)
self._output = []

self.swdb.endTransaction(
int(time.time()),
str(end_rpmdb_version),
bool(return_code)
return_code,
)

# Closing and cleanup is done in the close() method.
Expand Down
23 changes: 18 additions & 5 deletions dnf/yum/rpmtrans.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ def callback(self, what, amount, total, key, client_data):
return self._instOpenFile(key)
elif what == rpm.RPMCALLBACK_INST_CLOSE_FILE:
self._instCloseFile(key)
elif what == rpm.RPMCALLBACK_INST_START:
self._inst_start(key)
elif what == rpm.RPMCALLBACK_INST_STOP:
self._inst_stop(key)
elif what == rpm.RPMCALLBACK_INST_PROGRESS:
self._instProgress(amount, total, key)
elif what == rpm.RPMCALLBACK_UNINST_START:
Expand Down Expand Up @@ -321,12 +325,17 @@ def _instOpenFile(self, key):
return self.fd.fileno()

def _instCloseFile(self, key):
transaction_list = self._extract_cbkey(key)
self.fd.close()
self.fd = None

def _inst_start(self, key):
pass

def _inst_stop(self, key):
if self.test or not self.trans_running:
return

transaction_list = self._extract_cbkey(key)
for tsi in transaction_list:
if tsi.state == libdnf.transaction.TransactionItemState_UNKNOWN:
tsi.state = libdnf.transaction.TransactionItemState_DONE
Expand Down Expand Up @@ -376,6 +385,10 @@ def _unInstStop(self, key):

def _cpioError(self, key):
transaction_list = self._extract_cbkey(key)
for tsi in transaction_list:
if tsi.state == libdnf.transaction.TransactionItemState_UNKNOWN:
tsi.state = libdnf.transaction.TransactionItemState_ERROR
break
msg = "Error in cpio payload of rpm package %s" % transaction_list[0].pkg
for display in self.displays:
display.error(msg)
Expand All @@ -386,11 +399,11 @@ def _unpackError(self, key):
msg = "Error unpacking rpm package %s" % tsi.pkg
for display in self.displays:
display.error(msg)
for tsi1 in transaction_list:
if tsi1.state == libdnf.transaction.TransactionItemState_UNKNOWN:
tsi1.state = libdnf.transaction.TransactionItemState_ERROR

for tsi in transaction_list:
if tsi.state == libdnf.transaction.TransactionItemState_UNKNOWN:
tsi.state = libdnf.transaction.TransactionItemState_ERROR
return
tsi.state = libdnf.transaction.TransactionItemState_ERROR

def _scriptError(self, amount, total, key):
# "amount" carries the failed scriptlet tag,
Expand Down