persistentstorage/centralrepository/cenrepsrv/shrepos.cpp
changeset 55 44f437012c90
parent 15 3eacc0623088
equal deleted inserted replaced
51:7d4490026038 55:44f437012c90
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
   125 		}
   125 		}
   126 	if (error == KErrNone)
   126 	if (error == KErrNone)
   127 		{
   127 		{
   128 		// changes have been made: fail all other sessions' transactions so we can commit
   128 		// changes have been made: fail all other sessions' transactions so we can commit
   129 		FailAllTransactions(/*aExcludeTransactor=*/&aTransactor);
   129 		FailAllTransactions(/*aExcludeTransactor=*/&aTransactor);
       
   130 #ifdef SYMBIAN_INCLUDE_APP_CENTRIC
       
   131 		if (iSimRep->KeyspaceType() == EPMAKeyspace)
       
   132 		    {
       
   133 		    // We add the repository UID to the PMA array before the commit because
       
   134 		    //  if the commit then fails, we can simply remove the UID from the array,
       
   135 		    //  before returning the error code. If we perform the commit first,
       
   136 		    //  then update the array, in the event the commit succeeds but the
       
   137 		    //  array updated fails, then we are left in an inconsistent state.
       
   138             TInt err = TServerResources::iPMADriveRepositories.InsertInOrder( iSimRep->Uid(), TLinearOrder<TUid>(TServerResources::CompareUids) );
       
   139 		    if (err != KErrNone && err != KErrAlreadyExists)
       
   140                 {
       
   141 		        return err;
       
   142                 }
       
   143 		    error = CommitChanges(EPma); // This already calls ResetContent() in case of failure.
       
   144 		    
       
   145 		    if (error != KErrNone && err != KErrAlreadyExists)
       
   146 		        {
       
   147 		        // We only want to remove the UID from the array, if the failed commit
       
   148 		        //  means there is no repository in the protected area (i.e. this 
       
   149 		        //  commit is creating the repository there). If this commit is just
       
   150 		        //  updating an existing repository in the protected area then we want 
       
   151 		        //  to leave the UID in the array, in order to keep the array and
       
   152 		        //  protected area consistent.
       
   153                 TInt result = TServerResources::iPMADriveRepositories.FindInOrder( iSimRep->Uid(), TLinearOrder<TUid>(TServerResources::CompareUids) );
       
   154                 if (result != KErrNotFound)
       
   155                     {
       
   156                     TServerResources::iPMADriveRepositories.Remove( result );
       
   157                     }
       
   158 		        }
       
   159 		    }
       
   160 		else
       
   161 			{
       
   162 			error = CommitChanges(EPersists); // This already calls ResetContent() in case of failure.
       
   163 			}
       
   164 #else
   130 		error = CommitChanges(); // this already calls ResetContent() in case of failure
   165 		error = CommitChanges(); // this already calls ResetContent() in case of failure
       
   166 #endif
       
   167 
   131 		}
   168 		}
   132 	if (error == KErrNone)
   169 	if (error == KErrNone)
   133 		{
   170 		{
   134 		// settings are now persistent on disk: we can now notify about the changes
   171 		// settings are now persistent on disk: we can now notify about the changes
   135 		// following will notify about objects that are created and deleted in the transaction
   172 		// following will notify about objects that are created and deleted in the transaction
   183 
   220 
   184 // deletes an individual setting in the shared repository and makes it persistent
   221 // deletes an individual setting in the shared repository and makes it persistent
   185 // if changes are made, all sessions' transactions are failed
   222 // if changes are made, all sessions' transactions are failed
   186 TInt CSharedRepository::DeleteAndPersist(TUint32 aId)
   223 TInt CSharedRepository::DeleteAndPersist(TUint32 aId)
   187 	{
   224 	{
       
   225 #ifdef SYMBIAN_INCLUDE_APP_CENTRIC
       
   226     __ASSERT_DEBUG(iSimRep->KeyspaceType() != EPMAKeyspace, User::Invariant());
       
   227 #endif
   188 	TServerSetting* s = iSimRep->SettingsArray().Find(aId);
   228 	TServerSetting* s = iSimRep->SettingsArray().Find(aId);
   189 	if(!s)
   229 	if(!s)
   190 		return KErrNotFound;
   230 		return KErrNotFound;
   191 	iSimRep->SettingsArray().Remove(aId);
   231 	iSimRep->SettingsArray().Remove(aId);
   192 	
   232 	
   709 
   749 
   710 TInt CSharedRepository::CreateRepositoryFromCreFileL( TCentRepLocation aLocation)
   750 TInt CSharedRepository::CreateRepositoryFromCreFileL( TCentRepLocation aLocation)
   711 	{
   751 	{
   712 	// Get file path name from location
   752 	// Get file path name from location
   713     HBufC* filePath(NULL);
   753     HBufC* filePath(NULL);
   714     TServerResources::CreateRepositoryFileNameLC(filePath,iSimRep->Uid(), aLocation,ECre);
   754     TUid uidToOpen = iSimRep->Uid();
       
   755     TServerResources::CreateRepositoryFileNameLC(filePath, uidToOpen, aLocation,ECre);
   715     // Trap errors from repository creation so we can delete corrupt repositories
   756     // Trap errors from repository creation so we can delete corrupt repositories
   716 	TRAPD(error, iSimRep->CreateRepositoryFromCreFileL(TServerResources::iFs,*filePath));
   757 	TRAPD(error, iSimRep->CreateRepositoryFromCreFileL(TServerResources::iFs,*filePath));
   717 	if(error!=KErrNone && error!=KErrNotFound && error!=KErrNoMemory)
   758 
   718 		{
   759     if(error!=KErrNone && error!=KErrNotFound && error!=KErrNoMemory)
   719 		error=KErrCorrupt;
   760         {
       
   761         error = KErrCorrupt;
       
   762 
       
   763 #ifdef SYMBIAN_INCLUDE_APP_CENTRIC
       
   764         }
       
   765 	// Need to verify that if the reposistory is in the:
       
   766     // 1) protected directory, it MUST contain the 'protected' keyword.
       
   767 	// 2) persists directory, it MUST NOT contain the 'protected' keyword.
       
   768     // 3) install directory, it MUST NOT contain the 'protected' keyword. 
       
   769 	// 
       
   770 	// If the check fails, it means the keyspace is corrupted.
       
   771 	if (error == KErrNone)
       
   772 	    {
       
   773 	    TInt8 reposType = iSimRep->KeyspaceType();
       
   774         if (  (aLocation == EPma      && reposType != EPMAKeyspace)
       
   775             ||(aLocation == EPersists && reposType == EPMAKeyspace)
       
   776             ||(aLocation == EInstall  && reposType == EPMAKeyspace))
       
   777             {
       
   778             error = KErrNotSupported;
       
   779             }
       
   780 	    }
       
   781 
       
   782     if(error==KErrCorrupt || error==KErrNotSupported)
       
   783         {
       
   784 #endif
   720 		// store wasn't quite what we were expecting - can't return an error, can't leave
   785 		// store wasn't quite what we were expecting - can't return an error, can't leave
   721 		// so all we can do is close the file, tidy up as best we can, and return corrupt 
   786 		// so all we can do is close the file, tidy up as best we can, and return corrupt 
   722 		if (aLocation != ERom)
   787 		if (aLocation != ERom)
   723 			{
   788 			{
   724 			// If a debug build - record error
   789 			// If a debug build - record error
   727 				{
   792 				{
   728 				#ifdef _DEBUG
   793 				#ifdef _DEBUG
   729 				RDebug::Print(_L("CSharedRepository::CreateRepositoryFromCreFileL - Failed to delete file. Error = %d"), fileDeleteErr);
   794 				RDebug::Print(_L("CSharedRepository::CreateRepositoryFromCreFileL - Failed to delete file. Error = %d"), fileDeleteErr);
   730 				#endif
   795 				#endif
   731 				}
   796 				}
   732 
   797 #ifdef SYMBIAN_INCLUDE_APP_CENTRIC
       
   798 			else // Protected repository file successfully deleted, so remove it from the PMA array.
       
   799 			    {
       
   800 			    if (aLocation == EPma)
       
   801 			        {
       
   802 			        TInt result = TServerResources::iPMADriveRepositories.FindInOrder( uidToOpen, TLinearOrder<TUid>(TServerResources::CompareUids) );
       
   803 			        if (result != KErrNotFound)
       
   804 			            {
       
   805 			            TServerResources::iPMADriveRepositories.Remove( result );
       
   806 			            }
       
   807 			        }
       
   808 			    }
       
   809 #endif
   733 			}
   810 			}
   734 		}
   811 		}
   735 	else if( error==KErrNoMemory)
   812 	else if( error==KErrNoMemory)
   736 		{
   813 		{
   737 		User::Leave(KErrNoMemory);
   814 		User::Leave(KErrNoMemory);