persistentstorage/sql/SRC/Server/SqlBur.cpp
branchRCL_3
changeset 21 28839de615b4
parent 9 667e88a979d7
child 23 26645d81f48d
--- a/persistentstorage/sql/SRC/Server/SqlBur.cpp	Mon Jun 21 17:37:53 2010 +0300
+++ b/persistentstorage/sql/SRC/Server/SqlBur.cpp	Thu Aug 19 11:36:21 2010 +0300
@@ -592,6 +592,7 @@
 					CDir *dir=NULL;
 					__SQLLEAVE_IF_ERROR(iInterface->Fs().GetDir(KRestoreFilter,KEntryAttNormal,ESortNone,dir));
 					CleanupStack::PushL(dir);
+					TInt err2 = KErrNone;
 					for(TInt a=0;a<dir->Count();++a)
 						{
 						TEntry entry=(*dir)[a];
@@ -607,17 +608,23 @@
 						//the ".bak" file, if exists, will be deleted first.
 						(void)iInterface->Fs().Delete(bak);
 						TInt err=iInterface->Fs().Rename(db,bak);
-						if(err!=KErrNone && err!=KErrNotFound)
+						if(err == KErrNone || err == KErrNotFound)
 							{
-							__SQLLEAVE(err);
+							// now, rename the .rst as .db
+							err = iInterface->Fs().Rename(rst,db);
 							}
-						
-						// now, rename the .rst as .db
-						__SQLLEAVE_IF_ERROR(iInterface->Fs().Rename(rst,db));
+						if(err != KErrNone && err2 == KErrNone)
+							{
+							//The idea here is to not report the error immediatelly by calling LeaveIfError().
+							//If we leave here, the next database restore may also fail, for example, if the current database is still open by 
+							//its owner. Then "TInt err=iInterface->Fs().Rename(db,bak);" will fail again.
+							err2 = err;
+							}
 						
 						// if we got here, we have a backup of the original database in .db.bak
 						// and the new database in .db
-						}
+						}//end of for(...)
+					__SQLLEAVE_IF_ERROR(err2);
 					
 					// clean up dir
 					//delete dir;