backupandrestore/backuptest/burtestserver/TestServer/src/t_storagemanager.cpp
changeset 0 d0791faffa3f
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @released
       
    19 */
       
    20 
       
    21 
       
    22 #include "t_storagemanager.h"
       
    23 #include "e32cons.h"
       
    24 #include "e32panic.h"
       
    25 
       
    26 namespace bur_ts
       
    27 	{
       
    28 	CStorageManager* CStorageManager::NewL(const TFileName& aBackupDirName, TDriveList aDriveList, CBURTestStepBase* aTestStep)
       
    29 		/**
       
    30 		Symbian OS Constructor
       
    31 		
       
    32 		@internalComponent
       
    33 		@released
       
    34 		
       
    35 		@param aBackupDirName - Directory to which all backup files are to be stored in 
       
    36 			(or read from during a restore operation).
       
    37 		@param aDriveList - Drives that are being backed up. One subdirectory under per 
       
    38 			drive will be generated under iBackupDirName.
       
    39 		@param aTestStep - A pointer to a CBURTestStepBackup or CBURTestStepRestore that 
       
    40 			owns this object.
       
    41 		
       
    42 		@return Pointer to a newly created CStorageManager object.
       
    43 		*/
       
    44 		{
       
    45 		CStorageManager* self = new (ELeave) CStorageManager(aBackupDirName, aDriveList, aTestStep);
       
    46 		CleanupStack::PushL(self);
       
    47 		self->ConstructL();
       
    48 		CleanupStack::Pop();
       
    49 		return self;
       
    50 		}
       
    51 	
       
    52 	CStorageManager::CStorageManager(const TFileName& aBackupDirName, TDriveList aDriveList, CBURTestStepBase* aTestStep)
       
    53 		/**
       
    54 		C++ Constructor
       
    55 		
       
    56 		@internalComponent
       
    57 		@released
       
    58 		
       
    59 		@param aBackupDirName - Directory to which all backup files are to be stored in 
       
    60 				(or read from during a restore operation).
       
    61 		@param aDriveList - Drives that are being backed up. One subdirectory under per 
       
    62 			drive will be generated under iBackupDirName.
       
    63 		@param aTestStep - A pointer to a CBURTestStepBackup or CBURTestStepRestore that 
       
    64 			owns this object.
       
    65 		*/
       
    66 		:iBackupDirName(aBackupDirName), iDriveList(aDriveList), iTestStep(aTestStep), iLastFile(KNullDesC), iFirstSupply(ETrue), iBytesRead(0) 		
       
    67 		{}
       
    68 	
       
    69 	void CStorageManager::ConstructL()
       
    70 		/**
       
    71 		Symbian OS 2nd phase Constructor
       
    72 		
       
    73 		@internalComponent
       
    74 		@released
       
    75 		*/
       
    76 		{
       
    77 		}
       
    78 	
       
    79 	CStorageManager::~CStorageManager()
       
    80 		/**
       
    81 		C++ Destructor
       
    82 	 	
       
    83 		@internalComponent
       
    84 		@released
       
    85 		*/
       
    86 		{}
       
    87 	
       
    88 	void CStorageManager::ArchiveDataL(CSBGenericTransferType* aTransferType, const TDesC8& aData, TBool aFinished)
       
    89 		/**
       
    90 		Stores data to the archive for the given transfer type
       
    91 		
       
    92 		@internalComponent
       
    93 		@released
       
    94 		
       
    95 		@param aTransferType - A CSBGenericTransferType* containing information about transfer type
       
    96 		@param aData - Data to be stored
       
    97 		
       
    98 		*/
       
    99 		{
       
   100 		__ASSERT_DEBUG(aTransferType != NULL, User::Panic(KBURTestPanicText, ENullTargetPointer));
       
   101 		
       
   102 		TFileName filename;
       
   103 		
       
   104 		if (iFirstSupply && aFinished) //no partial data
       
   105 			{
       
   106 			GetFileNameL(aTransferType, filename, ETrue);		
       
   107 			}
       
   108 		else if (iFirstSupply && !aFinished) // we start to write
       
   109 			{
       
   110 			GetFileNameL(aTransferType, filename, ETrue);
       
   111 			iFirstSupply = EFalse;
       
   112 			}
       
   113 		else if (!iFirstSupply && !aFinished) // we continue
       
   114 			{
       
   115 			filename = iLastFile;
       
   116 			}
       
   117 		else if (!iFirstSupply && aFinished) // we finish
       
   118 			{
       
   119 			filename = iLastFile;
       
   120 			iFirstSupply = ETrue;
       
   121 			}
       
   122 	
       
   123 		// Handle the error case where no name valid was generated!
       
   124 		__ASSERT_DEBUG(filename != _L(""), User::Panic(KBURTestPanicText, KErrBURTestInvalidFileName));
       
   125 		
       
   126 		WriteToDiskL(filename, aData);
       
   127 		
       
   128 		}
       
   129 	
       
   130 	void CStorageManager::RetrieveDataL(CSBGenericTransferType* aTransferType, TDes8& aData, TBool& aFinished, TInt aIndex)
       
   131 		/**
       
   132 		Retrieves data from the backup archive for the given transfer type.
       
   133 		
       
   134 		@internalComponent
       
   135 		@released
       
   136 		
       
   137 		@param aTransferType - A CSBGenericTransferType* containing information about transfer type
       
   138 		@param aErrorCode - Error code to be set on completion
       
   139 		@param aIndex - Index of the increment
       
   140 		
       
   141 		@return Pointer to the retrieved data on the heap
       
   142 		
       
   143 		*/
       
   144 		{
       
   145 		__ASSERT_DEBUG(aTransferType != NULL, User::Panic(KBURTestPanicText, ENullTargetPointer));
       
   146 		
       
   147 		TFileName filename;
       
   148 		GetFileNameL(aTransferType, filename, EFalse, aIndex);
       
   149 		
       
   150 		ReadFromDiskL(filename, aData, aFinished);		
       
   151 		}
       
   152 		
       
   153 	void CStorageManager::Reset()
       
   154 	/**
       
   155 	Resets last name and first supply variables
       
   156 	*/
       
   157 		{
       
   158 		iLastFile = KNullDesC;
       
   159 		iFirstSupply = ETrue;
       
   160 		iBytesRead = 0;
       
   161 		}
       
   162 		
       
   163 	void CStorageManager::GetFileNameL(CSBGenericTransferType* aTransferType, TFileName& aFileName, TBool aBackup, TInt aIndex)
       
   164 		/**
       
   165 		Creates the name of the file depending on its type
       
   166 	
       
   167 		@intenalComponent
       
   168 		@released
       
   169 	
       
   170 		@param aTransferType - A CSBGenericTransferType contains information about transfer type
       
   171 		@param aFileName - reference to a TFileName
       
   172 		@param aBackup - is it Backup or Restore
       
   173 		@param aIndex - index of increment (currently not supported)
       
   174 		
       
   175 		*/
       
   176 		{
       
   177 		__ASSERT_DEBUG(aTransferType != NULL, User::Panic(KBURTestPanicText, ENullTargetPointer));
       
   178 		TSBDerivedType derivedType = aTransferType->DerivedTypeL();
       
   179 		
       
   180 		if (derivedType == ESIDTransferDerivedType)
       
   181 			{
       
   182 			CSBSIDTransferType* type = CSBSIDTransferType::NewL(aTransferType);
       
   183 			CleanupStack::PushL(type);
       
   184 				
       
   185 			GetSIDFileNameL(type, aFileName);
       
   186 		
       
   187 			TTransferDataType  dataType = type->DataTypeL();
       
   188 		
       
   189 			if (dataType == EActiveIncrementalData || dataType == EPassiveIncrementalData )
       
   190 				{
       
   191 				aFileName.Append(KIncrement);
       
   192 				if (aBackup)
       
   193 					{
       
   194 					GenerateIncNumber(TotalIncFiles(type)+1, aFileName);
       
   195 					//GenerateIncNumber(TotalIncFiles(type)+1, aFileName);
       
   196 					}
       
   197 				else
       
   198 					{
       
   199 					GenerateIncNumber(aIndex, aFileName);
       
   200 					}
       
   201 				aFileName.Append(KBackupExtn);	
       
   202 				}
       
   203 			
       
   204 			CleanupStack::PopAndDestroy(type);
       
   205 			}
       
   206 				
       
   207 		else if (derivedType == EPackageTransferDerivedType)
       
   208 			{
       
   209 			CSBPackageTransferType* pkgType = CSBPackageTransferType::NewL(aTransferType);
       
   210 			CleanupStack::PushL(pkgType);
       
   211 				
       
   212 			GetPIDFileNameL(pkgType, aFileName);
       
   213 			
       
   214 			CleanupStack::PopAndDestroy(pkgType);
       
   215  			}
       
   216  		else if (derivedType == EJavaTransferDerivedType)
       
   217  			{
       
   218  			CSBJavaTransferType* javaType = CSBJavaTransferType::NewL(aTransferType);
       
   219  			CleanupStack::PushL(javaType);
       
   220  			
       
   221  			GetJavaFileNameL(javaType, aFileName);
       
   222  			
       
   223  			CleanupStack::PopAndDestroy(javaType);
       
   224  			}
       
   225 		}
       
   226 		
       
   227 	void CStorageManager::GetPIDFileNameL(CSBPackageTransferType* aTransferType, TFileName& aFileName)
       
   228 		/**
       
   229 		Generates file name for the PID
       
   230 		
       
   231 		@param aTransferType - A CSBPackageTransferType contains info about Package Type
       
   232 		@param aFileName - Reference to a filename
       
   233 		
       
   234 		*/
       
   235 		{
       
   236 		__ASSERT_DEBUG(aTransferType != NULL, User::Panic(KBURTestPanicText, ENullTargetPointer));
       
   237 		TUid id;
       
   238 		TChar drive;
       
   239 		TDriveNumber driveNumber;
       
   240 		TPackageDataType pkgType;
       
   241 		
       
   242 		id = aTransferType->PackageIdL();
       
   243 		pkgType = aTransferType->DataTypeL();
       
   244 		driveNumber = aTransferType->DriveNumberL();
       
   245 		
       
   246 		//Get the drive letter
       
   247 		iTestStep->Fs().DriveToChar(driveNumber, drive);
       
   248 		
       
   249 		switch(pkgType)
       
   250 			{
       
   251 			case ESystemData:
       
   252 				GetSIDPrivateDirName(drive, id, aFileName);
       
   253 				aFileName.Append(KData);
       
   254 				aFileName.Append(KBackupExtn);
       
   255 				break;
       
   256 			case ESystemSnapshotData:
       
   257 				GetSIDPrivateDirName(drive, id, aFileName);
       
   258 				aFileName.Append(KSnapshot);
       
   259 				aFileName.Append(KBackupExtn);
       
   260 				break;
       
   261 			}
       
   262 		}
       
   263 		
       
   264 	void CStorageManager::GetJavaFileNameL(CSBJavaTransferType* aTransferType, TFileName& aFileName)
       
   265 		/**
       
   266 		Concatenates the name of the backup file from the information found in aTransferType.
       
   267 		
       
   268 		
       
   269 		@param 	aTransferType - A CSBJavaTransferType* containing information about the 
       
   270 					type of file name that needs be returned.
       
   271 			
       
   272 		@param TFilename of the backup file generated in line with the 
       
   273 				implemented naming scheme
       
   274 		*/
       
   275 		{
       
   276 		const TDesC& suiteHash = aTransferType->SuiteHashL();
       
   277 		TDriveNumber driveNumber = aTransferType->DriveNumberL();
       
   278 		TJavaTransferType javaType = aTransferType->DataTypeL();
       
   279 		
       
   280 		TChar drive;
       
   281 		
       
   282 		iTestStep->Fs().DriveToChar(driveNumber, drive);
       
   283 		
       
   284 		// we can't create a TSecureID from suiteHash therefore need to duplicate GetSIDPrivateDir Method
       
   285 		GetJavaPrivateDirName(drive, suiteHash, aFileName);
       
   286 		
       
   287 		switch(javaType)
       
   288 			{
       
   289 			case EJavaMIDlet:
       
   290 				aFileName.Append(KMidlet);
       
   291 				aFileName.Append(KBackupExtn);
       
   292 				break;
       
   293 			case EJavaMIDletData:
       
   294 				aFileName.Append(KData);
       
   295 				aFileName.Append(KBackupExtn);
       
   296 				break;
       
   297 			}
       
   298 		}
       
   299 	
       
   300 	void CStorageManager::GetSIDFileNameL(CSBSIDTransferType* aTransferType, TFileName& aFileName)
       
   301 		/**
       
   302 		Concatenates the name of the backup file from the information found in aTransferType.
       
   303 		
       
   304 		@internalComponent
       
   305 		@released
       
   306 		
       
   307 		@param 	aTransferType - A CSBSIDTransferType* containing information about the 
       
   308 				type of file name that needs be returned.
       
   309 		
       
   310 		@param TFilename of the backup file generated in line with the 
       
   311 				implemented naming scheme
       
   312 				
       
   313 		*/
       
   314 		{
       
   315 		__ASSERT_DEBUG(aTransferType != NULL, User::Panic(KBURTestPanicText, ENullTargetPointer));
       
   316 		TSecureId sid;
       
   317 		TChar drive;
       
   318 		TDriveNumber driveNumber;
       
   319 		TTransferDataType dataType;
       
   320 		
       
   321 		sid = aTransferType->SecureIdL();
       
   322 		dataType = aTransferType->DataTypeL();
       
   323 		driveNumber = aTransferType->DriveNumberL();
       
   324 		
       
   325 		// Get the drive letter
       
   326 		iTestStep->Fs().DriveToChar(driveNumber, drive);
       
   327 		
       
   328 		switch(dataType)
       
   329 			{
       
   330 			case ERegistrationData:
       
   331 				{
       
   332 				GetSIDPrivateDirName(drive, sid, aFileName);
       
   333 				aFileName.Append(KRegFilesDir);
       
   334 				aFileName.AppendNumUC(sid, EHex);
       
   335 				aFileName.Append(KBackupExtn);
       
   336 				break;
       
   337 				}
       
   338 				// No need to create this directory, as it's done in SetupDirs():
       
   339 			case EPassiveSnapshotData:
       
   340 				{
       
   341 				GetSIDPrivateDirName(drive, sid, aFileName);
       
   342 				aFileName.Append(KPassiveDataDir);
       
   343 				aFileName.Append(KSnapshotDataDir);
       
   344 				aFileName.Append(KSnapshot);
       
   345 				aFileName.Append(KBackupExtn);
       
   346 				break;
       
   347 				}
       
   348 			case EPassiveBaseData:
       
   349 				{
       
   350 				GetSIDPrivateDirName(drive, sid, aFileName);
       
   351 				aFileName.Append(KPassiveDataDir);
       
   352 				aFileName.Append(KBaseDataDir);
       
   353 				aFileName.Append(KData);
       
   354 				aFileName.Append(KBackupExtn);
       
   355 				break;
       
   356 				} 
       
   357 			case EPassiveIncrementalData :
       
   358 				{
       
   359 				GetSIDPrivateDirName(drive, sid, aFileName);
       
   360 				aFileName.Append(KPassiveDataDir);
       
   361 				aFileName.Append(KIncrementalDataDir);
       
   362 				break;
       
   363 				}
       
   364 			case EActiveSnapshotData:
       
   365 				{
       
   366 				GetSIDPrivateDirName(drive, sid, aFileName);
       
   367 				aFileName.Append(KActiveDataDir);
       
   368 				aFileName.Append(KSnapshotDataDir);
       
   369 				aFileName.Append(KSnapshot);
       
   370 				aFileName.Append(KBackupExtn);
       
   371 				break;
       
   372 				}
       
   373 			case EActiveBaseData:
       
   374 				{
       
   375 				GetSIDPrivateDirName(drive, sid, aFileName);
       
   376 				aFileName.Append(KActiveDataDir);
       
   377 				aFileName.Append(KBaseDataDir);
       
   378 				aFileName.Append(KData);
       
   379 				aFileName.Append(KBackupExtn);
       
   380 				break;
       
   381 				}
       
   382 			case EActiveIncrementalData:
       
   383 				{
       
   384 				GetSIDPrivateDirName(drive, sid, aFileName);
       
   385 				aFileName.Append(KActiveDataDir);
       
   386 				aFileName.Append(KIncrementalDataDir);
       
   387 				break;
       
   388 				}
       
   389 			default:
       
   390 				{
       
   391 				User::Leave(KErrArgument);
       
   392 				break;
       
   393 				}
       
   394 			}
       
   395 		
       
   396 		}
       
   397 	
       
   398 	
       
   399 	void CStorageManager::GetSIDPrivateDirName(TChar aDrive, TSecureId aSID, TFileName& aFileName) const
       
   400 		/**
       
   401 		Gets the name of the directory where the private data is to stored:\n
       
   402 		\<backup directory>\\KPrivateDirName\\<aSID>\\
       
   403 		
       
   404 		@internalComponent
       
   405 		@released
       
   406 		
       
   407 		@param aDrive - The drive letter of the drive where data resides.
       
   408 		@param aSID - SID the data belonds to.
       
   409 		
       
   410 		@param aFileName - Directory name of the given SID's private directory, generated in 
       
   411 				line with the implemented naming scheme.
       
   412 		*/
       
   413 		{
       
   414 		aFileName = iBackupDirName;
       
   415 		aFileName.AppendNumUC(aSID, EHex);
       
   416 		aFileName.Append(KSlash);
       
   417 		aFileName.Append(aDrive);
       
   418 		aFileName.Append(KSlash);
       
   419 		}
       
   420 		
       
   421 	void CStorageManager::GetJavaPrivateDirName(TChar aDrive, const TDesC& aSuiteHash, TFileName& aFileName)
       
   422 		/**
       
   423 		Gets the name of the directory where the private data is to stored:\n
       
   424 		\<backup directory>\\KPrivateDirName\\<aSID>\\
       
   425 		
       
   426 		@internalComponent
       
   427 		@released
       
   428 		
       
   429 		@param aDrive - The drive letter of the drive where data resides.
       
   430 		@param aSuiteHash - Suite Hash the data belonds to.
       
   431 		
       
   432 		@param aFileName name of the given suite hash private directory, generated in line with the implemented naming scheme.
       
   433 		*/
       
   434 		{
       
   435 		aFileName = iBackupDirName;
       
   436 		aFileName.Append(aSuiteHash);
       
   437 		aFileName.Append(KSlash);
       
   438 		aFileName.Append(aDrive);
       
   439 		aFileName.Append(KSlash);
       
   440 		}
       
   441 		
       
   442 	TInt CStorageManager::TotalIncFiles(CSBSIDTransferType* aTransferType)
       
   443 		/**
       
   444 		Returns number of Files in the directory for SID TransferType
       
   445 		
       
   446 		@param aTransferType - CSBSIDTransferType* pointer
       
   447 		*/
       
   448 		{
       
   449 		__ASSERT_DEBUG(aTransferType != NULL, User::Panic(KBURTestPanicText, ENullTargetPointer));
       
   450 		CDir* dir = NULL;
       
   451 		TFileName filename;
       
   452 		GetSIDFileNameL(aTransferType, filename);
       
   453 		TInt err = iTestStep->Fs().GetDir(filename, KEntryAttMaskSupported, ESortByName, dir);
       
   454 		if (err != KErrNone)
       
   455 			{
       
   456 			return 0;
       
   457 			}
       
   458 		return dir->Count();
       
   459 		}
       
   460 			
       
   461 	void CStorageManager::GenerateIncNumber(TInt aIndex, TDes& aDes)
       
   462 		/**
       
   463 		Generates number from int to string in range 0 - 999
       
   464 		
       
   465 		@param aIndex - Number
       
   466 		@param aDes - A Descriptor
       
   467 		*/
       
   468 	
       
   469 		{
       
   470 		if (aIndex <= 9)
       
   471 			{
       
   472 			aDes.AppendNum(0);
       
   473 			aDes.AppendNum(0);
       
   474 			aDes.AppendNum(aIndex);
       
   475 			}
       
   476 		else if (aIndex <= 99)
       
   477 			{
       
   478 			aDes.AppendNum(0);
       
   479 			aDes.AppendNum(aIndex);
       
   480 			}
       
   481 		else if (aIndex <= 999)
       
   482 			{
       
   483 			aDes.AppendNum(aIndex);
       
   484 			}
       
   485 		else
       
   486 			{
       
   487 			_LIT(KPanic1, "Number greater then 999 ");
       
   488 			User::Panic(KPanic1, KErrNotSupported);
       
   489 			}
       
   490 		}
       
   491 
       
   492 		
       
   493 	void CStorageManager::SaveDataOwnerL(CDataOwnerInfo& aDataOwner)
       
   494 		/**
       
   495 		Saves data for DataOwner
       
   496 		
       
   497 		@param aDataOwner - DataOwner to be saved
       
   498 		
       
   499 		*/
       
   500 
       
   501 		{		
       
   502 		CDir* dir = NULL;
       
   503 		TFileName filename;
       
   504 		filename.Append(iBackupDirName);
       
   505 		filename.Append(KDataOwnerDir);
       
   506 		iTestStep->Fs().MkDirAll(filename);
       
   507 		_LIT(KPid, "pid");
       
   508 		_LIT(KSid, "sid");
       
   509 		_LIT(KJid, "jid");
       
   510 		
       
   511 		
       
   512 		TSBDerivedType type;
       
   513 		type = aDataOwner.Identifier().DerivedTypeL();
       
   514 		
       
   515 		if (type == ESIDDerivedType)
       
   516 			{
       
   517 			CSBSecureId* sid = CSBSecureId::NewL(&(aDataOwner.Identifier()));
       
   518 			CleanupStack::PushL(sid);
       
   519 			filename.Append(KSid);
       
   520 			filename.AppendNumUC(sid->SecureIdL(), EHex);
       
   521 			CleanupStack::PopAndDestroy(sid);
       
   522 			}
       
   523 		else if (type == EPackageDerivedType)
       
   524 			{
       
   525 			CSBPackageId* pid = CSBPackageId::NewL(&(aDataOwner.Identifier()));
       
   526 			CleanupStack::PushL(pid);
       
   527 			filename.Append(KPid);
       
   528 			filename.AppendNumUC(pid->PackageIdL().iUid, EHex);
       
   529 			CleanupStack::PopAndDestroy(pid);
       
   530 			}
       
   531 		else if (type == EJavaDerivedType)
       
   532 			{
       
   533 			CSBJavaId* jid = CSBJavaId::NewL(&(aDataOwner.Identifier()));
       
   534 			CleanupStack::PushL(jid);
       
   535 			filename.Append(KJid);
       
   536 			filename.Append(jid->SuiteHashL());
       
   537 			CleanupStack::PopAndDestroy(jid);
       
   538 			}
       
   539 		
       
   540 		filename.Append(KBackupExtn);
       
   541 		//HBufC8* data = HBufC8::NewLC(aDataOwner.Size());
       
   542 		
       
   543 		HBufC8* data = aDataOwner.ExternaliseLC();
       
   544 		WriteToDiskL(filename, *data);
       
   545 		CleanupStack::PopAndDestroy(data);
       
   546 		delete dir;
       
   547 		dir = NULL;
       
   548 		}
       
   549 		
       
   550 	void CStorageManager::WriteToDiskL(TFileName& aFile, const TDesC8& aData)
       
   551 		/**
       
   552 		Writes data to disk
       
   553 		
       
   554 		@param aFile - file to write to
       
   555 		@param aData - data to write
       
   556 		
       
   557 		*/
       
   558 		{
       
   559 		RFile file;
       
   560 		// Place on the cleanup stack:
       
   561 		CleanupClosePushL(file);
       
   562 		TInt error = iTestStep->Fs().MkDirAll(aFile);
       
   563 		
       
   564 		if (error == KErrAlreadyExists || error == KErrNone) // directory exists
       
   565 			{
       
   566 			if (iLastFile == aFile) // more data needs appended to already open file
       
   567 				{
       
   568 				error = file.Open(iTestStep->Fs(), aFile, EFileWrite);	
       
   569 				}
       
   570 			else 
       
   571 				{
       
   572 				error = file.Replace(iTestStep->Fs(), aFile, EFileWrite);
       
   573 				}
       
   574 			}
       
   575 		if (error != KErrNone)
       
   576 			{
       
   577 			CleanupStack::PopAndDestroy(&file); // file
       
   578 			User::Leave(error)	;
       
   579 			}
       
   580 		
       
   581 		TInt size = NULL;
       
   582 		file.Size(size);
       
   583 		error = file.Write(size, aData);
       
   584 		file.Flush();
       
   585 		
       
   586 		iLastFile = aFile;	
       
   587 			
       
   588 		CleanupStack::PopAndDestroy(&file); // file
       
   589 		User::LeaveIfError(error);
       
   590 		}
       
   591 		
       
   592 	void CStorageManager::ReadFromDiskL(TFileName& aFile, TDes8& aData, TBool& aFinished)
       
   593 		/**
       
   594 		Read data from a disk
       
   595 		
       
   596 		@param aFile - file to read
       
   597 		@param aData - reference to a buffer to put the data from a file
       
   598 		
       
   599 		*/
       
   600 		{
       
   601 		RFile file;
       
   602 		CleanupClosePushL(file);
       
   603 				
       
   604 		TInt err = file.Open(iTestStep->Fs(), aFile, EFileRead);
       
   605 		if (err != KErrNone)
       
   606 			{
       
   607 			CleanupStack::PopAndDestroy(&file);
       
   608 			User::Leave(err);
       
   609 			}
       
   610 		
       
   611 		TInt size;
       
   612 		file.Size(size);
       
   613 		
       
   614 		TInt availableSpace = aData.MaxLength() - aData.Length();
       
   615 		
       
   616 		if (availableSpace - (size - iBytesRead) >= 0)
       
   617 			{
       
   618 			aFinished = ETrue;
       
   619 			}
       
   620 		else
       
   621 			{
       
   622 			aFinished = EFalse;	
       
   623 			}
       
   624 		
       
   625 		err = file.Read(iBytesRead, aData);
       
   626 		file.Flush();
       
   627 		CleanupStack::PopAndDestroy(&file);
       
   628 		
       
   629 		User::LeaveIfError(err);
       
   630 		
       
   631 		if (aFinished)
       
   632 			{
       
   633 			iBytesRead = 0;
       
   634 			}
       
   635 		else
       
   636 			{
       
   637 			iBytesRead += availableSpace;
       
   638 			}
       
   639 		}
       
   640 		
       
   641 	void CStorageManager::ReadDataOwnersFromDiskL(RDataOwnerArray& aArray)
       
   642 		/**
       
   643 		Reads Data Owners from a storage
       
   644 		
       
   645 		@param aArray - RDataOwnerArray will contain dataowners found in storage
       
   646 		
       
   647 		*/
       
   648 
       
   649 		{
       
   650 		aArray.ResetAndDestroy();
       
   651 		CDir* dir = NULL;
       
   652 		TFileName filename = iBackupDirName;
       
   653 		filename.Append(KDataOwnerDir);
       
   654 		User::LeaveIfError(iTestStep->Fs().GetDir(filename, KEntryAttMaskSupported, ESortByName, dir));
       
   655 		TInt totalFiles = dir->Count();
       
   656 		
       
   657 		for (TInt index = 0; index < totalFiles; index++)
       
   658 			{
       
   659 			TFileName file = filename;
       
   660 			TEntry entry = (*dir)[index];
       
   661 			file.Append(entry.iName);
       
   662 			HBufC8* data = HBufC8::NewLC(entry.iSize);
       
   663 			TPtr8 pData = data->Des();
       
   664 			TBool ignore;
       
   665 			TRAPD(err, ReadFromDiskL(file, pData, ignore));
       
   666 			if (err != KErrNone)
       
   667 				{
       
   668 				_LIT(KLog1, "Error opening file: ");
       
   669 				iTestStep->LogWithText(LOG_LEVEL2, KLog1, file);
       
   670 				CleanupStack::PopAndDestroy(data);
       
   671 				continue;
       
   672 				}
       
   673 			CDataOwnerInfo* dataOwner = CDataOwnerInfo::NewL(pData);
       
   674 			CleanupStack::PushL(dataOwner);
       
   675 			aArray.AppendL(dataOwner);
       
   676 			CleanupStack::Pop(dataOwner);
       
   677 			CleanupStack::PopAndDestroy(data);
       
   678 			}
       
   679 		}
       
   680 	
       
   681 	TBool CStorageManager::IsFileExists(TFileName& aFileName)
       
   682 		/**
       
   683 		Is File Exists in the File System
       
   684 		
       
   685 		@param aFileName File Name of the file to check
       
   686 		
       
   687 		@return ETrue if exists
       
   688 		*/
       
   689 		{
       
   690 		TEntry entry;
       
   691 		TInt err = iTestStep->Fs().Entry(aFileName, entry);
       
   692 		if (err == KErrNone)
       
   693 			{
       
   694 			return ETrue;
       
   695 			}
       
   696 		else
       
   697 			{
       
   698 			return EFalse;
       
   699 			}
       
   700 		}
       
   701 	
       
   702 	}	// end namespace