1 /* 2 * Copyright 2013-2014, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Ingo Weinhold <ingo_weinhold@gmx.de> 7 */ 8 #ifndef COMMIT_TRANSACTION_HANDLER_H 9 #define COMMIT_TRANSACTION_HANDLER_H 10 11 12 #include <set> 13 #include <string> 14 15 #include <Directory.h> 16 17 #include "FSTransaction.h" 18 #include "FSUtils.h" 19 #include "Volume.h" 20 21 22 typedef std::set<std::string> StringSet; 23 24 25 namespace BPackageKit { 26 class BCommitTransactionResult; 27 } 28 29 using BPackageKit::BCommitTransactionResult; 30 31 32 class CommitTransactionHandler { 33 public: 34 CommitTransactionHandler(Volume* volume, 35 PackageFileManager* packageFileManager, 36 BCommitTransactionResult& result); 37 ~CommitTransactionHandler(); 38 39 void Init(VolumeState* volumeState, 40 bool isActiveVolumeState, 41 const PackageSet& packagesAlreadyAdded, 42 const PackageSet& packagesAlreadyRemoved); 43 44 void HandleRequest(BMessage* request); 45 void HandleRequest( 46 const BActivationTransaction& transaction); 47 void HandleRequest(); 48 // uses packagesAlreadyAdded and 49 // packagesAlreadyRemoved from Init() 50 51 void Revert(); 52 OldStateDirectoryName()53 const BString& OldStateDirectoryName() const 54 { return fOldStateDirectoryName; } 55 CurrentPackage()56 Package* CurrentPackage() const 57 { return fCurrentPackage; } 58 59 VolumeState* DetachVolumeState(); IsActiveVolumeState()60 bool IsActiveVolumeState() const 61 { return fVolumeStateIsActive; } 62 63 private: 64 typedef BObjectList<Package> PackageList; 65 typedef FSUtils::RelativePath RelativePath; 66 67 struct TransactionIssueBuilder; 68 69 private: 70 void _GetPackagesToDeactivate( 71 const BActivationTransaction& transaction); 72 void _ReadPackagesToActivate( 73 const BActivationTransaction& transaction); 74 void _ApplyChanges(); 75 void _CreateOldStateDirectory(); 76 void _RemovePackagesToDeactivate(); 77 void _AddPackagesToActivate(); 78 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); 94 95 void _RevertAddPackagesToActivate(); 96 void _RevertRemovePackagesToDeactivate(); 97 void _RevertUserGroupChanges(); 98 99 void _RunPostInstallScripts(); 100 void _RunPreUninstallScripts(); 101 void _RunPostOrPreScript(Package* package, 102 const BString& script, 103 bool postNotPre); 104 105 void _QueuePostInstallScripts(); 106 107 void _ExtractPackageContent(Package* package, 108 const BStringList& contentPaths, 109 BDirectory& targetDirectory, 110 BDirectory& _extractedFilesDirectory); 111 112 status_t _OpenPackagesSubDirectory( 113 const RelativePath& path, bool create, 114 BDirectory& _directory); 115 status_t _OpenPackagesFile( 116 const RelativePath& subDirectoryPath, 117 const char* fileName, uint32 openMode, 118 BFile& _file, BEntry* _entry = NULL); 119 120 void _WriteActivationFile( 121 const RelativePath& directoryPath, 122 const char* fileName, 123 const PackageSet& toActivate, 124 const PackageSet& toDeactivate, 125 BEntry& _entry); 126 void _CreateActivationFileContent( 127 const PackageSet& toActivate, 128 const PackageSet& toDeactivate, 129 BString& _content); 130 status_t _WriteTextFile( 131 const RelativePath& directoryPath, 132 const char* fileName, 133 const BString& content, BEntry& _entry); 134 void _ChangePackageActivation( 135 const PackageSet& packagesToActivate, 136 const PackageSet& packagesToDeactivate); 137 // throws Exception 138 void _ChangePackageActivationIOCtl( 139 const PackageSet& packagesToActivate, 140 const PackageSet& packagesToDeactivate); 141 // throws Exception 142 void _PrepareFirstBootPackages(); 143 void _FillInActivationChangeItem( 144 PackageFSActivationChangeItem* item, 145 PackageFSActivationChangeType type, 146 Package* package, char*& nameBuffer); 147 148 bool _IsSystemPackage(Package* package); 149 150 void _AddIssue( 151 const TransactionIssueBuilder& builder); 152 153 static BString _GetPath(const FSUtils::Entry& entry, 154 const BString& fallback); 155 156 static void _TagPackageEntriesRecursively( 157 BDirectory& directory, const BString& value, 158 bool nonDirectoriesOnly); 159 160 static status_t _AssertEntriesAreEqual(const BEntry& entry, 161 const BDirectory* directory); 162 163 private: 164 Volume* fVolume; 165 PackageFileManager* fPackageFileManager; 166 VolumeState* fVolumeState; 167 bool fVolumeStateIsActive; 168 PackageList fPackagesToActivate; 169 PackageSet fPackagesToDeactivate; 170 PackageSet fAddedPackages; 171 PackageSet fRemovedPackages; 172 PackageSet fPackagesAlreadyAdded; 173 PackageSet fPackagesAlreadyRemoved; 174 BDirectory fOldStateDirectory; 175 node_ref fOldStateDirectoryRef; 176 BString fOldStateDirectoryName; 177 node_ref fTransactionDirectoryRef; 178 bool fFirstBootProcessing; 179 BDirectory fWritableFilesDirectory; 180 StringSet fAddedGroups; 181 StringSet fAddedUsers; 182 FSTransaction fFSTransaction; 183 BCommitTransactionResult& fResult; 184 Package* fCurrentPackage; 185 }; 186 187 188 #endif // COMMIT_TRANSACTION_HANDLER_H 189