BDaemonClient::CommitTransaction(): Align with documentation

The method is supposed to return B_OK as long as the _result object has
been initialized, even if committing the transaction failed. Fixes the
unhelpful error messages of pkgman when committing the transaction
failed for some reason.
This commit is contained in:
Ingo Weinhold 2013-10-22 01:10:40 +02:00
parent 30794c2d79
commit df266f1c93
2 changed files with 38 additions and 55 deletions

View File

@ -60,10 +60,6 @@ private:
status_t _ExtractPackageInfoSet(const BMessage& message,
const char* field, BPackageInfoSet& _infos);
status_t _CommitTransaction(
const BActivationTransaction& transaction,
BCommitTransactionResult& _result);
private:
BMessenger fDaemonMessenger;
};

View File

@ -99,12 +99,45 @@ status_t
BDaemonClient::CommitTransaction(const BActivationTransaction& transaction,
BCommitTransactionResult& _result)
{
status_t error = _CommitTransaction(transaction, _result);
// B_OK just indicates that _result has been initialized.
if (error != B_OK)
_result.SetTo(error, BString(), BString(), BString());
if (transaction.InitCheck() != B_OK)
return B_BAD_VALUE;
return _result.Error();
status_t error = _InitMessenger();
if (error != B_OK)
return error;
// send the request
BMessage request(B_MESSAGE_COMMIT_TRANSACTION);
error = transaction.Archive(&request);
if (error != B_OK)
return error;
BMessage reply;
fDaemonMessenger.SendMessage(&request, &reply);
if (reply.what != B_MESSAGE_COMMIT_TRANSACTION_REPLY)
return B_ERROR;
// extract the result
int32 requestError;
error = reply.FindInt32("error", &requestError);
if (error != B_OK)
return error;
BString errorMessage;
BString errorPackage;
BString oldStateDirectory;
if (requestError == 0) {
error = reply.FindString("old state", &oldStateDirectory);
if (error != B_OK)
return error;
} else {
reply.FindString("error message", &errorMessage);
reply.FindString("error package", &errorPackage);
}
_result.SetTo(requestError, errorMessage, errorPackage, oldStateDirectory);
return B_OK;
// Even on error. B_OK just indicates that we have initialized _result.
}
@ -208,52 +241,6 @@ BDaemonClient::_ExtractPackageInfoSet(const BMessage& message,
}
status_t
BDaemonClient::_CommitTransaction(const BActivationTransaction& transaction,
BCommitTransactionResult& _result)
{
if (transaction.InitCheck() != B_OK)
return B_BAD_VALUE;
status_t error = _InitMessenger();
if (error != B_OK)
return error;
// send the request
BMessage request(B_MESSAGE_COMMIT_TRANSACTION);
error = transaction.Archive(&request);
if (error != B_OK)
return error;
BMessage reply;
fDaemonMessenger.SendMessage(&request, &reply);
if (reply.what != B_MESSAGE_COMMIT_TRANSACTION_REPLY)
return B_ERROR;
// extract the result
int32 requestError;
error = reply.FindInt32("error", &requestError);
if (error != B_OK)
return error;
BString errorMessage;
BString errorPackage;
BString oldStateDirectory;
if (requestError == 0) {
error = reply.FindString("old state", &oldStateDirectory);
if (error != B_OK)
return error;
} else {
reply.FindString("error message", &errorMessage);
reply.FindString("error package", &errorPackage);
}
_result.SetTo(requestError, errorMessage, errorPackage, oldStateDirectory);
return B_OK;
// Even on error. B_OK just indicates that we have initialized _result.
}
// #pragma mark - BCommitTransactionResult