|
1 /* |
|
2 * Copyright (c) 2004-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 <e32ldr_private.h> |
|
32 |
|
33 #include "integrityservicesevent.h" |
|
34 |
|
35 |
|
36 |
|
37 namespace Swi |
|
38 { |
|
39 class CJournal; |
|
40 class CIntegrityTreeNode; |
|
41 |
|
42 /** |
|
43 * This class maintains the integrity of installed software by ensuring that |
|
44 * the device is always left in a consistent state. If a software modification |
|
45 * process (install, upgrade or uninstall) is interrupted then that process is |
|
46 * reverted, returning the device to its original state with no orphaned or |
|
47 * missing files. |
|
48 * |
|
49 * @released |
|
50 * @internalTechnology |
|
51 */ |
|
52 class CIntegrityServices : public CBase |
|
53 { |
|
54 public: |
|
55 |
|
56 /** |
|
57 * Constructs a new CIntegrityServices object specifying a path for |
|
58 * the journal files |
|
59 * |
|
60 * @code |
|
61 * |
|
62 * TTime currentTime; |
|
63 * currentTime.UniversalTime(); |
|
64 * _LIT(KIntegrityServicesPath, "\\private\\SID\\"); |
|
65 * iIntegrityServices = CIntegrityServices::NewL(currentTime.Int64(), |
|
66 * KIntegrityServicesPath); |
|
67 * |
|
68 * @endcode |
|
69 * |
|
70 * @param aTransactionID A unique ID provided by the client to |
|
71 * identify this transaction. It is suggested |
|
72 * that the client use the current time as the |
|
73 * unique ID. This value can then be shared |
|
74 * between different processes so that they use |
|
75 * the same journal. |
|
76 * @param aPath The path in which to read and write journal |
|
77 * files. eg "\\private\\SID\\" |
|
78 */ |
|
79 IMPORT_C static CIntegrityServices* NewL(TInt64 aTransactionID, const TDesC& aPath); |
|
80 |
|
81 /** |
|
82 * Constructs a new CIntegrityServices object specifying a path for |
|
83 * the journal files and puts it on the cleanup stack |
|
84 * |
|
85 * @code |
|
86 * |
|
87 * TTime currentTime; |
|
88 * currentTime.UniversalTime(); |
|
89 * _LIT(KIntegrityServicesPath, "\\private\\SID\\"); |
|
90 * iIntegrityServices = CIntegrityServices::NewL(currentTime.Int64(), |
|
91 * KIntegrityServicesPath); |
|
92 * |
|
93 * @endcode |
|
94 * |
|
95 * @param aTransactionID A unique ID provided by the client to |
|
96 * identify this transaction. It is suggested |
|
97 * that the client use the current time as the |
|
98 * unique ID. This value can then be shared |
|
99 * between different processes so that they use |
|
100 * the same journal. |
|
101 * @param aPath The path in which to read and write journal |
|
102 * files. eg "\\private\\SID\\" |
|
103 */ |
|
104 IMPORT_C static CIntegrityServices* NewLC(TInt64 aTransactionID, const TDesC& aPath); |
|
105 |
|
106 IMPORT_C virtual ~CIntegrityServices(); |
|
107 |
|
108 /** |
|
109 * Notifies Integrity Services that a file or directory is being added |
|
110 * so that it can be removed if a rollback occurs. A record is created |
|
111 * in the journal file on the appropriate drive. |
|
112 * |
|
113 * @param aFileName - Name of file or directory including path |
|
114 */ |
|
115 IMPORT_C void AddL(const TDesC& aFileName); |
|
116 |
|
117 /** |
|
118 * Removes the specified file or directory, first backing it up before |
|
119 * deleting it. A record is created in the journal file on the |
|
120 * appropriate drive. |
|
121 * |
|
122 * @param aFileName - Name of file or directory including path |
|
123 */ |
|
124 IMPORT_C void RemoveL(const TDesC& aFileName); |
|
125 |
|
126 /** |
|
127 * Notifies Integrity Services that a file or directory is being added |
|
128 * that must later be removed. A record is created in the journal file |
|
129 * on the appropriate drive. |
|
130 * |
|
131 * @param aFileName - Name of file or directory including path |
|
132 */ |
|
133 IMPORT_C void TemporaryL(const TDesC& aFileName); |
|
134 |
|
135 /** |
|
136 * Commits the current transaction by deleting backup, temporary and |
|
137 * journal files. The journal files are first refreshed so that |
|
138 * operations shared between processes and spread across multiple |
|
139 * drives are committed at the same time. If any journal file from this |
|
140 * transaction is not present or has already been rolledback the |
|
141 * commit will fail. |
|
142 */ |
|
143 IMPORT_C void CommitL(); |
|
144 |
|
145 /** |
|
146 * Starts the recovery process for all drives. |
|
147 * Drive are rolled back independantly since removable media may be at |
|
148 * a different state to internal drives (which may have already been |
|
149 * rolled back). |
|
150 * |
|
151 * @param aAllTransactions if ETrue all transactions in the current |
|
152 * path are rolled back otherwise only this |
|
153 * transaction. |
|
154 */ |
|
155 IMPORT_C void RollBackL(TBool aAllTransactions); |
|
156 |
|
157 /** |
|
158 * Returns the TransactionID |
|
159 * |
|
160 * @return a TInt64 representing the transaction |
|
161 */ |
|
162 inline TInt64 TransactionId() const; |
|
163 |
|
164 |
|
165 /** |
|
166 * Test if any journal files have started being rolled back. |
|
167 * |
|
168 * @return ETrue if any journal files have started being rolled back |
|
169 * or EFalse otherwise. |
|
170 */ |
|
171 inline TBool StartedJournalRollback() const; |
|
172 |
|
173 /** |
|
174 * Failure types - indicate when to simulate power failure during |
|
175 * testing |
|
176 */ |
|
177 enum TFailType |
|
178 { |
|
179 EFailNone, |
|
180 EFailAddingNewFile, |
|
181 EFailRemovingFile, |
|
182 EFailAddingTempFile, |
|
183 EFailRestoringFile, |
|
184 EFailDeletingFile, |
|
185 EFailInstallComplete, |
|
186 EFailNewFilesRemoved, |
|
187 EFailOldFilesRestored, |
|
188 EFailTempFilesRemoved, |
|
189 EFailBackupFilesRemoved, |
|
190 }; |
|
191 |
|
192 /** |
|
193 * Failure position - indicate when to simulate power failure during |
|
194 * testing |
|
195 */ |
|
196 enum TFailPosition |
|
197 { |
|
198 EBeforeJournal, |
|
199 EAfterJournal, |
|
200 EBeforeAction, |
|
201 EAfterAction |
|
202 }; |
|
203 |
|
204 protected: |
|
205 /** |
|
206 * Constructor for CIntegrityServices |
|
207 * |
|
208 * @param aTransactionID A unique ID provided by the client to |
|
209 * identify this transaction. It is suggested |
|
210 * that the client use the current time as the |
|
211 * unique ID. This value can then be shared |
|
212 * between different processes so that they use |
|
213 * the same journal. |
|
214 */ |
|
215 IMPORT_C CIntegrityServices(TInt64 aTransactionID); |
|
216 |
|
217 /** |
|
218 * Second phase constructor for CIntegrityServices |
|
219 * |
|
220 * @param aPath The path in which to read and write journal |
|
221 * files. eg "\\private\\SID\\" |
|
222 */ |
|
223 IMPORT_C void ConstructL(const TDesC& aPath); |
|
224 |
|
225 /** |
|
226 * Function only implemented in derived test class. |
|
227 * |
|
228 * @param aFailType The operation on which to fail |
|
229 * @param aFailPosition The position at which to fail |
|
230 * @param aFailFileName The filename on which to fail |
|
231 */ |
|
232 virtual void SimulatePowerFailureL(TFailType aFailType, TFailPosition aPosition, const TDesC& aFailFileName); |
|
233 |
|
234 private: |
|
235 |
|
236 /** |
|
237 * Recovers the specified journal by either rolling back a failed |
|
238 * installation or completing it if past the point of no return |
|
239 * (ie backup files deleted). Processes the journal file on each drive |
|
240 * used by this transaction one after the other. |
|
241 * |
|
242 * @param aJournal The journal to rollback |
|
243 * |
|
244 */ |
|
245 void RollBackJournalL(CJournal& aJournal); |
|
246 |
|
247 /** |
|
248 * Performs recovery of the journal for a particular drive. |
|
249 * |
|
250 * @param aJournal The journal to rollback |
|
251 * @param aDrive The drive to rollback |
|
252 */ |
|
253 void RollBackDriveL(CJournal& aJournal, TInt aDrive); |
|
254 |
|
255 /** |
|
256 * Restores backup files to their original location |
|
257 * |
|
258 * @param aJournal The journal for which files are to be restored |
|
259 */ |
|
260 void RestoreFilesL(CJournal& aJournal, TInt aDrive = -1); |
|
261 |
|
262 /** |
|
263 * Function deletes all files in the list but does NOT fail |
|
264 * if a file cannot be found |
|
265 * |
|
266 * @param aJournal The journal for which files are to be deleted |
|
267 * @param aEvent Files corresponding to this event are deleted. |
|
268 */ |
|
269 void DeleteFilesL(CJournal& aJournal, TIntegrityServicesEvent aEvent, TInt aDrive = -1); |
|
270 |
|
271 /** |
|
272 * Removes a trailing slash from directory name, if needed. |
|
273 * |
|
274 * @param aFileName the filename to modify. If the filename does not represent a directory, it is not modified |
|
275 */ |
|
276 static void NormalizeDirectoryName(TDes& aFileName); |
|
277 |
|
278 /** |
|
279 Creates a backup file by copying the source to a defined backup name. This MUST be used for executables. |
|
280 The source files will then be deleted by invoking RLoader::Delete |
|
281 @param aSource the file to backup |
|
282 @param aBackup the name of the backup file |
|
283 */ |
|
284 void CopyToBackupL(const TDesC& aSource, const TDesC& aBackup); |
|
285 |
|
286 private: |
|
287 |
|
288 /** |
|
289 * Pointer to the journal - uses log file(s) for persistant storage |
|
290 * A log file is created on each drive involved so that they can be |
|
291 * recovered independantly. |
|
292 */ |
|
293 CJournal* iJournal; |
|
294 |
|
295 /** |
|
296 * Provided by the client to identify this transaction. |
|
297 */ |
|
298 TInt64 iTransactionID; |
|
299 |
|
300 /** |
|
301 * The supplied path in which to read and write journal files. |
|
302 */ |
|
303 TPath iJournalPath; |
|
304 |
|
305 /** |
|
306 * True if rollback has been started on at least one journal file. |
|
307 */ |
|
308 TBool iStartedJournalRollback; |
|
309 |
|
310 /** |
|
311 The drive number for the system drive. |
|
312 */ |
|
313 TDriveNumber iSystemDrive; |
|
314 |
|
315 protected: |
|
316 |
|
317 RFs iFs; |
|
318 |
|
319 RLoader iLoader; |
|
320 |
|
321 /** |
|
322 * Failure type (used only by test code) |
|
323 */ |
|
324 TFailType iFailType; |
|
325 |
|
326 /** |
|
327 * Failure position (used only by test code) |
|
328 */ |
|
329 TFailPosition iFailPosition; |
|
330 |
|
331 /** |
|
332 * Specify the name of the file to fail on (used only in test code) |
|
333 */ |
|
334 TFileName iFailFileName; |
|
335 |
|
336 friend class CIntegrityTreeNode; |
|
337 }; |
|
338 |
|
339 inline TInt64 CIntegrityServices::TransactionId() const |
|
340 { |
|
341 return iTransactionID; |
|
342 } |
|
343 |
|
344 inline TBool CIntegrityServices::StartedJournalRollback() const |
|
345 { |
|
346 return iStartedJournalRollback; |
|
347 } |
|
348 |
|
349 } //namespace |
|
350 #endif |