1 /* |
1 /* |
2 * Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of the License "Eclipse Public License v1.0" |
5 * under the terms of the License "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
136 iJournal->AddL(localFilename); |
136 iJournal->AddL(localFilename); |
137 SimulatePowerFailureL(EFailAddingNewFile, EAfterJournal, aFileName); |
137 SimulatePowerFailureL(EFailAddingNewFile, EAfterJournal, aFileName); |
138 CleanupStack::PopAndDestroy(localFilenameHeap); |
138 CleanupStack::PopAndDestroy(localFilenameHeap); |
139 } |
139 } |
140 |
140 |
|
141 void CIntegrityServices::CopyToBackupL(const TDesC& aSource, const TDesC& aBackup) |
|
142 { |
|
143 // Copying a file isn't atomic so we create a temporary backup file first |
|
144 RBuf backupTmpName; |
|
145 backupTmpName.Create(aBackup.Length() + 4); |
|
146 CleanupClosePushL(backupTmpName); |
|
147 backupTmpName.Copy(aBackup); |
|
148 _LIT(KTmpExt, ".tmp"); |
|
149 backupTmpName.Append(KTmpExt); |
|
150 |
|
151 // Copying a file is not an atomic operation so add the temporary |
|
152 // file to the journal to enable cleanup if a power failure occurs before |
|
153 // the rename |
|
154 SimulatePowerFailureL(EFailAddingTempFile, EBeforeJournal, backupTmpName); |
|
155 iJournal->TemporaryL(backupTmpName); |
|
156 SimulatePowerFailureL(EFailAddingTempFile, EAfterJournal, backupTmpName); |
|
157 |
|
158 CFileMan* fileMan = CFileMan::NewL(iFs); |
|
159 CleanupStack::PushL(fileMan); |
|
160 |
|
161 TInt err = fileMan->Copy(aSource, backupTmpName); |
|
162 DEBUG_PRINTF4(_L("CopyToBackupL: Copying %S to %S, err %d"), &aSource, &backupTmpName, err); |
|
163 User::LeaveIfError(err); |
|
164 |
|
165 // Backup is complete, use RFs::Rename as atomic 'commit' of backup |
|
166 err = iFs.Rename(backupTmpName, aBackup); |
|
167 DEBUG_PRINTF2(_L("CopyToBackupL: Commit backup returned error %d"), err); |
|
168 User::LeaveIfError(err); |
|
169 CleanupStack::PopAndDestroy(2, &backupTmpName); // backupTmpName, fileMan |
|
170 |
|
171 // Now the backup is safe the original can be deleted |
|
172 err = iLoader.Delete(aSource); |
|
173 DEBUG_PRINTF3(_L("CopyToBackupL: RLoader::Delete %S returned error %d"), &aSource, err); |
|
174 User::LeaveIfError(err); |
|
175 } |
141 |
176 |
142 EXPORT_C void CIntegrityServices::RemoveL(const TDesC& aFileName) |
177 EXPORT_C void CIntegrityServices::RemoveL(const TDesC& aFileName) |
143 { |
178 { |
144 DEBUG_PRINTF3(_L("Integrity Services - Session %Ld, Removing File: %S"), iTransactionID, &aFileName); |
179 DEBUG_PRINTF3(_L("Integrity Services - Session %Ld, Removing File: %S"), iTransactionID, &aFileName); |
145 |
180 |
176 { |
211 { |
177 User::Leave(err); |
212 User::Leave(err); |
178 } |
213 } |
179 |
214 |
180 SimulatePowerFailureL(EFailRemovingFile, EBeforeAction, aFileName); |
215 SimulatePowerFailureL(EFailRemovingFile, EBeforeAction, aFileName); |
181 |
216 |
182 err = iFs.Rename(localFilename, backupFileName); |
217 _LIT(KSysBinMatch, "?:\\sys\\bin\\*"); |
183 DEBUG_PRINTF4(_L("Renamed %S as %S error %d"), &localFilename, &backupFileName, err); |
218 if (localFilename.MatchF(KSysBinMatch) == 0) |
184 User::LeaveIfError(err); |
219 { |
185 |
220 // A copy is slower than a rename to only use the |
|
221 // demand paging safe API for files in sys\bin |
|
222 CopyToBackupL(localFilename, backupFileName); |
|
223 } |
|
224 else |
|
225 { |
|
226 err = iFs.Rename(localFilename, backupFileName); |
|
227 DEBUG_PRINTF4(_L("Renamed %S as %S error %d"), &localFilename, &backupFileName, err); |
|
228 User::LeaveIfError(err); |
|
229 } |
186 SimulatePowerFailureL(EFailRemovingFile, EAfterAction, aFileName); |
230 SimulatePowerFailureL(EFailRemovingFile, EAfterAction, aFileName); |
187 } |
231 } |
188 else |
232 else |
189 { |
233 { |
190 DEBUG_PRINTF2(_L("%S already backed up"), &aFileName); |
234 DEBUG_PRINTF2(_L("%S already backed up"), &aFileName); |