Skip to content

Commit

Permalink
package daemon: Rework error and issue propagation to client
Browse files Browse the repository at this point in the history
* BDaemonClient: Move inner class BCommitTransactionResult to top level
  and make it public.
* BCommitTransactionResult:
  - Add a whole bunch of specific error code enum values. Such an error
    code is now the primary error, as opposed to before where we would
    mix status_t and enum value errors. There's a systemError property
    of type status_t which may provide additional information, though
    (depending on the primary error type).
  - Remove the errorMessage property. Due to mapping all errors to the
    specific error codes this is no longer necessary. Mixing such a
    message with another error description is also not very helpful when
    it comes to localization (still not supported, though).
  - Add several properties (paths, strings, error codes) that serve as
    arguments to the primary error and are used by FullErrorMessage().
  - Add issues property, a list of instances of new class
    BTransactionIssue. Those describe non-critical issues (e.g. failed
    update of a settings file) that occurred in the process of
    committing the transaction. Those issues should be presented to the
    user by the package management program.
* Exception: Adjust to transport the BCommitTransactionResult
  properties.
* CommitTransactionHandler, FsTransactions, Root, Volume: Adjust to
  BCommitTransactionResult/Exception changes.
* CommitTransactionHandler: Now requires a BCommitTransactionResult to
  which it adds the issues it encounters. The reply BMessage is no
  longer needed, though.
* Volume: Refactor common code from the three methods that use
  CommitTransactionHandler into new method _CommitTransaction.
  • Loading branch information
weinhold committed Jun 15, 2014
1 parent 6077cad commit 0de3219
Show file tree
Hide file tree
Showing 20 changed files with 1,577 additions and 616 deletions.
1 change: 1 addition & 0 deletions headers/build/os/package/CommitTransactionResult.h
@@ -0,0 +1 @@
#include <../os/package/CommitTransactionResult.h>
168 changes: 168 additions & 0 deletions headers/os/package/CommitTransactionResult.h
@@ -0,0 +1,168 @@
/*
* Copyright 2014, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _PACKAGE__COMMIT_TRANSACTION_RESULT_H_
#define _PACKAGE__COMMIT_TRANSACTION_RESULT_H_


#include <ObjectList.h>
#include <String.h>


class BMessage;


namespace BPackageKit {


enum BTransactionError {
B_TRANSACTION_OK = 0,
B_TRANSACTION_NO_MEMORY,
B_TRANSACTION_INTERNAL_ERROR,
B_TRANSACTION_INSTALLATION_LOCATION_BUSY,
B_TRANSACTION_CHANGE_COUNT_MISMATCH,
B_TRANSACTION_BAD_REQUEST,
B_TRANSACTION_NO_SUCH_PACKAGE,
B_TRANSACTION_PACKAGE_ALREADY_EXISTS,
B_TRANSACTION_FAILED_TO_GET_ENTRY_PATH,
B_TRANSACTION_FAILED_TO_OPEN_DIRECTORY,
B_TRANSACTION_FAILED_TO_CREATE_DIRECTORY,
B_TRANSACTION_FAILED_TO_REMOVE_DIRECTORY,
B_TRANSACTION_FAILED_TO_MOVE_DIRECTORY,
B_TRANSACTION_FAILED_TO_WRITE_ACTIVATION_FILE,
B_TRANSACTION_FAILED_TO_READ_PACKAGE_FILE,
B_TRANSACTION_FAILED_TO_EXTRACT_PACKAGE_FILE,
B_TRANSACTION_FAILED_TO_OPEN_FILE,
B_TRANSACTION_FAILED_TO_MOVE_FILE,
B_TRANSACTION_FAILED_TO_COPY_FILE,
B_TRANSACTION_FAILED_TO_WRITE_FILE_ATTRIBUTE,
B_TRANSACTION_FAILED_TO_ACCESS_ENTRY,
B_TRANSACTION_FAILED_TO_ADD_GROUP,
B_TRANSACTION_FAILED_TO_ADD_USER,
B_TRANSACTION_FAILED_TO_ADD_USER_TO_GROUP,
B_TRANSACTION_FAILED_TO_CHANGE_PACKAGE_ACTIVATION,
};


class BTransactionIssue {
public:
enum BType {
B_WRITABLE_FILE_TYPE_MISMATCH,
B_WRITABLE_FILE_NO_PACKAGE_ATTRIBUTE,
B_WRITABLE_FILE_OLD_ORIGINAL_FILE_MISSING,
B_WRITABLE_FILE_OLD_ORIGINAL_FILE_TYPE_MISMATCH,
B_WRITABLE_FILE_COMPARISON_FAILED,
B_WRITABLE_FILE_NOT_EQUAL,
B_WRITABLE_SYMLINK_COMPARISON_FAILED,
B_WRITABLE_SYMLINK_NOT_EQUAL,
B_POST_INSTALL_SCRIPT_NOT_FOUND,
B_STARTING_POST_INSTALL_SCRIPT_FAILED,
B_POST_INSTALL_SCRIPT_FAILED,
};

public:
BTransactionIssue();
BTransactionIssue(BType type,
const BString& packageName,
const BString& path1, const BString& path2,
status_t systemError, int exitCode);
BTransactionIssue(
const BTransactionIssue& other);
~BTransactionIssue();

BType Type() const;
const BString& PackageName() const;
const BString& Path1() const;
const BString& Path2() const;
status_t SystemError() const;
int ExitCode() const;

BString ToString() const;

status_t AddToMessage(BMessage& message) const;
status_t ExtractFromMessage(const BMessage& message);

BTransactionIssue& operator=(const BTransactionIssue& other);

private:
BType fType;
BString fPackageName;
BString fPath1;
BString fPath2;
status_t fSystemError;
int fExitCode;
};


class BCommitTransactionResult {
public:
BCommitTransactionResult();
BCommitTransactionResult(
BTransactionError error);
BCommitTransactionResult(
const BCommitTransactionResult& other);
~BCommitTransactionResult();

void Unset();

int32 CountIssues() const;
const BTransactionIssue* IssueAt(int32 index) const;
bool AddIssue(const BTransactionIssue& issue);

BTransactionError Error() const;
void SetError(BTransactionError error);

status_t SystemError() const;
void SetSystemError(status_t error);

const BString& ErrorPackage() const;
// may be empty, even on error
void SetErrorPackage(const BString& packageName);

BString FullErrorMessage() const;

const BString& Path1() const;
void SetPath1(const BString& path);

const BString& Path2() const;
void SetPath2(const BString& path);

const BString& Path3() const;
void SetPath3(const BString& path);

const BString& String1() const;
void SetString1(const BString& string);

const BString& String2() const;
void SetString2(const BString& string);

const BString& OldStateDirectory() const;
void SetOldStateDirectory(const BString& directory);

status_t AddToMessage(BMessage& message) const;
status_t ExtractFromMessage(const BMessage& message);

BCommitTransactionResult& operator=(
const BCommitTransactionResult& other);

private:
typedef BObjectList<BTransactionIssue> IssueList;

private:
BTransactionError fError;
status_t fSystemError;
BString fErrorPackage;
BString fPath1;
BString fPath2;
BString fString1;
BString fString2;
BString fOldStateDirectory;
IssueList fIssues;
};


} // namespace BPackageKit


#endif // _PACKAGE__COMMIT_TRANSACTION_RESULT_H_
39 changes: 1 addition & 38 deletions headers/private/package/DaemonClient.h
Expand Up @@ -22,6 +22,7 @@ class BDirectory;
namespace BPackageKit {


class BCommitTransactionResult;
class BInstallationLocationInfo;
class BPackageInfoSet;

Expand All @@ -33,9 +34,6 @@ class BActivationTransaction;


class BDaemonClient {
public:
class BCommitTransactionResult;

public:
BDaemonClient();
~BDaemonClient();
Expand Down Expand Up @@ -65,41 +63,6 @@ class BDaemonClient {
};


class BDaemonClient::BCommitTransactionResult {
public:
BCommitTransactionResult();
BCommitTransactionResult(int32 error,
const BString& errorMessage,
const BString& errorPackage,
const BString& oldStateDirectory);
~BCommitTransactionResult();

void SetTo(int32 error, const BString& errorMessage,
const BString& errorPackage,
const BString& oldStateDirectory);

status_t Error() const;
BDaemonError DaemonError() const;
// may be B_DAEMON_OK, even if Error() is
// != B_OK, then Error() is as specific as
// is known
const BString& ErrorMessage() const;
// may be empty, even on error
const BString& ErrorPackage() const;
// may be empty, even on error

BString FullErrorMessage() const;

const BString& OldStateDirectory() const;

private:
int32 fError;
BString fErrorMessage;
BString fErrorPackage;
BString fOldStateDirectory;
};


} // namespace BPrivate
} // namespace BPackageKit

Expand Down
47 changes: 30 additions & 17 deletions headers/private/package/DaemonDefs.h
Expand Up @@ -16,16 +16,6 @@ namespace BPrivate {
#define B_PACKAGE_DAEMON_APP_SIGNATURE "application/x-vnd.haiku-package_daemon"


enum BDaemonError {
B_DAEMON_OK = 0,
B_DAEMON_INSTALLATION_LOCATION_BUSY,
B_DAEMON_CHANGE_COUNT_MISMATCH,
B_DAEMON_BAD_REQUEST,
B_DAEMON_NO_SUCH_PACKAGE,
B_DAEMON_PACKAGE_ALREADY_EXISTS
};


// message codes for requests to and replies from the daemon
enum {
B_MESSAGE_GET_INSTALLATION_LOCATION_INFO = 'PKLI',
Expand Down Expand Up @@ -59,17 +49,40 @@ enum {
// transaction directory
B_MESSAGE_COMMIT_TRANSACTION_REPLY = 'PKTR'
// "error": int32
// regular error code or BDaemonError describing how committing
// the transaction went
// "error message": string
// [error case only] gives some additional information what went
// wrong; optional
// a BTransactionError describing how committing the transaction
// went
// "system error": int32
// a status_t for the operation that failed; B_ERROR, if n/a
// "error package": string
// [error case only] file name of the package causing the error,
// if any in particarly; optional
// "path1": string
// [error case only] first path specific to the error
// "path2": string
// [error case only] second path specific to the error
// "string1": string
// [error case only] first string specific to the error
// "string2": string
// [error case only] second string specific to the error
// "old state": string
// name of the directory (subdirectory of the administrative
// directory) containing the deactivated packages
// [success case only] name of the directory (subdirectory of the
// administrative directory) containing the deactivated packages
// "issues": message[]
// A list of non-critical issues that occurred while performing the
// package activation. On success the user should be notified about
// these. Each contains:
// "type": int32
// a BTransactionIssue::BType specifying the kind of issue
// "package": string
// file name of the package which the issue is related to
// "path1": string
// first path specific to the issue
// "path2": string
// second path specific to the issue
// "system error": int32
// a status_t for the operation that failed; B_OK, if n/a
// "exit code": int32
// a exit code of the program that failed; 0, if n/a
};


Expand Down
6 changes: 2 additions & 4 deletions headers/private/package/manager/PackageManager.h
Expand Up @@ -234,8 +234,7 @@ class BPackageManager::InstallationInterface {
virtual status_t PrepareTransaction(Transaction& transaction)
= 0;
virtual status_t CommitTransaction(Transaction& transaction,
BDaemonClient::BCommitTransactionResult&
_result) = 0;
BCommitTransactionResult& _result) = 0;
};


Expand All @@ -250,8 +249,7 @@ class BPackageManager::ClientInstallationInterface

virtual status_t PrepareTransaction(Transaction& transaction);
virtual status_t CommitTransaction(Transaction& transaction,
BDaemonClient::BCommitTransactionResult&
_result);
BCommitTransactionResult& _result);

private:
BDaemonClient fDaemonClient;
Expand Down
1 change: 1 addition & 0 deletions src/build/libpackage/Jamfile
Expand Up @@ -97,6 +97,7 @@ BuildPlatformSharedLibrary libpackage_build.so
AddRepositoryRequest.cpp
Attributes.cpp
ChecksumAccessors.cpp
CommitTransactionResult.cpp
Context.cpp
DownloadFileRequest.cpp
DropRepositoryRequest.cpp
Expand Down

0 comments on commit 0de3219

Please sign in to comment.