LOCAL_C void StartupUpgradeL(TBool aIsSetup)
{
	if(aIsSetup)
		{
		// Set up files for test
		RFs fs;
		User::LeaveIfError(fs.Connect());
		CleanupClosePushL(fs);
		CFileMan* fm = CFileMan::NewL(fs);
		CleanupStack::PushL(fm);

		// Clean out files
		TInt err=fs.Delete(KInstallDirFile);
		if((err!=KErrNone)&&(err!=KErrNotFound))
			User::Leave(err);

		// Cause directory listing with no files to be written
		CCentRepSWIWatcher*	swiWatcher = CCentRepSWIWatcher::NewL(TServerResources::iFs);
		delete swiWatcher;

		User::LeaveIfError(fm->Copy(KPersistsFileNoUpgrade, KPersistsFile));
		User::LeaveIfError(fm->Attribs(KPersistsFile,0,KEntryAttReadOnly,TTime(0)));

		User::LeaveIfError(fm->Copy(KRomUpgradeRev1File, KUpgradeFile));
		User::LeaveIfError(fm->Attribs(KUpgradeFile,0,KEntryAttReadOnly,TTime(0)));

		CleanupStack::PopAndDestroy(2); // fs and fm
		}
	else
		{
		CCentRepSWIWatcher*	swiWatcher = CCentRepSWIWatcher::NewL(TServerResources::iFs);
		delete swiWatcher;
		}
}
LOCAL_C void StartupUninstallL(TBool aIsSetup)
{
	if(aIsSetup)
		{
		RFs fs;
		User::LeaveIfError(fs.Connect());
		CleanupClosePushL(fs);
		CFileMan* fm = CFileMan::NewL(fs);
		CleanupStack::PushL(fm);

		// Copy rev 1 file into install dir & Reset read-only bit
		User::LeaveIfError(fm->Copy(KInstallOnlyFile, KInstallFile));
		User::LeaveIfError(fm->Attribs(KInstallFile,0,KEntryAttReadOnly,TTime(0)));

		// Cause directory listing to be written and file to be installed
		CCentRepSWIWatcher*	swiWatcher = CCentRepSWIWatcher::NewL(TServerResources::iFs);
		delete swiWatcher;

		// Create a persists file that will be deleted
		User::LeaveIfError(fm->Copy(KPersistsFileUpgraded, KInstallPersistsFile));
		User::LeaveIfError(fm->Attribs(KInstallPersistsFile,0,KEntryAttReadOnly,TTime(0)));

		TInt err=fs.Delete(KInstallFile);
		if((err!=KErrNone)&&(err!=KErrNotFound))
			User::Leave(err);

		CleanupStack::PopAndDestroy(2); // fs and fm
		}
	else
		{
		CCentRepSWIWatcher*	swiWatcher = CCentRepSWIWatcher::NewL(TServerResources::iFs);
		delete swiWatcher;
		}
}
void CenrepSwiOOMTest::UninstallL(TBool aIsSetup)
	{
	if(aIsSetup)
		{
		// Install upgrade
		UpgradeInstallL(ETrue);
		UpgradeInstallL(EFalse);

		RFs fs;
		User::LeaveIfError(fs.Connect());
		CleanupClosePushL(fs);
		CFileMan* fm = CFileMan::NewL(fs);
		CleanupStack::PushL(fm);

		// Delete file from install dir
		User::LeaveIfError(fm->Attribs(KInstallFile,0,KEntryAttReadOnly,TTime(0)));
		TInt err=fs.Delete(KInstallFile);
		if((err!=KErrNone)&&(err!=KErrNotFound))
			User::Leave(err);

		// Create a cre persists file, doesn't matter what's in it, it should be deleted
		User::LeaveIfError(fm->Copy(KPersistsFileUpgraded, KInstallPersistsFile));
		User::LeaveIfError(fm->Attribs(KInstallPersistsFile,0,KEntryAttReadOnly,TTime(0)));

		CleanupStack::PopAndDestroy(2); // fs and fm
		}
	else
		{
		iSwiWatcher->HandleSWIEventL(ESASwisUninstall | ESASwisStatusSuccess);
		}
	}
TInt CSecMgrStore::RestoreTempPolicy(TPolicyID aPolicyID)
{
	HBufC *policyFile = HBufC::NewLC(KMaxName);
	TPtr policyFilePtr(policyFile->Des());
	
	HBufC *tempPolicyFile = HBufC::NewLC(KMaxName);
	TPtr tempPolicyFilePtr(tempPolicyFile->Des());
	
	TInt ret(GetPolicyFile(policyFilePtr, aPolicyID));

	ret= GetPolicyPath (tempPolicyFilePtr);

	if ( (KErrNone==ret) || (KErrAlreadyExists==ret))
	{
		HBufC *fPolicyName = HBufC::NewLC(KMaxName);
		TPtr policyNamePtr(fPolicyName->Des());
		policyNamePtr.Num (aPolicyID);

		tempPolicyFilePtr.Append (policyNamePtr);
		tempPolicyFilePtr.Append (_L("_temp"));
		tempPolicyFilePtr.Append (KDatExtn);
		
		CleanupStack::PopAndDestroy(fPolicyName);
	}
	
	CFileMan *fm = CFileMan::NewL(iFsSession);
	TInt restoreResult = fm->Copy(tempPolicyFilePtr, policyFilePtr, CFileMan::EOverWrite);
	delete fm;
	
	CleanupStack::PopAndDestroy(tempPolicyFile);
	CleanupStack::PopAndDestroy(policyFile);
	return restoreResult;
}
void CSmsSendRecvTest::TestAddBifL(const TDesC& aBifName)
{
    iSmsTest.Printf(_L("\tAdd BIF: %S\n"), &aBifName);

    RFs& fs = iSmsTest.FileSession();
    TInt err = fs.MkDir(KBifDir);

    if (err != KErrAlreadyExists)
        User::LeaveIfError(err);

    TParse fileOut;
    err = iSmsTest.ResolveFile(KSmsComponent, aBifName, fileOut);

    if (err)
    {
        iSmsTest.Printf(_L("Test BIF %S not found! Continuing without this test\n"), &aBifName);
        return;
    }

    CFileMan* fileMan = CFileMan::NewL(fs);
    CleanupStack::PushL(fileMan);

    err = fileMan->Copy(fileOut.FullName(), KBifDir);

    if (err != KErrAlreadyExists)
        User::LeaveIfError(err);

    CleanupStack::PopAndDestroy(fileMan);

    User::After(KBifWait);
}
Example #6
0
// ---------------------------------------------------------
// CPosTp16::UseContactDbL
// 
// (other items were commented in a header).
// ---------------------------------------------------------
//
CPosLandmarkDatabase* CPosTp16::UseContactDbL()
    {
    RemoveDefaultDbL();
    
    #ifdef __WINS__
        _LIT(KCorruptDbFile, "z:\\system\\test\\testdata\\SRVeposcontact.ldb");
    #else
        _LIT(KCorruptDbFile, "c:\\system\\test\\testdata\\SRVeposcontact.ldb");
    #endif
    
    _LIT(KCorruptDbFileOld, "c:\\system\\data\\SRVeposcontact.ldb");

    RFs fs;
    User::LeaveIfError(fs.Connect());
    CleanupClosePushL(fs);
    
    CFileMan* fileMan = CFileMan::NewL(fs);
    CleanupStack::PushL(fileMan);
    
    User::LeaveIfError(fileMan->Copy(KCorruptDbFile, KDefaultDbPath, CFileMan::EOverWrite));
    User::LeaveIfError(fileMan->Rename(KCorruptDbFileOld, KDefaultDb, CFileMan::EOverWrite));
    
    CleanupStack::PopAndDestroy(2, &fs);
    
    return CPosLandmarkDatabase::OpenL();
    }
/**
  * Copy the exported file attachments from ROM to RAM drive
  */
void CTestCalInterimApiSuiteStepBase::CopyImportFileToWritableDriveL()
	{
	CFileMan* fileCopier = CFileMan::NewL(iFsSession);
	CleanupStack::PushL(fileCopier);

	TPtrC	file;
	GetStringFromConfig(ConfigSection(), KInitialLocationOfFile, file);

	RArray<TPtrC>	fileList;
	CleanupClosePushL(fileList);
	TokenizeStringL(file, fileList);

	// Iterate through the file list and copy them from z drive to c drive
	for ( TInt i = 0; i < fileList.Count(); i++ )
		{
		TFileName initialLocationOfFile = fileList[i];
		initialLocationOfFile.Insert(0, KOriginalDrive());
		// get current time
		TTime now;
		now.HomeTime();
		// clear any read only attribute if the file is present such we avoid errors at copy time
		fileCopier->Attribs(fileList[i], 0, KEntryAttReadOnly, now);
		User::LeaveIfError(fileCopier->Copy(initialLocationOfFile, fileList[i], CFileMan::EOverWrite|CFileMan::ERecurse));
		// clear any read only attribute such we avoid errors at open time (true on real hardware)
		User::LeaveIfError(fileCopier->Attribs(fileList[i], 0, KEntryAttReadOnly, now));
		}

	CleanupStack::PopAndDestroy(&fileList);
	CleanupStack::PopAndDestroy(fileCopier);
	}
void CenrepSwiOOMTest::UpgradeInstallL(TBool aIsSetup)
	{
	if(aIsSetup)
		{
		// Install file
		InstallL(ETrue);
		InstallL(EFalse);

		RFs fs;
		User::LeaveIfError(fs.Connect());
		CleanupClosePushL(fs);
		CFileMan* fm = CFileMan::NewL(fs);
		CleanupStack::PushL(fm);

		// Get modification time
		TTime time;
		TBuf<50> fileName(KInstallFile);
		fs.Modified(fileName, time);

		// Copy upgrade file into install dir & Reset read-only bit
		User::LeaveIfError(fm->Copy(KInstallOnlyUpgradeFile, KInstallFile));
		User::LeaveIfError(fm->Attribs(KInstallFile,0,KEntryAttReadOnly,TTime(0)));
		// Modify timestamp to cause upgrade
		ModifyTimeStampL(fs,&fileName, time);

		CleanupStack::PopAndDestroy(2); // fs and fm
		}
	else
		{
		iSwiWatcher->HandleSWIEventL(ESASwisInstall | ESASwisStatusSuccess);
		}
	}
Example #9
0
// ---------------------------------------------------------
// CPosTp29::CopyResourceFileL
// 
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPosTp29::CopyResourceFileL(const TDesC& aResourceFile)
    {
    // Release all landmark references to make DLLs be unloaded.
    delete iLandmarksDb;
    iLandmarksDb = NULL;

    CFileMan* fileMan = CFileMan::NewL(iFileServer);
    CleanupStack::PushL(fileMan);
    
    // Check if landmark is flashed
     if (!BaflUtils::FileExists(iFileServer, KInternalServicesResFileRom))
        {
         iLog->Put(_L("Landmark is NOT flashed, backing up eposlmintservices.rsc by renaming it bofore copying rsc-file."));
        // Landmark FW is not flashed. Rename the file before copying an own defiend file.
        // Since landmark FW is not flashed the file should exist hence leaving if it is not found!
         User::LeaveIfError(fileMan->Rename(KInternalServicesResFileCdrive, KInternalServicesResFileBackup, CFileMan::EOverWrite));
        }
     else
        {
        iLog->Put(_L("Landmark framework is flashed, copying global categories to c:"));
        }

    User::LeaveIfError(fileMan->Copy(aResourceFile, KInternalServicesResFileCdrive, CFileMan::EOverWrite));
 
    CleanupStack::PopAndDestroy(fileMan);
    }
void CTcFileHandlerSession::DoCopyFileL( const RMessage2& aMessage ) const
    {
    TFileName sourcePath;
    ReadFileNameL( 0, aMessage, sourcePath );
    
    TFileName destinationPath;
    ReadFileNameL( 1, aMessage, destinationPath );
   	
    RFs fs;
	User::LeaveIfError( fs.Connect() );
	CleanupClosePushL( fs );
	
	CFileMan* fileMan = CFileMan::NewL(fs);
	CleanupStack::PushL(fileMan); 
	
	// Make sure path exists, ignore errors since path might exist already
	fs.MkDirAll( destinationPath );	
	
	// Make the destination file writeable, ignore errors since most probably
	// file doesn't exist yet
    fileMan->Attribs( destinationPath, 0, KEntryAttReadOnly, TTime( 0 ), 0 );
    
	User::LeaveIfError( fileMan->Copy( sourcePath, destinationPath ) );
    
	CleanupStack::PopAndDestroy( 2 ); // fileMan, fs
    }
void CopyDbFromROMToSystemL(RFs& aFs, const TDesC& aTargetPath)
	{
	CFileMan* fileManager = CFileMan::NewL(aFs);
	CleanupStack::PushL(fileManager);
	User::LeaveIfError(fileManager->Copy(KScrDbRomPath, aTargetPath, 0));

	// Reset the read-only attribute on the copied file
	User::LeaveIfError(aFs.SetAtt(aTargetPath, 0, KEntryAttReadOnly));
	CleanupStack::PopAndDestroy(fileManager);
	}
void DscDatabaseRestoreL()
	{
	// Restore DBMS / SQL data store backups available prior to running the test
	//		(if failures are reported, this may indicate that the ddbb didn't previously exist - should not be a problem)
	RFs fs;
	CleanupClosePushL(fs);
	User::LeaveIfError(fs.Connect());
	
	CFileMan* fileMan; 
	fileMan = CFileMan::NewL(fs);
	CleanupStack::PushL(fileMan);
	
	// DBMS ddbb
	RDebug::Print(_L("*** DscDatabaseBackupL(): Restore DBMS data store backup available prior to running the test"));
	TEntry fileEntry;
	TInt err = fs.Entry(KDbmsDscDdbbOriginal, fileEntry);
	if(KErrNone == err)
		{
		User::LeaveIfError(fs.Delete(KDbmsDscDdbbOriginal));
		}
	err = fs.Entry(KDbmsDscDdbbBackup, fileEntry);
	if(KErrNone == err)
		{
		User::LeaveIfError(fileMan->Copy(KDbmsDscDdbbBackup, KDbmsDscDdbbOriginal));
		User::LeaveIfError(fs.Delete(KDbmsDscDdbbBackup));
		}

	// SQL ddbb
	RDebug::Print(_L("*** DscDatabaseBackupL(): Restore SQL data store backup available prior to running the test"));
	err = fs.Entry(KSqlDscDdbbOriginal, fileEntry);
	if(KErrNone == err)
		{
		User::LeaveIfError(fs.Delete(KSqlDscDdbbOriginal));
		}
	err = fs.Entry(KSqlDscDdbbBackup, fileEntry);
	if(KErrNone == err)
		{
		User::LeaveIfError(fileMan->Copy(KSqlDscDdbbBackup, KSqlDscDdbbOriginal));
		User::LeaveIfError(fs.Delete(KSqlDscDdbbBackup));
		}
	CleanupStack::PopAndDestroy(fileMan);
	CleanupStack::PopAndDestroy(&fs);
	}
void CObexFileDebugReceiveState::StartL(TRequestStatus& aStatus)
    {
    CFileMan* fileMan = CFileMan::NewL(iClientTest.ObexTestUtils().iMsvSession->FileSession());
    CleanupStack::PushL(fileMan);                                               // PUSH
    User::LeaveIfError(fileMan->Copy(iSource, iDestination));
    CleanupStack::PopAndDestroy(); // fileMan                                   // POP(1)

    TRequestStatus* status = &aStatus;
	User::RequestComplete(status, KErrNone);
    }
/**
Set the current default Contacts database drive and optionally moves the
default Contacts database from the current default drive to the new drive.

@param aDriveUnit New current default Contacts database drive.
@param aCopy ETrue if default Contacts database should be moved to new drive.
*/
void CCntDbManagerController::SetDatabaseDriveL(TDriveUnit aDriveUnit, TBool aCopy)
	{
	if (aDriveUnit == iDefaultDriveUnit) // Same drive?
		{ 
		aCopy = EFalse;
		if (iIniFileManager->DatabaseDriveSet())
			{
			return;
			}
		}

	// Old drive name.
	TDriveName oldDrv = iDefaultDriveUnit.Name();
	// New drive name.
	TDriveName newDrv = aDriveUnit.Name();	
	TBuf<KCntMaxFilePath> oldPath;	
	User::LeaveIfError(iFs.PrivatePath(oldPath));
	// Drive name goes before the path.
	oldPath.Insert(0,oldDrv);
	// Filename goes after the path.
	oldPath.Append(KSqLiteFilePrefix);
	oldPath.Append(KContactsBaseFilename);
	
	TBuf<KCntMaxFilePath> newPath;	
	User::LeaveIfError(iFs.PrivatePath(newPath));
	// Drive name goes before the path.
	newPath.Insert(0,newDrv);
	// Filename goes after the path.
	newPath.Append(KSqLiteFilePrefix);
	newPath.Append(KContactsBaseFilename);

	// Move the old file to the new drive location.
	CFileMan* fileManager = CFileMan::NewL(iFs);
	CleanupStack::PushL(fileManager);
	// The new file will be overwritten if it exists.  If the file or the path
	// doesn't exist then it will be created.
	if (aCopy)
		{
		User::LeaveIfError(fileManager->Copy(oldPath, newPath, CFileMan::ERecurse | CFileMan::EOverWrite ));	
		}

	// Change the default drive to the specified drive.
	iDefaultDriveUnit = aDriveUnit;

	// Save to Contacts initialisation file.
	iIniFileManager->SetDefaultDatabaseDrive(iDefaultDriveUnit, ETrue);
	iIniFileManager->ScheduleSaveIniFileSettings(CIniFileManager::ESaveDefaultDbDrive);

	// Remove the old file.
	if (aCopy)
		{
		(void)fileManager->Delete(oldPath);
		}		
	CleanupStack::PopAndDestroy(fileManager);
	}
Example #15
0
void CopyFileL(const TDesC& aSourceFile, const TDesC& aDestFile)
{
   RFs fs;
   fs.Connect();
   CleanupClosePushL(fs);
   fs.MkDirAll(aDestFile);
   CFileMan* fileMan = CFileMan::NewL( fs );
   // Copy feature file to file manager private data cage.
   //Ignore any errors as the file or path may not exist
   fileMan->Copy(aSourceFile, aDestFile);   
   CleanupStack::PopAndDestroy(&fs);
   }
//static
bool QFileSystemEngine::copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
{
    //CFileMan is allocated each time because it is not thread-safe
    CFileMan *fm = 0;
    TRAPD(err, fm = CFileMan::NewL(qt_s60GetRFs()));
    if (err == KErrNone) {
        err = fm->Copy(qt_QString2TPtrC(absoluteName(source).nativeFilePath()), qt_QString2TPtrC(absoluteName(target).nativeFilePath()), 0);
        delete fm;
    }
    if (err == KErrNone)
        return true;
    error = QSystemError(err, QSystemError::NativeError);
    return false;
}
Example #17
0
//---------------------------------------------------------
// CPosTp56::CopTestDbL
//
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPosTp56::CopyTestDbL()
    {
        
    RFs fs;
    User::LeaveIfError(fs.Connect());
    CleanupClosePushL(fs);

    CFileMan* fileMan = CFileMan::NewL(fs);
    CleanupStack::PushL(fileMan);

    User::LeaveIfError(fileMan->Copy(KTestDb, KLocalDbLocation, CFileMan::EOverWrite));     
    
    CleanupStack::PopAndDestroy(2, &fs);  

    }
Example #18
0
// ---------------------------------------------------------
// CPosTp56::CreateDatabasesL
//
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPosTp56::CreateDatabasesL()
    {
    // Paths will need to be changed to the secure dbms path when security is implemented
   
    _LIT(KDefaultDbPath, "c:\\system\\data\\eposlm.ldb");

    _LIT(KDb1Path, "c:\\system\\data\\eposlm1.ldb");
    _LIT(KDb2Path, "c:\\system\\data\\eposlm2.ldb");
    _LIT(KDb3Path, "c:\\system\\data\\eposlm3.ldb");

    CPosLandmarkDatabase* lmd = CPosLandmarkDatabase::OpenL();
    CleanupStack::PushL(lmd);

    if (lmd->IsInitializingNeeded())
        {
        ExecuteAndDeleteLD(lmd->InitializeL()); 
        }
    
    CleanupStack::PopAndDestroy(lmd);  

    RFs fs;
    User::LeaveIfError(fs.Connect());
    CleanupClosePushL(fs);
   
    fs.Delete(KExportFile);

    CFileMan* fileMan = CFileMan::NewL(fs);
    CleanupStack::PushL(fileMan);

    User::LeaveIfError(fileMan->Copy(KDefaultDbPath, KDb1Path, CFileMan::EOverWrite));    
    User::LeaveIfError(fileMan->Copy(KDefaultDbPath, KDb2Path, CFileMan::EOverWrite));    
    User::LeaveIfError(fileMan->Copy(KDefaultDbPath, KDb3Path, CFileMan::EOverWrite));  


    CleanupStack::PopAndDestroy(2, &fs);  
    }
//The function copies all test script files from Z: to C: drive, in application's private data cage.	
static void DoCopyTestFilesL()
	{
	RDebug::Print(_L("###TCLSQLITE: Construct private data cage on drive C:\r\n"));
	RFs fs;
	CleanupClosePushL(fs);
	TFileName privatePath;
	GetFsAndPrivatePathL(fs, privatePath);

	CFileMan* fm = CFileMan::NewL(fs);
	CleanupStack::PushL(fm);
	
	TFileName srcPath;
	ConstructFilePathByMask(EDriveZ, privatePath, srcPath);
	TFileName destPath;
	ConstructDestPath(EDriveC, privatePath, destPath);
	RDebug::Print(_L("###TCLSQLITE: Copying \"%S\" to \"%S\"\r\n"), &srcPath, &destPath);
	User::LeaveIfError(fm->Copy(srcPath, destPath));

	ConstructFilePathByName(EDriveZ, KTesterTclFile, privatePath, srcPath);
	RDebug::Print(_L("###TCLSQLITE: Copying \"%S\" to \"%S\"\r\n"), &srcPath, &destPath);
	User::LeaveIfError(fm->Copy(srcPath, destPath));
	
	CleanupStack::PopAndDestroy(2);
	}
Example #20
0
TInt Copy(const TDesC& aOld,const TDesC& aNew)
	{
	__LOGSTR("Copy");
	TInt err;
	RFs session;
	__CH__(session.Connect());
	__CPUSHC(session);
	CFileMan* manager = CFileMan::NewL(session);
	__CPUSH(manager);
	err = manager->Copy(aOld,aNew,CFileMan::ERecurse | CFileMan::EOverWrite);

	__LOGSTR1("Copy returned value: %d",err);
	__CPOPD(manager);
	__CPOPD(&session);
	return err;
	}
Example #21
0
// ---------------------------------------------------------
// CPosTp50::ExportAllLandmarksL
//
// (other items were commented in a header).
// ---------------------------------------------------------
//	
void CPosTp50::ExportLandmarksL() 
    {
    RFs fs;
    User::LeaveIfError(fs.Connect());
    CleanupClosePushL(fs);
    
    fs.Delete(KAllLandmarks);
    
    CPosLmItemIterator* iter = iDatabase->LandmarkIteratorL();
    CleanupStack::PushL(iter);

    RArray<TPosLmItemId> arrayOfIds;
    CleanupClosePushL(arrayOfIds);
    
    TInt numberOfElements = iter->NumOfItemsL();    
    iter->GetItemIdsL(arrayOfIds, 0, (numberOfElements));
    
    CPosLandmarkEncoder* encoder = CPosLandmarkEncoder::NewL(KMimeType);
    CleanupStack::PushL(encoder);

    encoder->SetOutputFileL(KAllLandmarks);
   
    CPosLmOperation* op = iDatabase->ExportLandmarksL(*encoder, arrayOfIds,  CPosLandmarkDatabase::EDefaultOptions); 
    CleanupStack::PushL(op);
    op->ExecuteL();
    CleanupStack::PopAndDestroy(op);
    
    op = encoder->FinalizeEncodingL(); 
    CleanupStack::PushL(op);
    op->ExecuteL();
    
    // Create a file to be used from each thread
    CFileMan* fileMan = CFileMan::NewL(fs);
    CleanupStack::PushL(fileMan);
   
    for (TInt i=0; i<KNoMultipleClients; i++)
        {
        TBuf<100> fileName;
        fileName.Format(KAllLandmarksIndex, i+1);
        fs.Delete(fileName);
        
        User::LeaveIfError(fileMan->Copy(KAllLandmarks, fileName, CFileMan::EOverWrite));     
        }
        
    CleanupStack::PopAndDestroy(6, &fs); 
    }
EXPORT_C void CTestUtils::CopyToSimTsyConfigFileL(RFs& aFs, const TDesC& aFilename)
	{
	_LIT(KFileName,"config.txt");
	TChar driveChar=RFs::GetSystemDriveChar();
 	TBuf<2> systemDrive;
 	systemDrive.Append(driveChar);
 	systemDrive.Append(KDriveDelimiter);	
	aFs.SetSessionPath(systemDrive);
	aFs.Delete(KFileName);					//< Ignore Error

	CFileMan* fileMan = CFileMan::NewL(aFs);
	CleanupStack::PushL(fileMan);

	User::LeaveIfError(fileMan->Copy(aFilename, KFileName));

	CleanupStack::PopAndDestroy(fileMan);
	}
void TRepositoryCacheManagerTester::InstallIniFileL( TBorderTestStage aFileSet )
	{
	_LIT( KDriveC, "c:" );
	_LIT( KDriveZ, "z:" );

	TBuf<KMaxFileName> src1;
	TBuf<KMaxFileName> dest1;
	TInt r;

	DeleteFilesL();

	CFileMan* fm = CFileMan::NewL( iFs );
	CleanupStack::PushL( fm );

	if ((aFileSet>=ELastStage)||(aFileSet<0))
		{
		RDebug::Print( _L( "Illegal parameter to function: %d\r\n" ), aFileSet );
		TheTest( EFalse, __LINE__ );
		}
	else
		{
		dest1.Copy( KDriveC );
		dest1.Append( KCacheMgrIniFileFolder );
		dest1.Append( KCacheMgrIniFile );
		r = fm->Delete( dest1 );
		if ( r != KErrNone && r != KErrNotFound && r != KErrPathNotFound )
			User::Leave( r );
		r = iFs.MkDirAll( dest1 );
		if ( r != KErrNone && r != KErrAlreadyExists )
			User::Leave( r );
		src1.Copy( KDriveZ );
		src1.Append( KCacheMgrIniFileFolder );
		src1.Append( KCacheMgrIniSrcFile );
		TBuf<2> testNo;
		testNo.Num(aFileSet);
		src1.Append( testNo );
		User::LeaveIfError( fm->Copy( src1, dest1 ) );
		r = fm->Attribs( dest1, KEntryAttArchive, KEntryAttReadOnly, TTime( 0 ), CFileMan::ERecurse );
		TEST2( r, KErrNone );
		}

	CleanupStack::PopAndDestroy( fm );
	}
void CenrepSwiOOMTest::UpgradeROMRev1L(TBool aIsSetup)
	{
	if(aIsSetup)
		{
		RFs fs;
		User::LeaveIfError(fs.Connect());
		CleanupClosePushL(fs);
		CFileMan* fm = CFileMan::NewL(fs);
		CleanupStack::PushL(fm);

		// Copy rev 1 file into install dir & Reset read-only bit
		User::LeaveIfError(fm->Copy(KRomUpgradeRev1File, KUpgradeFile));
		User::LeaveIfError(fm->Attribs(KUpgradeFile,0,KEntryAttReadOnly,TTime(0)));
		CleanupStack::PopAndDestroy(2); // fs and fm
		}
	else
		{
		iSwiWatcher->HandleSWIEventL(ESASwisInstall | ESASwisStatusSuccess);
		}
	}
Example #25
0
// ---------------------------------------------------------
// CPosTp29::TryRestoreResourceFile
// 
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPosTp29::TryRestoreResourceFile()
    {
    iLog->Put(_L("TryRestoreResourceFile"));
    CFileMan* fileMan = NULL;
    TRAPD(err, fileMan = CFileMan::NewL(iFileServer));
    User::LeaveIfError(err);
    if (fileMan)
        {
        // Try to restore the backup up rsc-file (only possible when LM FW is not flashed.
        TInt result = fileMan->Copy(KInternalServicesResFileBackup, KInternalServicesResFileCdrive, CFileMan::EOverWrite);
        if (result == KErrNotFound)
            {
            if (BaflUtils::FileExists(iFileServer, KInternalServicesResFileRom))
                {
                // LM FW is flashed. We need to remove the rsc-file on c:
                fileMan->Delete(KInternalServicesResFileCdrive);
                }
            }
        delete fileMan;
        }
    }
Example #26
0
// Copy the files specified.
void CopyFileL(const TDesC& anOld, const TDesC& aNew)
	{	
	RFs fs;
	fs.Connect();	
	CleanupClosePushL(fs);

	CFileMan* fileMan = CFileMan::NewL(fs);
	CleanupStack::PushL(fileMan); 

	// Check if the destination directory exists, if so then delete files if they are present
	TInt err = fs.MkDirAll(aNew);	
	if (err == KErrAlreadyExists)
		{
		err = fileMan->Attribs(aNew, 0, KEntryAttReadOnly, TTime(0), 0);
		if ((err != KErrNone) && (err != KErrNotFound))
			{
			User::Leave(err);
			}
		else if(err == KErrNone)
			{
			User::LeaveIfError(fs.Delete(aNew));
			}
		}
	else if (err != KErrNone)
		{
		User::Leave(err);
		}

	// Make the destination file writeable 
    err = fileMan->Attribs(aNew, 0, KEntryAttReadOnly, TTime(0), 0);
	if ((err != KErrNone) && (err != KErrNotFound))
		{
		User::Leave(err);
		}

	// Do the file copy	
    User::LeaveIfError(fileMan->Copy(anOld, aNew));

	CleanupStack::PopAndDestroy(2); 
	}
void CTestMessageConverterManager::TestStartConversion()
	{
	_LIT(KFunction,"TestStartConversion");
	INFO_PRINTF1(KFunction);
	
	RFs fs;
	User::LeaveIfError(fs.Connect());
	CFileMan* fileMngr = CFileMan::NewL(fs);
	CleanupStack::PushL(fileMngr);
	
	TPtrC drive;
	
		// create the directories
	fs.MkDirAll(_L("D:\\private\\1000484b\\mail2\\"));
	fs.MkDirAll(_L("E:\\private\\1000484b\\mail2\\"));
		
	// cleanup mesasging.db in drive D
	TRAPD(err,fileMngr->Delete(KDbFileName));	
	MY_ASSERT_EQUALS(err, KErrNone);
	
	//copy mail2
	TRAP(err, fileMngr->Copy(KConverterMail2Folder,KMail2FolderPathD,2));
	MY_ASSERT_EQUALS(err, KErrNone);
	
	CleanupStack::PopAndDestroy(fileMngr);
	fs.Close();	
	
	_LIT(KStartMessageStoreConversionL,"Starting Conversion on Drive D, this request will be cancelled after some time so that we can resume conversion in the next step");
	INFO_PRINTF1(KStartMessageStoreConversionL);
	
	//Conversion request
	TDriveNumber driveNumber = EDriveD;
	TAny* conversionStatus = &driveNumber;
	
	_LIT(KConverterTestThread,"StartMessageStoreConversion");
	err = iConverterThread.Create(KConverterTestThread, &CMessageConverterManager::StartConversion,KDefaultStackSize*8,KMinHeapSize,0x8000000,conversionStatus,EOwnerThread);

	// Request for notification
	TRAPD(error, iConverterThread.Logon(iActiveWaiter->iStatus);)	
Example #28
0
void SymbianLog::RollLogFile(void)
{
    CFileMan* fileMan = CFileMan::NewL(fsSession);
    CleanupStack::PushL(fileMan);
    //copy the current file into the roll file, file must be open
    TInt err = KErrNone;
    err = file.Open(fsSession, iLogName, EFileWrite|EFileShareAny);
    if (err != KErrNone) {
        setErrorF(err, "SymbianLog: could not open log file (code %d)", err);
    } else {
        err = fileMan->Copy(file,iRollLogName,CFileMan::EOverWrite);
    }
    if (err != KErrNone) {
        setErrorF(err, "SymbianLog: copy error on roll log file (code %d)", err);
    }
    file.Close();
    // reset the current file
    // we don't use reset() method because we don't want 
    // nested semaphores
    err = KErrNone;
    err = file.Replace(fsSession, iLogName, EFileWrite|EFileShareAny);
    if (err != KErrNone) {
        setErrorF(err, "SymbianLog: error resetting the log file (code %d)", err);
        return;
    }
    // Write the Header
    StringBuffer header = createHeader();
    RBuf8 buf;
    buf.Assign(stringBufferToNewBuf8(header));
    file.Write(buf);
    buf.Close();
    file.Close();
    
    CleanupStack::PopAndDestroy(fileMan);

}
Example #29
0
void CImPop3TransferMessage::StartL(TMsvId aSourceMessage, TMsvId aDestFolder, TImPop3TransferMethod aTransferMethod, TRequestStatus& aStatus)
	{
	iSourceMessage = aSourceMessage;
	iDestFolder = aDestFolder;
	iTransferMethod = aTransferMethod;
	iReportStatus = &aStatus;

	User::LeaveIfError(iEntry.SetEntry(aSourceMessage));
	TMsvEntry entry = iEntry.Entry();

	HBufC* details = HBufC::NewLC(entry.iDetails.Size());
	(*details) = entry.iDetails;
	HBufC* description = HBufC::NewLC(entry.iDescription.Size());
	(*description) = entry.iDescription;

	TFileName mailDirectory;
	mailDirectory.Append('a' + MessageServer::CurrentDriveL(iEntry.FileSession()));
	mailDirectory.Append(KPop3DriveSeparator);
	mailDirectory.Append(KMsvDefaultFolder2);
	
	// Get the store filename from the source message
	TFileName sourceStoreFilename = mailDirectory;
	User::LeaveIfError(iEntry.SetEntry(aSourceMessage));

	TBool storeFound = iEntry.HasStoreL();
	if (storeFound)
		{
		MsvUtils::ConstructEntryName(iEntry.Entry().iServiceId, iEntry.Entry().Id(), sourceStoreFilename, MsvUtils::EStore);	
		}

	// Create a message entry in the destination folder
	iEntry.SetEntry(aDestFolder);
	TMsvEmailEntry emailEntry(entry);
	emailEntry.SetVisible(ETrue);
	emailEntry.iDetails.Set(details->Des());
	emailEntry.iDescription.Set(description->Des());
	emailEntry.SetDisconnectedOperation(ENoDisconnectedOperations);
  
	User::LeaveIfError(iEntry.CreateEntry(emailEntry));
	iCopiedMessageId = emailEntry.Id();

	User::LeaveIfError(iEntry.SetEntry(emailEntry.Id()));
	TMsvId newEntry = emailEntry.Id();

	// Get the serviceId of the service the destination ID is located in.
	TMsvId destinationServiceId = iEntry.OwningService();

	if (storeFound)
		{
		// Get the name that the destination file should be copied to
		TFileName destinationStoreFilename = mailDirectory;
		MsvUtils::ConstructEntryName(destinationServiceId, iEntry.Entry().Id(), destinationStoreFilename, MsvUtils::EStore);
		CFileMan* fileMan = CFileMan::NewL(iEntry.FileSession());
		CleanupStack::PushL(fileMan);
		User::LeaveIfError(fileMan->Copy(sourceStoreFilename, destinationStoreFilename, CFileMan::ERecurse|CFileMan::EOverWrite));
		CleanupStack::PopAndDestroy(); // fileMan

		// This change entry isn't actually changing anything.
		// However the store contains a hidden stream created by the Message Server.
		// This is used to rebuild the index if it's corrupted
		// Calling ChangeEntry will make sure the stream is updated correctly
		iEntry.ChangeEntry(iEntry.Entry());
		}

	// Move all child entries from under the remote entry to the new entry
	User::LeaveIfError(iEntry.SetEntry(aSourceMessage));
	CMsvEntrySelection* childEntries = new (ELeave) CMsvEntrySelection;
	CleanupStack::PushL(childEntries);
	User::LeaveIfError(iEntry.GetChildren(*childEntries));
	if (childEntries->Count() > 0)
		{
		if (iTransferMethod == EImPop3CopyTransfer)
			// If we are in disconnected mode then we really want to copy the
			// entries, however if we are not then we want to move them.
			// This is because the only reason there are entries under the
			// service is because the remote server does not support the TOP
			// command.
			{
			iStatus = KRequestPending;
			iEntry.CopyEntriesL(*childEntries, newEntry, iStatus);
			SetActive();
			}
		else
			{
			iStatus = KRequestPending;
			iEntry.MoveEntriesL(*childEntries, newEntry, iStatus);
			SetActive();
			}
		}
	else
		{
		iStatus = KRequestPending;
		SetActive();
		TRequestStatus* status = &iStatus;
		User::RequestComplete(status, KErrNone);
		}

	CleanupStack::PopAndDestroy(); // childEntries

	CleanupStack::PopAndDestroy(2); // description, details

	}
Example #30
0
// ---------------------------------------------------------
// CPosTp1::VerifyLockedDatabaseL
//
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CPosTp1::VerifyLockedDatabaseL()
    {
    _LIT(KTestPath, "c:\\system\\test\\testdata\\");
    // copy the test db to the private path
    CFileMan* fileMan = CFileMan::NewL(iFileSession);
    CleanupStack::PushL(fileMan);

    TBuf<150> srcPath;

    srcPath.Append(KTestPath);
    srcPath.Append(KTp1TestDb);

    TInt err = fileMan->Copy(srcPath, KLmTp1DefaultDbPath,
            CFileMan::EOverWrite);
    if (err != KErrNone)
        iLog->Log(_L("Error when copying file"));

    CleanupStack::PopAndDestroy(fileMan);
    CPosLmDatabaseManager* manager = CPosLmDatabaseManager::NewL();
    CleanupStack::PushL(manager);

    // This db must exist
    manager->SetDefaultDatabaseUriL(KTp1TestDb);
    CleanupStack::PopAndDestroy(manager);

    CPosLandmarkDatabase* db1 = CPosLandmarkDatabase::OpenL(KTp1TestDb);
    CleanupStack::PushL(db1);
    if (db1->IsInitializingNeeded())
        {
        TRAPD( err, ExecuteAndDeleteLD( db1->InitializeL() ) );
        AssertTrueSecL(err == KErrNone, _L("Init db failed"));
        }
    
    

    // Take read lock
    RArray<TPosLmItemId> ids;
    CleanupClosePushL(ids);
    User::LeaveIfError(ids.Append(1));
    User::LeaveIfError(ids.Append(3));
    User::LeaveIfError(ids.Append(4));
    User::LeaveIfError(ids.Append(6));
    User::LeaveIfError(ids.Append(7));
    User::LeaveIfError(ids.Append(9));
    User::LeaveIfError(ids.Append(24));
    User::LeaveIfError(ids.Append(14));
    User::LeaveIfError(ids.Append(66));
    User::LeaveIfError(ids.Append(61));
    User::LeaveIfError(ids.Append(14));
    CPosLmOperation* operation = db1->PreparePartialLandmarksL(ids);
    CleanupStack::PushL(operation);
    TReal32 progress(0);
    TRequestStatus status;
    while (progress < 0.4)
        {
        operation->NextStep(status, progress);
        User::WaitForRequest(status);
        }

    // Try to instantiate a new db handle
    operation->NextStep(status, progress);
    CPosLandmarkDatabase* db2 = CPosLandmarkDatabase::OpenL();
    iLog->Log(_L("CPosLandmarkDatabase::OpenL done"));
    delete db2;
    User::WaitForRequest(status);

    // Release read lock
    CleanupStack::PopAndDestroy(operation);
    
    // Take write lock
    operation = db1->RemoveAllLandmarksL();
    CleanupStack::PushL(operation);
    progress = 0;
    while (progress < 0.4)
        {
        operation->NextStep(status, progress);
        User::WaitForRequest(status);
        }

    // Try to instantiate a new db handle - should result in KErrLocked
    operation->NextStep(status, progress);
    db2 = NULL;
    TRAPD(err1, db2 = CPosLandmarkDatabase::OpenL());
    delete db2;
    User::WaitForRequest(status);
    AssertTrueSecL(err1 == KErrLocked, _L("OpenL() didn't result in KErrLocked but in %d"), err1);
    
    CleanupStack::PopAndDestroy(3, db1);
    }