|
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 CJournalFile |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @released |
|
23 @internalTechnology |
|
24 */ |
|
25 |
|
26 #ifndef __JOURNALFILE_H__ |
|
27 #define __JOURNALFILE_H__ |
|
28 |
|
29 #include <e32base.h> |
|
30 #include <s32file.h> |
|
31 |
|
32 #include "integrityservicesevent.h" |
|
33 #include "integritytree.h" |
|
34 |
|
35 namespace Usif |
|
36 { |
|
37 |
|
38 /** |
|
39 * The purpose of this class is to wrap a RFileWriteStream so that multiple |
|
40 * journal files can be held open by the client. This eliminates the need to |
|
41 * constantly open and close files. |
|
42 * |
|
43 * @released |
|
44 * @internalTechnology |
|
45 */ |
|
46 class CJournalFile : public CBase |
|
47 { |
|
48 public: |
|
49 |
|
50 /** |
|
51 * Constructs a new CJournalFile |
|
52 * |
|
53 * @param aFs reference to the supplied file system session |
|
54 * @param aLoader reference to the RLoader session |
|
55 * @param aFileName the filename of the journal |
|
56 */ |
|
57 static CJournalFile* NewL(RFs& aFs, RLoader& aLoader, const TDesC& aFileName, TInt aDrive); |
|
58 |
|
59 /** |
|
60 * Constructs a new CJournalFile an places it on the cleanup stack |
|
61 * |
|
62 * @param aFs reference to the supplied file system session |
|
63 * @param aLoader reference to the RLoader session |
|
64 * @param aFileName the filename of the journal |
|
65 */ |
|
66 static CJournalFile* NewLC(RFs& aFs, RLoader& aLoader, const TDesC& aFileName, TInt aDrive); |
|
67 |
|
68 virtual ~CJournalFile(); |
|
69 |
|
70 /** |
|
71 * Records an event in this journal file. |
|
72 * |
|
73 * @param aEvent the event to record |
|
74 * @param aEvent specifies whether the event should be serialized. If set to False, only the "in-memory" state of the journal is changed |
|
75 This parameter is used in possible low memory or low disk space conditions. |
|
76 */ |
|
77 void EventL(TIntegrityServicesEvent aEvent, TBool aSerializeEventToJournal = ETrue); |
|
78 |
|
79 /** |
|
80 * Notifies Integrity Services that a file or directory is being added |
|
81 * so that it can be removed if a rollback occurs. A record is created |
|
82 * in the journal file on the appropriate drive. |
|
83 * |
|
84 * @param aFileName - Name of file or directory including path |
|
85 */ |
|
86 void AddL(const TDesC& aFileName); |
|
87 |
|
88 /** |
|
89 * Checks if the file being removed has already been journalled for |
|
90 * adding in the same journal file. If it has been, nothing is |
|
91 * journalled and the backup file name is set to zero length. Otherwise |
|
92 * a record is journalled for the removal and the backup filename is |
|
93 * set to the appropriate next name to use. |
|
94 * |
|
95 * @param aFileName - Name of file or directory including path |
|
96 * @param aBackupFileName - the generated backup filename to return or |
|
97 * zero-length if the file doesn't need to |
|
98 * be backed up. |
|
99 */ |
|
100 void RemoveL(const TDesC& aFileName, TDes& aBackupFileName); |
|
101 |
|
102 /** |
|
103 * Notifies Integrity Services that a file or directory is being added |
|
104 * that must later be removed. A record is created in the journal file |
|
105 * on the appropriate drive. |
|
106 * |
|
107 * @param aFileName - Name of file or directory including path |
|
108 */ |
|
109 void TemporaryL(const TDesC& aFileName); |
|
110 |
|
111 /** |
|
112 * Performs an operation on the file tree structure |
|
113 * |
|
114 * @param aFunc A function to apply to all nodes |
|
115 * @param aTypeFilter The type of node to apply the function to |
|
116 * @param aFailType The type of failure to induce, used exclusively in testing. |
|
117 * |
|
118 */ |
|
119 |
|
120 void JournalOperationL(TTreeWalkFunctionL aFunc, TIntegrityServicesEvent aTypeFilter, |
|
121 CIntegrityServices::TFailType aFailType); |
|
122 |
|
123 /** |
|
124 * Returns the last event found in the journal, used to determine how far the |
|
125 * installation progressed |
|
126 * |
|
127 * @return TIntegrityServicesEvent representing the last event in the file |
|
128 */ |
|
129 TIntegrityServicesEvent LastEvent() const; |
|
130 |
|
131 /** |
|
132 * Checks that the filename is valid and complete |
|
133 * |
|
134 * @param aFs a reference to an open file system session |
|
135 * @param aFileName the filename to check |
|
136 * @return TInt representing the drive specified in this filename |
|
137 */ |
|
138 static TInt CheckFileNameL(RFs& aFs, const TDesC& aFileName); |
|
139 |
|
140 /** |
|
141 * Accessor method that tells us which drive this journal file is on |
|
142 */ |
|
143 |
|
144 TInt Drive(); |
|
145 |
|
146 /** |
|
147 * Closes any file handle held open by this object. The journal file object |
|
148 * must not be used again after this call. |
|
149 */ |
|
150 |
|
151 void Close(); |
|
152 |
|
153 private: |
|
154 /** |
|
155 * Constructor for CJournalFile |
|
156 * |
|
157 * @param aFs a reference to the supplied file system session |
|
158 * @param aLoader reference to the RLoader session |
|
159 */ |
|
160 CJournalFile(RFs& aFs, RLoader& aLoader, TInt aDrive); |
|
161 |
|
162 /** |
|
163 * Second phase constructor for CJournalFile |
|
164 * |
|
165 * @param aFileName the filename of the journal |
|
166 */ |
|
167 void ConstructL(const TDesC& aFileName); |
|
168 |
|
169 /** |
|
170 * Reads and verifies the journal file |
|
171 */ |
|
172 void ReadL(); |
|
173 |
|
174 /** |
|
175 * Reads and verifies a journal entry from the supplied stream |
|
176 * |
|
177 * @param aJournalStream the stream to read |
|
178 * @param aDrive used to verify files referred to are only from that drive |
|
179 */ |
|
180 void ReadEntryL(RFileReadStream& aJournalStream, TInt aDrive); |
|
181 |
|
182 /** |
|
183 * Prepares to write to the journal file by opening an RFileWriteStream |
|
184 */ |
|
185 void PrepareToWriteL(); |
|
186 |
|
187 /** |
|
188 * Generates the next backup filename for this journal file. |
|
189 */ |
|
190 void NextBackupFileNameL(TDes& aBackupFileName); |
|
191 |
|
192 /** |
|
193 * Reference to the supplied file system session |
|
194 */ |
|
195 RFs& iFs; |
|
196 |
|
197 /** |
|
198 * Reference to RLoader server session |
|
199 */ |
|
200 RLoader& iLoader; |
|
201 |
|
202 /** |
|
203 * The write stream for this journal |
|
204 */ |
|
205 RFileWriteStream iWriteStream; |
|
206 |
|
207 /** |
|
208 * The last journal event recorded in the journal |
|
209 */ |
|
210 TIntegrityServicesEvent iLastEvent; |
|
211 |
|
212 CIntegrityTreeNode* iTreeRoot; |
|
213 |
|
214 /** |
|
215 * The count of backup files in this journal |
|
216 */ |
|
217 TInt iBackupFilesCount; |
|
218 |
|
219 /** |
|
220 * The filename of this journal |
|
221 */ |
|
222 TFileName iJournalFileName; |
|
223 |
|
224 /** |
|
225 * The drive number this journal file is on |
|
226 */ |
|
227 |
|
228 TInt iDrive; |
|
229 }; |
|
230 |
|
231 } //namespace |
|
232 #endif |