590 // we need to rename all the |
590 // we need to rename all the |
591 // temp rst files to the real database names |
591 // temp rst files to the real database names |
592 CDir *dir=NULL; |
592 CDir *dir=NULL; |
593 __SQLLEAVE_IF_ERROR(iInterface->Fs().GetDir(KRestoreFilter,KEntryAttNormal,ESortNone,dir)); |
593 __SQLLEAVE_IF_ERROR(iInterface->Fs().GetDir(KRestoreFilter,KEntryAttNormal,ESortNone,dir)); |
594 CleanupStack::PushL(dir); |
594 CleanupStack::PushL(dir); |
|
595 TInt err2 = KErrNone; |
595 for(TInt a=0;a<dir->Count();++a) |
596 for(TInt a=0;a<dir->Count();++a) |
596 { |
597 { |
597 TEntry entry=(*dir)[a]; |
598 TEntry entry=(*dir)[a]; |
598 TPtrC rst=entry.iName.Des(); |
599 TPtrC rst=entry.iName.Des(); |
599 TInt len=rst.Length(); |
600 TInt len=rst.Length(); |
605 // first, rename the orig .db as .bak just in case |
606 // first, rename the orig .db as .bak just in case |
606 // ok if not found - might have been deleted. |
607 // ok if not found - might have been deleted. |
607 //the ".bak" file, if exists, will be deleted first. |
608 //the ".bak" file, if exists, will be deleted first. |
608 (void)iInterface->Fs().Delete(bak); |
609 (void)iInterface->Fs().Delete(bak); |
609 TInt err=iInterface->Fs().Rename(db,bak); |
610 TInt err=iInterface->Fs().Rename(db,bak); |
610 if(err!=KErrNone && err!=KErrNotFound) |
611 if(err == KErrNone || err == KErrNotFound) |
611 { |
612 { |
612 __SQLLEAVE(err); |
613 // now, rename the .rst as .db |
|
614 err = iInterface->Fs().Rename(rst,db); |
613 } |
615 } |
614 |
616 if(err != KErrNone && err2 == KErrNone) |
615 // now, rename the .rst as .db |
617 { |
616 __SQLLEAVE_IF_ERROR(iInterface->Fs().Rename(rst,db)); |
618 //The idea here is to not report the error immediatelly by calling LeaveIfError(). |
|
619 //If we leave here, the next database restore may also fail, for example, if the current database is still open by |
|
620 //its owner. Then "TInt err=iInterface->Fs().Rename(db,bak);" will fail again. |
|
621 err2 = err; |
|
622 } |
617 |
623 |
618 // 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 |
619 // and the new database in .db |
625 // and the new database in .db |
620 } |
626 }//end of for(...) |
|
627 __SQLLEAVE_IF_ERROR(err2); |
621 |
628 |
622 // clean up dir |
629 // clean up dir |
623 //delete dir; |
630 //delete dir; |
624 CleanupStack::PopAndDestroy(dir); |
631 CleanupStack::PopAndDestroy(dir); |
625 dir=NULL; |
632 dir=NULL; |