|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Definition of CIntegrityServices |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @released |
|
23 @internalTechnology |
|
24 */ |
|
25 |
|
26 #ifndef __INTEGRITYSERVICES_H__ |
|
27 #define __INTEGRITYSERVICES_H__ |
|
28 |
|
29 #include <e32base.h> |
|
30 #include <f32file.h> |
|
31 #include <usif/sts/stsdefs.h> |
|
32 #include "integrityservicesevent.h" |
|
33 |
|
34 |
|
35 class RFs; |
|
36 |
|
37 namespace Usif |
|
38 { |
|
39 class CJournal; |
|
40 class CIntegrityTreeNode; |
|
41 /** |
|
42 * This class maintains the integrity of installed software by ensuring that |
|
43 * the device is always left in a consistent state. If a software modification |
|
44 * process (install, upgrade or uninstall) is interrupted then that process is |
|
45 * reverted, returning the device to its original state with no orphaned or |
|
46 * missing files. |
|
47 * |
|
48 * @released |
|
49 * @internalTechnology |
|
50 */ |
|
51 class CIntegrityServices : public CBase |
|
52 { |
|
53 public: |
|
54 |
|
55 /** |
|
56 * Constructs a new CIntegrityServices object specifying a path for |
|
57 * the journal files |
|
58 * |
|
59 * @code |
|
60 * |
|
61 * TTime currentTime; |
|
62 * currentTime.UniversalTime(); |
|
63 * _LIT(KIntegrityServicesPath, "\\private\\SID\\"); |
|
64 * iIntegrityServices = CIntegrityServices::NewL(currentTime.Int64(), |
|
65 * KIntegrityServicesPath); |
|
66 * |
|
67 * @endcode |
|
68 * |
|
69 * @param aTransactionID A unique ID provided by the client to |
|
70 * identify this transaction. It is suggested |
|
71 * that the client use the current time as the |
|
72 * unique ID. This value can then be shared |
|
73 * between different processes so that they use |
|
74 * the same journal. |
|
75 */ |
|
76 static CIntegrityServices* NewL(TStsTransactionId aTransactionID); |
|
77 |
|
78 /** |
|
79 * Constructs a new CIntegrityServices object specifying a path for |
|
80 * the journal files and puts it on the cleanup stack |
|
81 * @param aTransactionID A unique ID provided by the client to |
|
82 * identify this transaction. It is suggested |
|
83 * that the client use the current time as the |
|
84 * unique ID. This value can then be shared |
|
85 * between different processes so that they use |
|
86 * the same journal. |
|
87 */ |
|
88 static CIntegrityServices* NewLC(TStsTransactionId aTransactionID); |
|
89 |
|
90 ~CIntegrityServices(); |
|
91 |
|
92 /** |
|
93 * Notifies Integrity Services that a file or directory is being added |
|
94 * so that it can be removed if a rollback occurs. A record is created |
|
95 * in the journal file on the appropriate drive. |
|
96 * |
|
97 * @param aFileName - Name of file or directory including path |
|
98 */ |
|
99 void RegisterNewL(const TDesC& aFileName); |
|
100 |
|
101 /** |
|
102 * Instructs Integrity Services to create a new file. |
|
103 * It is removed if a rollback occurs. A record is created |
|
104 * in the journal file on the appropriate drive. |
|
105 * |
|
106 * @param aFileName - Name of file or directory including path |
|
107 * @param newFile - Reference of a file handle that is set to the newly created file |
|
108 * @param aFileMode - File creation mode of the new file (see TFileMode documentation |
|
109 * for the possible mode or combination of modes) |
|
110 */ |
|
111 void CreateNewL(const TDesC& aFileName, RFile &newFile, TUint aFileMode); |
|
112 |
|
113 /** |
|
114 * Removes the specified file or directory, first backing it up before |
|
115 * deleting it. A record is created in the journal file on the |
|
116 * appropriate drive. |
|
117 * |
|
118 * @param aFileName - Name of file or directory including path |
|
119 */ |
|
120 void RemoveL(const TDesC& aFileName); |
|
121 |
|
122 /** |
|
123 * Notifies Integrity Services that a file or directory is being added |
|
124 * that must later be removed. A record is created in the journal file |
|
125 * on the appropriate drive. |
|
126 * |
|
127 * @param aFileName - Name of file including path |
|
128 */ |
|
129 void RegisterTemporaryL(const TDesC& aFileName); |
|
130 |
|
131 /** |
|
132 * Instructs Integrity Services to create a new temporary file. |
|
133 * It is removed if a rollback occurs. A record is created |
|
134 * in the journal file on the appropriate drive. |
|
135 * |
|
136 * @param aFileName - Name of file including path |
|
137 * @param newFile - Reference of a file handle that is set to the newly created file |
|
138 * @param aFileMode - File creation mode of the new file (see TFileMode documentation |
|
139 * for the possible mode or combination of modes) |
|
140 */ |
|
141 void CreateTemporaryL(const TDesC& aFileName, RFile &newFile, TUint aFileMode); |
|
142 |
|
143 /** |
|
144 * Instructs Integrity Services to create a new file. |
|
145 * If the file already exists it's removed to a backup location first before the new file is created. |
|
146 * The newly created file is removed if a rollback occurs and the old one is restored. |
|
147 * A record is created in the journal file on the appropriate drive. |
|
148 * @param aFileName - Name of file or directory including path |
|
149 * @param newFile - Reference of a file handle that is set to the newly created file |
|
150 * @param aFileMode - File creation mode of the new file (see TFileMode documentation |
|
151 * for the possible mode or combination of modes) |
|
152 */ |
|
153 void OverwriteL(const TDesC& aFileName, RFile &newFile, TUint aFileMode); |
|
154 |
|
155 /** |
|
156 * Commits the current transaction by deleting backup, temporary and |
|
157 * journal files. The journal files are first refreshed so that |
|
158 * operations shared between processes and spread across multiple |
|
159 * drives are committed at the same time. If any journal file from this |
|
160 * transaction is not present or has already been rolledback the |
|
161 * commit will fail. |
|
162 */ |
|
163 void CommitL(); |
|
164 |
|
165 /** |
|
166 * Starts the recovery process for all drives. |
|
167 * Drive are rolled back independantly since removable media may be at |
|
168 * a different state to internal drives (which may have already been |
|
169 * rolled back). |
|
170 * |
|
171 * @param aRecordAllRollbackEvents- This parameter specifies whether we should record events during the rollback. |
|
172 * This allows continuing the rollback in case it has been interrupted. In most cases, this flag should be "on", however |
|
173 * if we failed a previous roll back due to low space or low memory, it can prevent any roll back due to lack of resources for recording |
|
174 * the rollback events. In these cases, it should be set to "off". |
|
175 * |
|
176 */ |
|
177 void RollBackL(TBool aRecordAllRollbackEvents = ETrue); |
|
178 |
|
179 /** |
|
180 * Returns the TransactionID |
|
181 * |
|
182 * @return a TStsTransactionId representing the transaction |
|
183 */ |
|
184 inline TStsTransactionId TransactionId() const; |
|
185 |
|
186 /** |
|
187 * Scans through the transaction path and returns a list if transaction ids that have been found. |
|
188 * |
|
189 * @param idArray - an array of TStsTransactionId in which the found ids are returned to the caller |
|
190 */ |
|
191 static void GetListOfTransactionsL(RArray<TStsTransactionId>& aIdArray); |
|
192 |
|
193 /** |
|
194 * Roll back all transactions that it can find in the transaction path in the filesystem |
|
195 * Important note: The function tries the best effort to roll back all transactions found. |
|
196 * Failing to roll back one transaction doesn't influence the roll back of others, |
|
197 * however if any of the transactions fail to roll back properly the function finally |
|
198 * will leave with the latest error encountered. (After it has tried to roll back all!) |
|
199 */ |
|
200 static void RollbackAllL(); |
|
201 |
|
202 |
|
203 /** |
|
204 * Creates a backup file by copying the source to a defined backup name. This MUST be used for executables. |
|
205 * The source files will then be deleted by invoking RLoader::Delete |
|
206 * @param aSource the file to backup |
|
207 * @param aBackup the name of the backup file |
|
208 */ |
|
209 void CopyToBackupL(const TDesC& aSource, const TDesC& aBackup); |
|
210 |
|
211 /** |
|
212 * Failure types - indicate when to simulate power failure during |
|
213 * testing |
|
214 */ |
|
215 enum TFailType |
|
216 { |
|
217 EFailNone, |
|
218 EFailAddingNewFile, |
|
219 EFailRemovingFile, |
|
220 EFailAddingTempFile, |
|
221 EFailRestoringFile, |
|
222 EFailDeletingFile, |
|
223 EFailInstallComplete, |
|
224 EFailNewFilesRemoved, |
|
225 EFailOldFilesRestored, |
|
226 EFailTempFilesRemoved, |
|
227 EFailBackupFilesRemoved, |
|
228 }; |
|
229 |
|
230 /** |
|
231 * Failure position - indicate when to simulate power failure during |
|
232 * testing |
|
233 */ |
|
234 enum TFailPosition |
|
235 { |
|
236 EBeforeJournal, |
|
237 EAfterJournal, |
|
238 EBeforeAction, |
|
239 EAfterAction |
|
240 }; |
|
241 |
|
242 private: |
|
243 /** |
|
244 * Constructor for CIntegrityServices |
|
245 * |
|
246 * @param aTransactionID A unique ID provided by the client to |
|
247 * identify this transaction. It is suggested |
|
248 * that the client use the current time as the |
|
249 * unique ID. This value can then be shared |
|
250 * between different processes so that they use |
|
251 * the same journal. |
|
252 */ |
|
253 CIntegrityServices(TStsTransactionId aTransactionID); |
|
254 |
|
255 /** |
|
256 * Second phase constructor for CIntegrityServices |
|
257 * |
|
258 */ |
|
259 void ConstructL(); |
|
260 |
|
261 /** |
|
262 * Removes a trailing slash from directory name, if needed. |
|
263 * |
|
264 * @param aFileName the filename to modify. If the filename does not represent a directory, it is not modified |
|
265 */ |
|
266 static void NormalizeDirectoryName(TDes& aFileName); |
|
267 |
|
268 private: |
|
269 |
|
270 /** |
|
271 * Pointer to the journal - uses log file(s) for persistant storage |
|
272 * A log file is created on each drive involved so that they can be |
|
273 * recovered independantly. |
|
274 */ |
|
275 CJournal* iJournal; |
|
276 |
|
277 /** |
|
278 * Provided by the client to identify this transaction. |
|
279 */ |
|
280 TStsTransactionId iTransactionID; |
|
281 |
|
282 /** |
|
283 * The supplied path in which to read and write journal files. |
|
284 */ |
|
285 TPath iJournalPath; |
|
286 |
|
287 /** |
|
288 The drive number for the system drive. |
|
289 */ |
|
290 TDriveNumber iSystemDrive; |
|
291 |
|
292 private: |
|
293 |
|
294 RFs iFs; |
|
295 |
|
296 RLoader iLoader; |
|
297 |
|
298 public: |
|
299 /** |
|
300 * Failure type (used only by test code) |
|
301 */ |
|
302 static TFailType iFailType; |
|
303 |
|
304 /** |
|
305 * Failure position (used only by test code) |
|
306 */ |
|
307 static TFailPosition iFailPosition; |
|
308 |
|
309 /** |
|
310 * Specify the name of the file to fail on (used only in test code) |
|
311 */ |
|
312 static TFileName iFailFileName; |
|
313 static TBool iIsFailureTestingEnabled; |
|
314 |
|
315 /** |
|
316 * Test utility function |
|
317 * |
|
318 * @param aFailType The operation on which to fail |
|
319 * @param aFailPosition The position at which to fail |
|
320 * @param aFailFileName The filename on which to fail |
|
321 */ |
|
322 static void SimulatePowerFailureL(TFailType aFailType, TFailPosition aPosition, const TDesC& aFailFileName); |
|
323 }; |
|
324 |
|
325 inline TStsTransactionId CIntegrityServices::TransactionId() const |
|
326 { |
|
327 return iTransactionID; |
|
328 } |
|
329 |
|
330 } //namespace |
|
331 #endif |