2 * Copyright 2013-2014, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
8 #ifndef COMMIT_TRANSACTION_HANDLER_H
9 #define COMMIT_TRANSACTION_HANDLER_H
15 #include <Directory.h>
17 #include "FSTransaction.h"
22 typedef std::set
<std::string
> StringSet
;
25 namespace BPackageKit
{
26 class BCommitTransactionResult
;
29 using BPackageKit::BCommitTransactionResult
;
32 class CommitTransactionHandler
{
34 CommitTransactionHandler(Volume
* volume
,
35 PackageFileManager
* packageFileManager
,
36 BCommitTransactionResult
& result
);
37 ~CommitTransactionHandler();
39 void Init(VolumeState
* volumeState
,
40 bool isActiveVolumeState
,
41 const PackageSet
& packagesAlreadyAdded
,
42 const PackageSet
& packagesAlreadyRemoved
);
44 void HandleRequest(BMessage
* request
);
46 const BActivationTransaction
& transaction
);
48 // uses packagesAlreadyAdded and
49 // packagesAlreadyRemoved from Init()
53 const BString
& OldStateDirectoryName() const
54 { return fOldStateDirectoryName
; }
56 Package
* CurrentPackage() const
57 { return fCurrentPackage
; }
59 VolumeState
* DetachVolumeState();
60 bool IsActiveVolumeState() const
61 { return fVolumeStateIsActive
; }
64 typedef BObjectList
<Package
> PackageList
;
65 typedef FSUtils::RelativePath RelativePath
;
67 struct TransactionIssueBuilder
;
70 void _GetPackagesToDeactivate(
71 const BActivationTransaction
& transaction
);
72 void _ReadPackagesToActivate(
73 const BActivationTransaction
& transaction
);
75 void _CreateOldStateDirectory();
76 void _RemovePackagesToDeactivate();
77 void _AddPackagesToActivate();
79 void _PreparePackageToActivate(Package
* package
);
80 void _AddGroup(Package
* package
,
81 const BString
& groupName
);
82 void _AddUser(Package
* package
, const BUser
& user
);
83 void _AddGlobalWritableFiles(Package
* package
);
84 void _AddGlobalWritableFile(Package
* package
,
85 const BGlobalWritableFileInfo
& file
,
86 const BDirectory
& rootDirectory
,
87 const BDirectory
& extractedFilesDirectory
);
88 void _AddGlobalWritableFileRecurse(Package
* package
,
89 const BDirectory
& sourceDirectory
,
90 FSUtils::Path
& relativeSourcePath
,
91 const BDirectory
& targetDirectory
,
92 const char* targetName
,
93 BWritableFileUpdateType updateType
);
95 void _RevertAddPackagesToActivate();
96 void _RevertRemovePackagesToDeactivate();
97 void _RevertUserGroupChanges();
99 void _RunPostInstallScripts();
100 void _RunPostInstallScript(Package
* package
,
101 const BString
& script
);
103 void _QueuePostInstallScripts();
105 void _ExtractPackageContent(Package
* package
,
106 const BStringList
& contentPaths
,
107 BDirectory
& targetDirectory
,
108 BDirectory
& _extractedFilesDirectory
);
110 status_t
_OpenPackagesSubDirectory(
111 const RelativePath
& path
, bool create
,
112 BDirectory
& _directory
);
113 status_t
_OpenPackagesFile(
114 const RelativePath
& subDirectoryPath
,
115 const char* fileName
, uint32 openMode
,
116 BFile
& _file
, BEntry
* _entry
= NULL
);
118 void _WriteActivationFile(
119 const RelativePath
& directoryPath
,
120 const char* fileName
,
121 const PackageSet
& toActivate
,
122 const PackageSet
& toDeactivate
,
124 void _CreateActivationFileContent(
125 const PackageSet
& toActivate
,
126 const PackageSet
& toDeactivate
,
128 status_t
_WriteTextFile(
129 const RelativePath
& directoryPath
,
130 const char* fileName
,
131 const BString
& content
, BEntry
& _entry
);
132 void _ChangePackageActivation(
133 const PackageSet
& packagesToActivate
,
134 const PackageSet
& packagesToDeactivate
);
136 void _ChangePackageActivationIOCtl(
137 const PackageSet
& packagesToActivate
,
138 const PackageSet
& packagesToDeactivate
);
140 void _FillInActivationChangeItem(
141 PackageFSActivationChangeItem
* item
,
142 PackageFSActivationChangeType type
,
143 Package
* package
, char*& nameBuffer
);
145 bool _IsSystemPackage(Package
* package
);
148 const TransactionIssueBuilder
& builder
);
150 static BString
_GetPath(const FSUtils::Entry
& entry
,
151 const BString
& fallback
);
153 static void _TagPackageEntriesRecursively(
154 BDirectory
& directory
, const BString
& value
,
155 bool nonDirectoriesOnly
);
159 PackageFileManager
* fPackageFileManager
;
160 VolumeState
* fVolumeState
;
161 bool fVolumeStateIsActive
;
162 PackageList fPackagesToActivate
;
163 PackageSet fPackagesToDeactivate
;
164 PackageSet fAddedPackages
;
165 PackageSet fRemovedPackages
;
166 PackageSet fPackagesAlreadyAdded
;
167 PackageSet fPackagesAlreadyRemoved
;
168 BDirectory fOldStateDirectory
;
169 node_ref fOldStateDirectoryRef
;
170 BString fOldStateDirectoryName
;
171 node_ref fTransactionDirectoryRef
;
172 BDirectory fWritableFilesDirectory
;
173 StringSet fAddedGroups
;
174 StringSet fAddedUsers
;
175 FSTransaction fFSTransaction
;
176 BCommitTransactionResult
& fResult
;
177 Package
* fCurrentPackage
;
181 #endif // COMMIT_TRANSACTION_HANDLER_H