13 // Description: |
13 // Description: |
14 // |
14 // |
15 |
15 |
16 #include "SqlBur.h" |
16 #include "SqlBur.h" |
17 #include "SqlAssert.h" |
17 #include "SqlAssert.h" |
18 #include "OstTraceDefinitions.h" |
18 #include "SqlPanic.h" |
19 #ifdef OST_TRACE_COMPILER_IN_USE |
|
20 #include "SqlBurTraces.h" |
|
21 #endif |
|
22 #include "SqlTraceDef.h" |
|
23 |
|
24 #define UNUSED_ARG(arg) arg = arg |
|
25 |
19 |
26 //Extracts and returns 32-bit integer from aNumBuf buffer. |
20 //Extracts and returns 32-bit integer from aNumBuf buffer. |
27 static TUint32 GetNumUint32L(const TDesC& aNumBuf) |
21 static TUint32 GetNumUint32L(const TDesC& aNumBuf) |
28 { |
22 { |
29 TLex lex(aNumBuf); |
23 TLex lex(aNumBuf); |
30 lex.SkipSpace(); |
24 lex.SkipSpace(); |
31 TUint32 num = 0xFFFFFFFF; |
25 TUint32 num = 0xFFFFFFFF; |
32 __SQLLEAVE_IF_ERROR2(lex.Val(num, EHex)); |
26 __SQLLEAVE_IF_ERROR(lex.Val(num, EHex)); |
33 return num; |
27 return num; |
34 } |
28 } |
35 |
29 |
36 //Extracts and returns 64-bit integer from aNumBuf buffer. |
30 //Extracts and returns 64-bit integer from aNumBuf buffer. |
37 static TInt64 GetNumInt64L(const TDesC& aNumBuf) |
31 static TInt64 GetNumInt64L(const TDesC& aNumBuf) |
38 { |
32 { |
39 TLex lex(aNumBuf); |
33 TLex lex(aNumBuf); |
40 lex.SkipSpace(); |
34 lex.SkipSpace(); |
41 TInt64 num = -1; |
35 TInt64 num = -1; |
42 __SQLLEAVE_IF_ERROR2(lex.Val(num, EHex)); |
36 __SQLLEAVE_IF_ERROR(lex.Val(num, EHex)); |
43 return num; |
37 return num; |
44 } |
38 } |
45 |
39 |
46 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
40 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
47 |
41 |
61 CSqlBackupClient* CSqlBackupClient::NewLC(MSqlSrvBurInterface *aInterface) |
55 CSqlBackupClient* CSqlBackupClient::NewLC(MSqlSrvBurInterface *aInterface) |
62 { |
56 { |
63 CSqlBackupClient *self=(CSqlBackupClient *)new(ELeave) CSqlBackupClient(aInterface); |
57 CSqlBackupClient *self=(CSqlBackupClient *)new(ELeave) CSqlBackupClient(aInterface); |
64 CleanupStack::PushL(self); |
58 CleanupStack::PushL(self); |
65 self->ConstructL(); |
59 self->ConstructL(); |
66 SQL_TRACE_BUR(OstTrace1(TRACE_INTERNALS, CSQLBACKUPCLIENT_NEWLC, "0x%X;CSqlBackupClient::NewLC", (TUint)self)); |
|
67 return self; |
60 return self; |
68 } |
61 } |
69 |
62 |
70 /** Standard two phase construction |
63 /** Standard two phase construction |
71 @return an instance of the backup client |
64 @return an instance of the backup client |
137 |
128 |
138 /** Not implemented |
129 /** Not implemented |
139 @return a flag indicating whether we actioned the error |
130 @return a flag indicating whether we actioned the error |
140 @param the error unused |
131 @param the error unused |
141 */ |
132 */ |
142 TInt CSqlBackupClient::RunError(TInt aError) |
133 TInt CSqlBackupClient::RunError(TInt /* aError */) |
143 { |
134 { |
144 UNUSED_ARG(aError); |
|
145 SQL_TRACE_BUR(OstTraceExt2(TRACE_INTERNALS, CSQLBACKUPCLIENT_RUNERROR, "0x%X;CSqlBackupClient::RunError;aError=%d", (TUint)this, aError)); |
|
146 // just satisfy it that we did something! |
135 // just satisfy it that we did something! |
147 return KErrNone; |
136 return KErrNone; |
148 } |
137 } |
149 |
138 |
150 /** Kick off the BUR client |
139 /** Kick off the BUR client |
171 This is for performance reasons |
159 This is for performance reasons |
172 @leave if ConfirmReadyForBURL leaves |
160 @leave if ConfirmReadyForBURL leaves |
173 */ |
161 */ |
174 void CSqlBackupClient::TestBurStatusL() |
162 void CSqlBackupClient::TestBurStatusL() |
175 { |
163 { |
176 SQL_TRACE_BUR(OstTrace1(TRACE_INTERNALS, CSQLBACKUPCLIENT_TESTBURSTATUSL_ENTRY, "Entry;0x%X;CSqlBackupClient::TestBurStatusL", (TUint)this)); |
|
177 TInt status; |
164 TInt status; |
178 __SQLTRACE_BURVAR(TInt err = KErrNone); |
165 if(iBurProperty.Get(status)!=KErrNotFound) |
179 if((__SQLTRACE_BUREXPR(err =) iBurProperty.Get(status)) != KErrNotFound) |
|
180 { |
166 { |
181 status&=KBURPartTypeMask; |
167 status&=KBURPartTypeMask; |
182 #ifdef _SQL_RDEBUG_PRINT |
|
183 SQL_TRACE_BUR(OstTraceExt2(TRACE_INTERNALS, CSQLBACKUPCLIENT_TESTBURSTATUSL1, "0x%X;CSqlBackupClient::TestBurStatusL;status=%d", (TUint)this, status)); |
|
184 #else |
|
185 SQL_TRACE_BUR(OstTraceExt2(TRACE_INTERNALS, CSQLBACKUPCLIENT_TESTBURSTATUSL2, "0x%X;CSqlBackupClient::TestBurStatusL;status=%{TBURPartType}", (TUint)this, status)); |
|
186 #endif |
|
187 switch(status) |
168 switch(status) |
188 { |
169 { |
189 case EBURUnset: // same as EBURNormal |
170 case EBURUnset: // same as EBURNormal |
190 case EBURNormal: |
171 case EBURNormal: |
191 delete iActiveBackupClient; |
172 delete iActiveBackupClient; |
227 supposed to allow the BUE to optimise its behaviour by know up front |
207 supposed to allow the BUE to optimise its behaviour by know up front |
228 the data volume. |
208 the data volume. |
229 @return an arbitrary number |
209 @return an arbitrary number |
230 @param TDrive unused |
210 @param TDrive unused |
231 */ |
211 */ |
232 TUint CSqlBackupClient::GetExpectedDataSize(TDriveNumber aDrive) |
212 TUint CSqlBackupClient::GetExpectedDataSize(TDriveNumber /* aDrive */) |
233 { |
213 { |
234 UNUSED_ARG(aDrive); |
|
235 // we have no idea at this point - we even don't know who is to be backed up yet |
214 // we have no idea at this point - we even don't know who is to be backed up yet |
236 const TUint KArbitraryNumber = 1024; |
215 const TUint KArbitraryNumber = 1024; |
237 SQL_TRACE_BUR(OstTraceExt3(TRACE_INTERNALS, CSQLBACKUPCLIENT_GETEXPECTEDDATASIZE, "0x%X;CSqlBackupClient::GetExpectedDataSize;aDrive=%d;rc=%u", (TUint)this, (TInt)aDrive, KArbitraryNumber)); |
|
238 return KArbitraryNumber; |
216 return KArbitraryNumber; |
239 } |
217 } |
240 |
218 |
241 /** This is the backup state machine |
219 /** This is the backup state machine |
242 Because the data has to be sent back in sections and the various |
220 Because the data has to be sent back in sections and the various |
247 @param TBool set to true when all data has been submitted for backup |
225 @param TBool set to true when all data has been submitted for backup |
248 @leave |
226 @leave |
249 */ |
227 */ |
250 void CSqlBackupClient::GetBackupDataSectionL(TPtr8& aBuffer, TBool& aFinishedFlag) |
228 void CSqlBackupClient::GetBackupDataSectionL(TPtr8& aBuffer, TBool& aFinishedFlag) |
251 { |
229 { |
252 SQL_TRACE_BUR(OstTraceExt3(TRACE_INTERNALS, CSQLBACKUPCLIENT_GETBACKUPDATASECTIONL0, "0x%X;CSqlBackupClient::GetBackupDataSectionL;iState=%d;iFileIndex=%d", (TUint)this, (TInt)iState, iFileIndex)); |
|
253 // don't assume they set it to false |
230 // don't assume they set it to false |
254 aFinishedFlag=EFalse; |
231 aFinishedFlag=EFalse; |
255 // any files to backup |
232 // any files to backup |
256 if(iFileList.Count()==0) |
233 if(iFileList.Count()==0) |
257 { |
234 { |
258 SQL_TRACE_BUR(OstTrace1(TRACE_INTERNALS, CSQLBACKUPCLIENT_GETBACKUPDATASECTIONL1, "0x%X;CSqlBackupClient::GetBackupDataSectionL;file count is 0", (TUint)this)); |
|
259 // nothing to backup - just return the finished flag |
235 // nothing to backup - just return the finished flag |
260 aFinishedFlag=ETrue; |
236 aFinishedFlag=ETrue; |
261 // clear down the list |
237 // clear down the list |
262 iFileList.Reset(); |
238 iFileList.Reset(); |
263 // iFileList closed in dtor |
239 // iFileList closed in dtor |
264 return; |
240 return; |
265 } |
241 } |
266 |
242 |
267 // run the state machine |
243 // run the state machine |
268 for(TInt bufFreeSpace=aBuffer.MaxSize()-aBuffer.Size(); bufFreeSpace>0; bufFreeSpace=aBuffer.MaxSize()-aBuffer.Size()) |
244 for(TInt bufFreeSpace=aBuffer.MaxSize()-aBuffer.Size(); bufFreeSpace>0; bufFreeSpace=aBuffer.MaxSize()-aBuffer.Size()) |
269 { |
245 { |
270 switch(iState) |
246 switch(iState) |
271 { |
247 { |
272 case EBackupNoFileOpen: // open a file for processing |
248 case EBackupNoFileOpen: // open a file for processing |
273 { |
249 { |
274 if(iFileIndex>=iFileList.Count()) |
250 if(iFileIndex>=iFileList.Count()) |
275 { |
251 { |
276 SQL_TRACE_BUR(OstTrace1(TRACE_INTERNALS, CSQLBACKUPCLIENT_GETBACKUPDATASECTIONL2, "0x%X;CSqlBackupClient::GetBackupDataSectionL;all files processed", (TUint)this)); |
|
277 // all files have been processed - send the finished flag |
252 // all files have been processed - send the finished flag |
278 aFinishedFlag=ETrue; |
253 aFinishedFlag=ETrue; |
279 // clear down the filelist |
254 // clear down the filelist |
280 iFileList.Reset(); |
255 iFileList.Reset(); |
281 return; |
256 return; |
282 } |
257 } |
283 // open the database file to send |
258 // open the database file to send |
284 TInt rc=iFile.Open( iInterface->Fs(), iFileList[iFileIndex].FullName(), EFileRead | EFileShareExclusive); |
259 TInt rc=iFile.Open( iInterface->Fs(), iFileList[iFileIndex].FullName(), EFileRead | EFileShareExclusive); |
285 __SQLTRACE_BUREXPR(TPtrC fname = iFileList[iFileIndex].FullName()); |
|
286 SQL_TRACE_BUR(OstTraceExt5(TRACE_INTERNALS, CSQLBACKUPCLIENT_GETBACKUPDATASECTIONL3, "0x%X;CSqlBackupClient::GetBackupDataSectionL;BEGIN;fname=%S;iFileIndex=%d;iFile.SubSessionHandle()=0x%X;rc=%d", (TUint)this, __SQLPRNSTR(fname), iFileIndex, (TUint)iFile.SubSessionHandle(), rc)); |
|
287 if(KErrNone!=rc) |
260 if(KErrNone!=rc) |
288 { |
261 { |
289 // there's nothing we can do if we can't open the file so we just skip it |
262 // there's nothing we can do if we can't open the file so we just skip it |
290 ++iFileIndex; |
263 ++iFileIndex; |
291 break; |
264 break; |
315 KMagicNum, // %8x |
288 KMagicNum, // %8x |
316 KBackupHeaderVersion, // %4x |
289 KBackupHeaderVersion, // %4x |
317 fileSize, // %16lx |
290 fileSize, // %16lx |
318 fileName.Length(), // %8x |
291 fileName.Length(), // %8x |
319 &fileName); // %S |
292 &fileName); // %S |
320 SQL_TRACE_BUR(OstTraceExt4(TRACE_INTERNALS, CSQLBACKUPCLIENT_GETBACKUPDATASECTIONL5, "0x%X;CSqlBackupClient::GetBackupDataSectionL;fileName=%S;hdrPtr=|%S|;fileSize=%lld", (TUint)this, __SQLPRNSTR(fileName), __SQLPRNSTR(iBuffer), fileSize)); |
|
321 |
293 |
322 // we need it to look like an 8bit buffer |
294 // we need it to look like an 8bit buffer |
323 TPtr8 hdrPtr8((TUint8*)iBuffer.Ptr(), iBuffer.Size(), iBuffer.Size()); |
295 TPtr8 hdrPtr8((TUint8*)iBuffer.Ptr(), iBuffer.Size(), iBuffer.Size()); |
324 |
296 |
325 TInt len = Min(hdrPtr8.Size(), bufFreeSpace); |
297 TInt len = Min(hdrPtr8.Size(), bufFreeSpace); |
401 |
372 |
402 /** This is called by BUE when the restore has completed |
373 /** This is called by BUE when the restore has completed |
403 Nothing to do here except tell the server |
374 Nothing to do here except tell the server |
404 @param TDrive the drive that is being restored (unused) |
375 @param TDrive the drive that is being restored (unused) |
405 */ |
376 */ |
406 void CSqlBackupClient::RestoreComplete(TDriveNumber aDrive) |
377 void CSqlBackupClient::RestoreComplete(TDriveNumber /* aDrive */) |
407 { |
378 { |
408 UNUSED_ARG(aDrive); |
|
409 SQL_TRACE_BUR(OstTraceExt2(TRACE_INTERNALS, CSQLBACKUPCLIENT_RESTORECOMPLETE, "0x%X;CSqlBackupClient::RestoreComplete;aDrive=%d", (TUint)this, (TInt)aDrive)); |
|
410 } |
379 } |
411 |
380 |
412 /** This is called to let us know that the given SID is to be backed up |
381 /** This is called to let us know that the given SID is to be backed up |
413 We ask the SQL server for a list of databases that want to be backed |
382 We ask the SQL server for a list of databases that want to be backed |
414 up - this is because the backup flag is an internal metadata object |
383 up - this is because the backup flag is an internal metadata object |
416 this data is stored. |
385 this data is stored. |
417 @param TSecureSid the UID of the application to backup |
386 @param TSecureSid the UID of the application to backup |
418 @param TDriveNumber the drive to be backed up (unused) |
387 @param TDriveNumber the drive to be backed up (unused) |
419 @leave |
388 @leave |
420 */ |
389 */ |
421 void CSqlBackupClient::InitialiseGetProxyBackupDataL(TSecureId aSid, TDriveNumber aDrive) |
390 void CSqlBackupClient::InitialiseGetProxyBackupDataL(TSecureId aSid, TDriveNumber /*aDrive*/) |
422 { |
391 { |
423 UNUSED_ARG(aDrive); |
|
424 SQL_TRACE_BUR(OstTraceExt3(TRACE_INTERNALS, CSQLBACKUPCLIENT_INITIALIZEGETPROXYBACKUPDATAL, "0x%X;CSqlBackupClient::InitialiseGetProxyBackupDataL;aSid=0x%X;aDrive=%d", (TUint)this, (TUint)aSid.iId, (TInt)aDrive)); |
|
425 // get the list of database files to back up - this is provided by the SQL server |
392 // get the list of database files to back up - this is provided by the SQL server |
426 GetBackupListL(aSid); |
393 GetBackupListL(aSid); |
427 // this is the index of the file being processed - point to the beginning |
394 // this is the index of the file being processed - point to the beginning |
428 iFileIndex=0; |
395 iFileIndex=0; |
429 // the first state of the backup state machine |
396 // the first state of the backup state machine |
435 /** Called when the BUE wants to start sending data to us |
402 /** Called when the BUE wants to start sending data to us |
436 @param TSecureId the UID of the application that is to be restored |
403 @param TSecureId the UID of the application that is to be restored |
437 @param TDriveNumber the drive to restore (unused) |
404 @param TDriveNumber the drive to restore (unused) |
438 @leave |
405 @leave |
439 */ |
406 */ |
440 void CSqlBackupClient::InitialiseRestoreProxyBaseDataL(TSecureId aSid, TDriveNumber aDrive) |
407 void CSqlBackupClient::InitialiseRestoreProxyBaseDataL(TSecureId aSid, TDriveNumber /* aDrive */) |
441 { |
408 { |
442 UNUSED_ARG(aDrive); |
|
443 SQL_TRACE_BUR(OstTraceExt3(TRACE_INTERNALS, CSQLBACKUPCLIENT_INITIALIZERESTOREPROXYBASEDATAL, "0x%X;CSqlBackupClient::InitialiseRestoreProxyBaseDataL;aSid=0x%X;aDrive=%d", (TUint)this, (TUint)aSid.iId, (TInt)aDrive)); |
|
444 iBuffer.Zero(); |
409 iBuffer.Zero(); |
445 // this is the first state of the restore state machine |
410 // this is the first state of the restore state machine |
446 iState=ERestoreExpectChecksum; |
411 iState=ERestoreExpectChecksum; |
447 iAnyData=EFalse; // to keep track in the state machine whether any data was actually sent |
412 iAnyData=EFalse; // to keep track in the state machine whether any data was actually sent |
448 // save the sid for notifying the server when the restore is done |
413 // save the sid for notifying the server when the restore is done |
459 Attention!!! This function won't work properly if aInBuffer parameter contains odd number of bytes!!! |
424 Attention!!! This function won't work properly if aInBuffer parameter contains odd number of bytes!!! |
460 (a legacy problem, if it is a problem at all, because the B&R engine probably sends the data in chunks with even size) |
425 (a legacy problem, if it is a problem at all, because the B&R engine probably sends the data in chunks with even size) |
461 */ |
426 */ |
462 void CSqlBackupClient::RestoreBaseDataSectionL(TDesC8& aInBuffer, TBool aFinishedFlag) |
427 void CSqlBackupClient::RestoreBaseDataSectionL(TDesC8& aInBuffer, TBool aFinishedFlag) |
463 { |
428 { |
464 SQL_TRACE_BUR(OstTraceExt4(TRACE_INTERNALS, CSQLBACKUPCLIENT_RESTOREBASEDATASECTONL0, "0x%X;CSqlBackupClient::RestoreBaseDataSectionL;iState=%d;aInBuffer.Length()=%d;aFinishedFlag=%d", (TUint)this, (TInt)iState, aInBuffer.Length(), (TInt)aFinishedFlag)); |
|
465 // used to walk the buffer |
429 // used to walk the buffer |
466 // got a new buffer - because each time this method is called, we have a |
430 // got a new buffer - because each time this method is called, we have a |
467 // fresh chunk of data |
431 // fresh chunk of data |
468 TInt inBufferPos = 0; |
432 TInt inBufferPos = 0; |
469 |
433 |
560 { |
524 { |
561 iFileSize = GetNumInt64L(iBuffer); |
525 iFileSize = GetNumInt64L(iBuffer); |
562 iState = ERestoreExpectFileNameSize; |
526 iState = ERestoreExpectFileNameSize; |
563 iBuffer.Zero(); |
527 iBuffer.Zero(); |
564 } |
528 } |
565 SQL_TRACE_BUR(OstTraceExt2(TRACE_INTERNALS, CSQLBACKUPCLIENT_RESTOREBASEDATASECTONL1, "0x%X;CSqlBackupClient::RestoreBaseDataSectionL;iFileSize=%lld", (TUint)this, iFileSize)); |
|
566 break; |
529 break; |
567 } |
530 } |
568 case ERestoreExpectFileNameSize: // the size of the file name to restore |
531 case ERestoreExpectFileNameSize: // the size of the file name to restore |
569 { |
532 { |
570 const TInt KFileNameLenStrLen = 8; |
533 const TInt KFileNameLenStrLen = 8; |
578 break; |
541 break; |
579 } |
542 } |
580 case ERestoreExpectFileName: // the name of the file to restore |
543 case ERestoreExpectFileName: // the name of the file to restore |
581 { |
544 { |
582 CopyBufData(aInBuffer, inBufferPos, iBuffer, iFileNameSize); |
545 CopyBufData(aInBuffer, inBufferPos, iBuffer, iFileNameSize); |
583 SQL_TRACE_BUR(OstTraceExt4(TRACE_INTERNALS, CSQLBACKUPCLIENT_RESTOREBASEDATASECTONL2, "0x%X;CSqlBackupClient::RestoreBaseDataSectionL;BEGIN;iBuffer=%S;iBuffer.Length()=%d;iFileNameSize=%d", (TUint)this, __SQLPRNSTR(iBuffer), iBuffer.Length(), iFileNameSize)); |
|
584 if(iBuffer.Length() == iFileNameSize) |
546 if(iBuffer.Length() == iFileNameSize) |
585 { |
547 { |
586 iState = ERestoreExpectData; |
548 iState = ERestoreExpectData; |
587 iBuffer.Append(KRestoreSuffix); |
549 iBuffer.Append(KRestoreSuffix); |
588 // now we start writing the data to the target file |
550 // now we start writing the data to the target file |
589 // write to a temp - double disk space potentially |
551 // write to a temp - double disk space potentially |
590 // once all the temp files are created, then they are renamed to the |
552 // once all the temp files are created, then they are renamed to the |
591 // real file names in one fell swoop |
553 // real file names in one fell swoop |
592 __SQLLEAVE_IF_ERROR(iFile.Replace(iInterface->Fs(), iBuffer, EFileWrite | EFileShareExclusive)); |
554 __SQLLEAVE_IF_ERROR(iFile.Replace(iInterface->Fs(), iBuffer, EFileWrite | EFileShareExclusive)); |
593 SQL_TRACE_BUR(OstTraceExt2(TRACE_INTERNALS, CSQLBACKUPCLIENT_RESTOREBASEDATASECTONL3, "0x%X;CSqlBackupClient::RestoreBaseDataSectionL;iFile.SubSessionHandle()=0x%X", (TUint)this, (TUint)iFile.SubSessionHandle())); |
|
594 iBuffer.Zero(); |
555 iBuffer.Zero(); |
595 } |
556 } |
596 break; |
557 break; |
597 } |
558 } |
598 case ERestoreExpectData: // now for the data |
559 case ERestoreExpectData: // now for the data |
611 { |
572 { |
612 // calculate the checksum |
573 // calculate the checksum |
613 TUint32 cksum = CheckSumL(iFile) & KMaxTUint32; |
574 TUint32 cksum = CheckSumL(iFile) & KMaxTUint32; |
614 |
575 |
615 // done with the file now - has to follow checksum cos it |
576 // done with the file now - has to follow checksum cos it |
616 // expects ann open file |
577 // expects an open file |
617 SQL_TRACE_BUR(OstTraceExt2(TRACE_INTERNALS, CSQLBACKUPCLIENT_RESTOREBASEDATASECTONL4, "0x%X;CSqlBackupClient::RestoreBaseDataSectionL;END;iFile.SubSessionHandle()=0x%X", (TUint)this, (TUint)iFile.SubSessionHandle())); |
578 __SQLLEAVE_IF_ERROR(iFile.Flush()); |
618 __SQLLEAVE_IF_ERROR(iFile.Flush()); |
|
619 iFile.Close(); |
579 iFile.Close(); |
620 |
580 |
621 // validate that the checksum matches |
581 // validate that the checksum matches |
622 if(cksum!=iChecksum) |
582 if(cksum!=iChecksum) |
623 { |
583 { |
646 // first, rename the orig .db as .bak just in case |
606 // first, rename the orig .db as .bak just in case |
647 // ok if not found - might have been deleted. |
607 // ok if not found - might have been deleted. |
648 //the ".bak" file, if exists, will be deleted first. |
608 //the ".bak" file, if exists, will be deleted first. |
649 (void)iInterface->Fs().Delete(bak); |
609 (void)iInterface->Fs().Delete(bak); |
650 TInt err=iInterface->Fs().Rename(db,bak); |
610 TInt err=iInterface->Fs().Rename(db,bak); |
651 SQL_TRACE_BUR(OstTraceExt4(TRACE_INTERNALS, CSQLBACKUPCLIENT_RESTOREBASEDATASECTONL5, "0x%X;CSqlBackupClient::RestoreBaseDataSectionL;END;bak=%S;db=%S;err=%d", (TUint)this, __SQLPRNSTR(bak), __SQLPRNSTR(db), err)); |
|
652 if(err == KErrNone || err == KErrNotFound) |
611 if(err == KErrNone || err == KErrNotFound) |
653 { |
612 { |
654 // now, rename the .rst as .db |
613 // now, rename the .rst as .db |
655 err = iInterface->Fs().Rename(rst,db); |
614 err = iInterface->Fs().Rename(rst,db); |
656 } |
615 } |
659 //The idea here is to not report the error immediatelly by calling LeaveIfError(). |
618 //The idea here is to not report the error immediatelly by calling LeaveIfError(). |
660 //If we leave here, the next database restore may also fail, for example, if the current database is still open by |
619 //If we leave here, the next database restore may also fail, for example, if the current database is still open by |
661 //its owner. Then "TInt err=iInterface->Fs().Rename(db,bak);" will fail again. |
620 //its owner. Then "TInt err=iInterface->Fs().Rename(db,bak);" will fail again. |
662 err2 = err; |
621 err2 = err; |
663 } |
622 } |
|
623 |
664 // if we got here, we have a backup of the original database in .db.bak |
624 // if we got here, we have a backup of the original database in .db.bak |
665 // and the new database in .db |
625 // and the new database in .db |
666 }//end of for(...) |
626 }//end of for(...) |
667 __SQLLEAVE_IF_ERROR(err2); |
627 __SQLLEAVE_IF_ERROR(err2); |
668 |
628 |
675 // we do this here and not part of the earlier loop |
635 // we do this here and not part of the earlier loop |
676 // because we want to make sure that we have a coherent set of database |
636 // because we want to make sure that we have a coherent set of database |
677 // files that belong together and not bits of old and new |
637 // files that belong together and not bits of old and new |
678 __SQLLEAVE_IF_ERROR(iInterface->Fs().GetDir(KBackupFilter,KEntryAttNormal,ESortNone,dir)); |
638 __SQLLEAVE_IF_ERROR(iInterface->Fs().GetDir(KBackupFilter,KEntryAttNormal,ESortNone,dir)); |
679 CleanupStack::PushL(dir); |
639 CleanupStack::PushL(dir); |
680 SQL_TRACE_BUR(OstTraceExt2(TRACE_INTERNALS, CSQLBACKUPCLIENT_RESTOREBASEDATASECTONL6, "0x%X;CSqlBackupClient::RestoreBaseDataSectionL;bak files count=%d", (TUint)this, dir->Count())); |
|
681 for(TInt a1=0;a1<dir->Count();++a1) |
640 for(TInt a1=0;a1<dir->Count();++a1) |
682 { |
641 { |
683 TEntry entry=(*dir)[a1]; |
642 TEntry entry=(*dir)[a1]; |
684 TPtrC bak=entry.iName.Des(); |
643 TPtrC bak=entry.iName.Des(); |
685 __SQLLEAVE_IF_ERROR(iInterface->Fs().Delete(bak)); |
644 __SQLLEAVE_IF_ERROR(iInterface->Fs().Delete(bak)); |
714 { |
673 { |
715 // backup/restore terminated, try to tidy up! Can't leave, can't Panic!!!!! |
674 // backup/restore terminated, try to tidy up! Can't leave, can't Panic!!!!! |
716 // rename all the .bak files to .db |
675 // rename all the .bak files to .db |
717 CDir *dir=NULL; |
676 CDir *dir=NULL; |
718 TInt rc=iInterface->Fs().GetDir(KBackupFilter,KEntryAttNormal,ESortNone,dir); |
677 TInt rc=iInterface->Fs().GetDir(KBackupFilter,KEntryAttNormal,ESortNone,dir); |
719 SQL_TRACE_BUR(OstTraceExt3(TRACE_INTERNALS, CSQLBACKUPCLIENT_TERMINATEMULTISTAGEOPERATION1, "0x%X;CSqlBackupClient::TerminateMultiStageOperation;Fs().GetDir() err=%d;file count=%d", (TUint)this, rc, rc == KErrNone ? dir->Count() : 0)); |
|
720 if(KErrNone!=rc) |
678 if(KErrNone!=rc) |
721 { |
679 { |
722 // can't get a file list - can't do anything |
680 // can't get a file list - can't do anything |
723 return; |
681 return; |
724 } |
682 } |
735 } |
693 } |
736 //The function cannot leave or return an error. The only thing which could be done here is to print out something |
694 //The function cannot leave or return an error. The only thing which could be done here is to print out something |
737 //and continue with the next file. |
695 //and continue with the next file. |
738 if(KErrNone != rc) |
696 if(KErrNone != rc) |
739 { |
697 { |
740 SQL_TRACE_BUR(OstTraceExt4(TRACE_INTERNALS, CSQLBACKUPCLIENT_TERMINATEMULTISTAGEOPERATION2, "0x%X;CSqlBackupClient::TerminateMultiStageOperation;Fs().Rename() err=%d;bak=%S;db=%S", (TUint)this, rc, __SQLPRNSTR(bak), __SQLPRNSTR(db))); |
698 RDebug::Print(_L(" *** CSqlBackupClient::TerminateMultiStageOperation(), file \"%S\", err=%d\r\n"), &db, rc); |
741 } |
699 } |
742 // backup restored ok |
700 // backup restored ok |
743 } |
701 } |
744 // cleanup dir |
702 // cleanup dir |
745 delete dir; |
703 delete dir; |
823 @leave |
781 @leave |
824 @param TSecureSid the UID of the data owner |
782 @param TSecureSid the UID of the data owner |
825 */ |
783 */ |
826 void CSqlBackupClient::GetBackupListL(TSecureId aSid) |
784 void CSqlBackupClient::GetBackupListL(TSecureId aSid) |
827 { |
785 { |
828 SQL_TRACE_BUR(OstTraceExt2(TRACE_INTERNALS, CSQLBACKUPCLIENT_GETBACKUPLISTL, "0x%X;CSqlBackupClient::GetBackupListL;aSid=0x%X", (TUint)this, (TUint)aSid.iId)); |
|
829 // we own the array - the SQL server just populates it |
786 // we own the array - the SQL server just populates it |
830 iInterface->GetBackUpListL(aSid,iFileList); |
787 iInterface->GetBackUpListL(aSid,iFileList); |
831 } |
788 } |
832 |
789 |
833 /** A simple checksumming algorithm to allow a degree |
790 /** A simple checksumming algorithm to allow a degree |
884 //otherwise CopyBufData() will copy as much characters as possible (in which case RestoreBaseDataSectionL() will |
841 //otherwise CopyBufData() will copy as much characters as possible (in which case RestoreBaseDataSectionL() will |
885 //stay in the same state, waiting for more data from the B&R server). |
842 //stay in the same state, waiting for more data from the B&R server). |
886 // |
843 // |
887 void CSqlBackupClient::CopyBufData(const TDesC8& aInBuf, TInt& aInBufReadPos, TDes& aOutBuf, TInt aDataLen) |
844 void CSqlBackupClient::CopyBufData(const TDesC8& aInBuf, TInt& aInBufReadPos, TDes& aOutBuf, TInt aDataLen) |
888 { |
845 { |
889 __ASSERT_DEBUG(aInBufReadPos >= 0, __SQLPANIC(ESqlPanicBadArgument)); |
846 __SQLASSERT(aInBufReadPos >= 0, ESqlPanicBadArgument); |
890 __ASSERT_DEBUG(aDataLen > 0, __SQLPANIC(ESqlPanicBadArgument)); |
847 __SQLASSERT(aDataLen > 0, ESqlPanicBadArgument); |
891 __ASSERT_DEBUG(!(aInBuf.Length() & 0x01), __SQLPANIC(ESqlPanicInternalError)); |
848 __SQLASSERT(!(aInBuf.Length() & 0x01), ESqlPanicInternalError); |
892 |
849 |
893 TInt needed = (aDataLen - aOutBuf.Length()) << K8to16bitShift; |
850 TInt needed = (aDataLen - aOutBuf.Length()) << K8to16bitShift; |
894 TInt available = aInBuf.Size() - aInBufReadPos; |
851 TInt available = aInBuf.Size() - aInBufReadPos; |
895 TInt len = Min(needed, available); |
852 TInt len = Min(needed, available); |
896 TPtrC8 ptr8 = aInBuf.Mid(aInBufReadPos, len); |
853 TPtrC8 ptr8 = aInBuf.Mid(aInBufReadPos, len); |