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 class CommitTransactionHandler { 26 public: 27 CommitTransactionHandler(Volume* volume, 28 VolumeState* volumeState, 29 const PackageSet& packagesAlreadyAdded, 30 const PackageSet& packagesAlreadyRemoved); 31 ~CommitTransactionHandler(); 32 33 void HandleRequest(BMessage* request, 34 BMessage* reply); 35 void HandleRequest( 36 const BActivationTransaction& transaction, 37 BMessage* reply); 38 void HandleRequest(const PackageSet& packagesAdded, 39 const PackageSet& packagesRemoved); 40 41 void Revert(); 42 43 const BString& OldStateDirectoryName() const 44 { return fOldStateDirectoryName; } 45 46 private: 47 typedef BObjectList<Package> PackageList; 48 typedef FSUtils::RelativePath RelativePath; 49 50 private: 51 void _GetPackagesToDeactivate( 52 const BActivationTransaction& transaction); 53 void _ReadPackagesToActivate( 54 const BActivationTransaction& transaction); 55 void _ApplyChanges(BMessage* reply); 56 void _CreateOldStateDirectory(BMessage* reply); 57 void _RemovePackagesToDeactivate(); 58 void _AddPackagesToActivate(); 59 60 void _PreparePackageToActivate(Package* package); 61 void _AddGroup(Package* package, 62 const BString& groupName); 63 void _AddUser(Package* package, const BUser& user); 64 void _AddGlobalWritableFiles(Package* package); 65 void _AddGlobalWritableFile(Package* package, 66 const BGlobalWritableFileInfo& file, 67 const BDirectory& rootDirectory, 68 const BDirectory& extractedFilesDirectory); 69 void _AddGlobalWritableFileRecurse(Package* package, 70 const BDirectory& sourceDirectory, 71 FSUtils::Path& relativeSourcePath, 72 const BDirectory& targetDirectory, 73 const char* targetName, 74 BWritableFileUpdateType updateType); 75 76 void _RevertAddPackagesToActivate(); 77 void _RevertRemovePackagesToDeactivate(); 78 void _RevertUserGroupChanges(); 79 80 void _RunPostInstallScripts(); 81 void _RunPostInstallScript(Package* package, 82 const BString& script); 83 84 void _ExtractPackageContent(Package* package, 85 const BStringList& contentPaths, 86 BDirectory& targetDirectory, 87 BDirectory& _extractedFilesDirectory); 88 89 status_t _OpenPackagesSubDirectory( 90 const RelativePath& path, bool create, 91 BDirectory& _directory); 92 status_t _OpenPackagesFile( 93 const RelativePath& subDirectoryPath, 94 const char* fileName, uint32 openMode, 95 BFile& _file, BEntry* _entry = NULL); 96 97 status_t _WriteActivationFile( 98 const RelativePath& directoryPath, 99 const char* fileName, 100 const PackageSet& toActivate, 101 const PackageSet& toDeactivate, 102 BEntry& _entry); 103 status_t _CreateActivationFileContent( 104 const PackageSet& toActivate, 105 const PackageSet& toDeactivate, 106 BString& _content); 107 status_t _WriteTextFile( 108 const RelativePath& directoryPath, 109 const char* fileName, 110 const BString& content, BEntry& _entry); 111 void _ChangePackageActivation( 112 const PackageSet& packagesToActivate, 113 const PackageSet& packagesToDeactivate); 114 // throws Exception 115 void _FillInActivationChangeItem( 116 PackageFSActivationChangeItem* item, 117 PackageFSActivationChangeType type, 118 Package* package, char*& nameBuffer); 119 120 static BString _GetPath(const FSUtils::Entry& entry, 121 const BString& fallback); 122 123 static status_t _TagPackageEntriesRecursively( 124 BDirectory& directory, const BString& value, 125 bool nonDirectoriesOnly); 126 127 private: 128 Volume* fVolume; 129 VolumeState* fVolumeState; 130 PackageList fPackagesToActivate; 131 PackageSet fPackagesToDeactivate; 132 PackageSet fAddedPackages; 133 PackageSet fRemovedPackages; 134 const PackageSet& fPackagesAlreadyAdded; 135 const PackageSet& fPackagesAlreadyRemoved; 136 BDirectory fOldStateDirectory; 137 BString fOldStateDirectoryName; 138 node_ref fTransactionDirectoryRef; 139 BDirectory fWritableFilesDirectory; 140 StringSet fAddedGroups; 141 StringSet fAddedUsers; 142 FSTransaction fFSTransaction; 143 }; 144 145 146 #endif // COMMIT_TRANSACTION_HANDLER_H 147