// -----------------------------------------------------------------------------
// CAknKeyRotatorImpl::GetWsiniLC
// Reads the whole wsini.ini to memory and returns in heap descriptor.
// -----------------------------------------------------------------------------
//
HBufC* CAknKeyRotatorImpl::GetWsiniLC()
    {
    // Read the whole wsini.ini to memory
    RFs fs;
    User::LeaveIfError( fs.Connect() );
    CleanupClosePushL( fs );
    
    TEntry wsiniEntry;
    User::LeaveIfError( fs.Entry( KAknWsini, wsiniEntry ) );

    HBufC* wsiniText = HBufC::NewLC( ( wsiniEntry.iSize + 1 )/2 );
    TPtr wsiniPtr = wsiniText->Des();
    TPtr8 wsiniPtr8( (TText8*)wsiniPtr.Ptr(), 0, wsiniPtr.MaxLength()*2 );

    RFile wsiniFile;
    User::LeaveIfError( wsiniFile.Open( fs, KAknWsini, EFileRead | EFileShareReadersOnly ) );
    CleanupClosePushL( wsiniFile );

    User::LeaveIfError( wsiniFile.Read( wsiniPtr8, wsiniEntry.iSize ) );
    wsiniPtr.SetLength( wsiniPtr8.Length() / 2 );

    CleanupStack::PopAndDestroy( &wsiniFile );
    CleanupStack::Pop( wsiniText );
    CleanupStack::PopAndDestroy( &fs );
    CleanupStack::PushL( wsiniText );
    return wsiniText;
    }
예제 #2
0
//Delete "aFullName" file.
static void DeleteDataFile(const TDesC& aFullName)
	{
	RFs fsSession;
	TInt err = fsSession.Connect();
	if(err == KErrNone)
		{
		TEntry entry;
		if(fsSession.Entry(aFullName, entry) == KErrNone)
			{
			RDebug::Print(_L("Deleting \"%S\" file.\n"), &aFullName);
			err = fsSession.SetAtt(aFullName, 0, KEntryAttReadOnly);
			if(err != KErrNone)
				{
				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &aFullName);
				}
			err = fsSession.Delete(aFullName);
			if(err != KErrNone)
				{
				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &aFullName);
				}
			}
		fsSession.Close();
		}
	else
		{
		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &aFullName);
		}
	}
// ----------------------------------------------------------------------------------------
// CTerminalControlServer::DeleteFileL
// ----------------------------------------------------------------------------------------
void CTerminalControlServer::DeleteFileL( const TDesC8 &aFileName )
{
    RDEBUG("CTerminalControlServer::DeleteFileL");

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

    HBufC *fileName = HBufC::NewLC( aFileName.Length()+1 );
    TPtr fnptr( fileName->Des() );

    fnptr.Copy(aFileName);
    TEntry entry;

    User::LeaveIfError( fs.Entry( fnptr, entry ) );

    if( entry.IsDir() )
    {
        if(fnptr.Right(1) != _L("\\"))
        {
            fnptr.Append(_L("\\"));
        }
        User::LeaveIfError(fs.RmDir( fnptr ) );
    }
    else
    {
        User::LeaveIfError(fs.Delete( fnptr ) );
    }

    CleanupStack::PopAndDestroy( fileName );

    CleanupStack::PopAndDestroy( &fs );
}
예제 #4
0
void T_CntImageRescaler::testRescaleImageSuccefully()
    {
    test.Next(_L("Rescale image"));

    TPath dest;
    dest.Append(KDestDir());
    dest.Append(_L("test.jpg"));

    TTime time;
    time.UniversalTime();

    TRAPD(err, iRescaler->ResizeImageL(KSrcImage(), dest));

    TTime time2;
    time2.UniversalTime();

    TInt seconds = time2.MicroSecondsFrom( time ).Int64() / 1000000;

    test.Printf(_L("rescaled in %d seconds\n"), seconds);

    test(err == KErrNone);
    test(BaflUtils::FileExists(iFs, dest));

    TEntry file;
    if (iFs.Entry(dest, file) == KErrNone)
        {
        test(file.iSize <= KMaxImageSize);
        }
    }
예제 #5
0
void CStateDownload::ScanDirectory(RFs& aFs, const TDesC& aDir, const TDesC& aWild, CDesCArray* aFilesArray)
	{
	TParse parse;
	parse.Set(aWild, &aDir, NULL);
	TPtrC spec(parse.FullName());
	 
	TFindFile FindFile(aFs);
	CDir* dir;
	 
	if (FindFile.FindWildByPath(parse.FullName(), NULL, dir) == KErrNone)
		{
	    CleanupStack::PushL(dir);
	 
	    TInt count=dir->Count();
	    for(TInt i = 0; i < count; i++)
	    	{
	        parse.Set((*dir)[i].iName, &spec, NULL);
	        TEntry entry;
	        if(aFs.Entry(parse.FullName(),entry) == KErrNone)
	        	{
	        	if(!entry.IsDir())
	        		{
	        		//InsertIsqL raises a KErrAlreadyExists (-11) when inserting a duplicate
	        		TRAPD(err,aFilesArray->InsertIsqL(parse.FullName())); 
	        		}
	        	}
	        }
	    CleanupStack::PopAndDestroy(dir);
	    }
	}
예제 #6
0
/** Find entry in directory

*/
LOCAL_C TInt FindEntryAccess2(TAny*)
	{
	RFs fs;
	TInt r  = fs.Connect();
	RTest test(_L("test 2")); 
	
	fs.SetSessionPath(gSessionPath);
	
	client.Signal();
	
	FOREVER
		{
			TEntry entry;
			r = fs.Entry(gFindEntryDir2, entry);
			FailIfError(r);
			r = fs.Entry(gFindDir2,entry);
			FailIfError(r);
		}
	}
TBool LangUtilsTest::FileExists(const RFs& aFileSession,const TDesC& aFileName)
/** Checks if the specified file exists.
    
@param aFs File server session
@param aFileName File to check
@return ETrue if the file exists, otherwise EFalse */
    { // static
    TEntry entry;
    return(aFileSession.Entry(aFileName,entry)==KErrNone);
    }
TBool CSwisExpressionEnvironment::FileExistsL(const TDesC& aFileName)
	{
	RFs fs;
	User::LeaveIfError(fs.Connect());
	// Try getting file info to see if it exists
	TEntry entry;
	TInt err = fs.Entry(aFileName, entry);  
	fs.Close();
	return err==KErrNone ? ETrue : EFalse;
	}
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 CMMCScBkupReadDataTransferRequestBase::DumpTransferDataL( RFs& aFsSession, const TDesC8& aData ) const
    {
    TPtrC subDirectory( KNullDesC );
    //
    switch( ElementType() )
        {
    case EMMCScBkupOwnerDataTypeJavaData:
        subDirectory.Set(KMMCScBkupDataTransferDebuggingPathDataJava);
        break;
    case EMMCScBkupOwnerDataTypeSystemData:
        subDirectory.Set(KMMCScBkupDataTransferDebuggingPathDataSystem);
        break;
    case EMMCScBkupOwnerDataTypePassiveData:
        subDirectory.Set(KMMCScBkupDataTransferDebuggingPathDataPassive);
        break;
    case EMMCScBkupOwnerDataTypeActiveData:
        subDirectory.Set(KMMCScBkupDataTransferDebuggingPathDataActive);
        break;
    default:
        User::Leave( KErrNotSupported );
        break;
        }
    //
    const TSecureId secureId = DataOwner().SecureId();
    _LIT(KMMCScBkupFormatDes, "%S%S");
    TFileName transferDumpFileName;
    const TDesC& path = PathInfo::MemoryCardRootPath();
    transferDumpFileName.Format(KMMCScBkupFormatDes, &path, &KMMCScBkupDataTransferDebuggingPathRoot);
    
    transferDumpFileName.Append( subDirectory );
    transferDumpFileName.Append( KMMCScBkupDataTransferDebuggingPathDataRestore );
    transferDumpFileName.AppendFormat( KMMCScBkupDataTransferDebuggingFileName, secureId.iId, 'a' + CurrentDrive() );
    //
    RFile64 file;
    TInt error = KErrNone;
    TEntry entry;
    if  ( aFsSession.Entry( transferDumpFileName, entry ) == KErrNone )
        {
        // Already exists - append data
        error = file.Open( aFsSession, transferDumpFileName, EFileWrite | EFileStream | EFileShareExclusive );
        }
    else
        {
        entry.iSize = 0;
        error = file.Create( aFsSession, transferDumpFileName, EFileWrite | EFileStream | EFileShareExclusive );
        }
    //
    User::LeaveIfError( error );
    CleanupClosePushL( file );
    error = file.Write( entry.iSize, aData );
    CleanupStack::PopAndDestroy( &file );
    }
예제 #11
0
static void DoDeleteDatabaseL(const TDesC& aDbPath, TBool aCloseBeforeDelete)
    {
    CBaBackupSessionWrapper* backup = NULL;
    if(aCloseBeforeDelete)
        {
        //Reseting of log engine databse is done via its backup server.
        //Create backup session wrapper
        backup = CBaBackupSessionWrapper::NewL();
        CleanupStack::PushL(backup);

        //This eventually calls CLogBackup::ChangeFileLockL(..) which closes the database 
        //file and notifies all handles to that file that it has closed.
        backup->CloseFileL(aDbPath, MBackupObserver::EReleaseLockNoAccess);
        User::After(1000000);
        }

    //Since the log engine database file is closed we can delete it.   
    //Once this file is deleted, the backup server notices this and attempts to reopen 
    //the database.  Since the file is deleted a default database is created instead.
    
    TInt error = theFs.Delete(aDbPath);

    if(!(error == KErrNone || error == KErrNotFound || error == KErrPathNotFound) )
        {
        RDebug::Print(_L("DoDeleteDatabaseL(), Error %d deleting database \"%S\"\n"),error, &aDbPath);
        }
    else
        {
        RDebug::Print(_L("DoDeleteDatabaseL(), Database \"%S\" deleted ok\n"), &aDbPath);
        }

    if(aCloseBeforeDelete)
        {
        //The next line restarts the logeng server and re-creates logdbu.dat file.
        CleanupStack::PopAndDestroy(backup);
            
        TInt count = 10;
        while(count--)
            {
            User::After(100000);
            TEntry entry;
            if(theFs.Entry(aDbPath, entry) == KErrNone)
                {
                break;
                }
            }
        }
    }
void IntegrityRestoreFileL(const TDesC& aPath, CIntegrityTreeLeaf* aLeaf, RFs& aFs, 
								RLoader& /*aLoader*/, CFileMan& /*aFileMan*/)
	{
	RBuf name;
	name.CreateL(aPath, KMaxFileName);
	CleanupClosePushL(name);
	name.Append(aLeaf->Name());

	// find the peer file, and check it's a backup.
	CIntegrityTreeLeaf* peer = aLeaf->Peer();
	if (peer->Type() != EBackupFile)
		{
		User::Leave(KErrCorrupt);
		}
	
	TParsePtrC parse(peer->Journal());
	RBuf backup;
	backup.CreateL(parse.DriveAndPath(), KMaxFileName);
	CleanupClosePushL(backup);
	backup.Append(parse.Name());
	backup.Append(KPathDelimiter);
	backup.Append(peer->Name());

	TInt err = aFs.MkDirAll(name);
	if(err != KErrNone && err != KErrAlreadyExists)
		{
		User::Leave(err);
		}
			
	err = aFs.Rename(backup, name);
	if (err != KErrNone)
		{
		VerifyDeletionErrorL(err);
		// we may have already moved it back during a previous recovery
		// attempt, check for its presence in the original location
		TEntry restoredEntry;
		User::LeaveIfError(aFs.Entry(name, restoredEntry));
		}
	else
		{
		// prune the backup directory tree if possible.
		RemoveDirectoryTreeL(aFs, backup);
		}
	CleanupStack::PopAndDestroy(2, &name);	// backup
	}
예제 #13
0
void CScrHelperSession::GetFileHandleL(RFs& aFs, const RMessage2& aMessage, const TDesC& aFileName)
	{
	DEBUG_PRINTF2(_L("Returning file handle of %S."), &aFileName);
	RBuf filePath;
	filePath.CreateL(aFileName.Length());
	filePath.CleanupClosePushL();
	filePath.Copy(aFileName);
	filePath[0] = aFs.GetSystemDriveChar();
	TInt err = aFs.MkDirAll(filePath);
	if(KErrNone != err && KErrAlreadyExists != err)
		{
		DEBUG_PRINTF3(_L("An error (%d) occured while making all directories of %S."), err, &filePath);
		User::Leave(err);
		}
	
	RFile file;
	TEntry entry;

	if(KErrNone == aFs.Entry(filePath, entry))
		{ // The file exists, just open it.
		User::LeaveIfError(file.Open(aFs, filePath, EFileShareAny|EFileWrite));
		}    
	else
		{ // The file doesn't exist. First, check if the requested file is database or journal file.
		if(KScrDatabaseFilePath() == aFileName)
			{ // This is the database file. Copy the default one into the requested location.
			DEBUG_PRINTF(_L8("SCR database file doesn't exist. It is being copied from ROM"));
			CopyDbFromROMToSystemL(aFs, filePath);
			 // Then, open the file.
			User::LeaveIfError(file.Open(aFs, filePath, EFileShareAny|EFileWrite));
			}
		else
			{ // This is the journal file, simply create an empty file.
			User::LeaveIfError(file.Create(aFs, filePath, EFileShareAny|EFileWrite));
			}
		}
	CleanupStack::PopAndDestroy(&filePath);
	CleanupClosePushL(file);
	
	// Store the RFile handle into the package buffer in slot 0 and complete the message with the RFs handle
	User::LeaveIfError(file.TransferToClient(aMessage, 0));
	ASSERT(aMessage.IsNull());  // The message should have been completed

	CleanupStack::PopAndDestroy(&file);
	}
예제 #14
0
LOCAL_C void TestCleanup()
	{
	TheTable.Close();
	TheView.Close();
	TheDatabase.Close();
#ifndef __TOOLS2__
	TheDbs.Close();
#endif

	TRAPD(errCode, TheCrcChecker.GenerateCrcL(KTestDatabase));

	TheFs.Close();
	/////////////
	RFs fsSession;
	TInt err = fsSession.Connect();
	if(err == KErrNone)
		{
		TEntry entry;
		if(fsSession.Entry(KTestDatabase, entry) == KErrNone)
			{
			RDebug::Print(_L("Deleting \"%S\" file.\n"), &KTestDatabase);
			err = fsSession.SetAtt(KTestDatabase, 0, KEntryAttReadOnly);
			if(err != KErrNone) 
				{
				RDebug::Print(_L("Error %d changing \"%S\" file attributes.\n"), err, &KTestDatabase);
				}
			err = fsSession.Delete(KTestDatabase);
			if(err != KErrNone) 
				{
				RDebug::Print(_L("Error %d deleting \"%S\" file.\n"), err, &KTestDatabase);
				}
			}
		fsSession.Close();
		}
	else
		{
		RDebug::Print(_L("Error %d connecting file session. File: %S.\n"), err, &KTestDatabase);
		}
	}
예제 #15
0
int PosixFilesystem::stat (RFs& aFs, const wchar_t* name, struct stat *st, int& anErrno)
{
    TFullName fullName;
    TInt err=GetFullFile(fullName,(const TText16*)name,aFs);
    if (!err)
    {
        TEntry entry;
        if (fullName.Length()==3)
        {
            entry.iAtt=KEntryAttDir;
            entry.iModified==TTime(0);
        }
        else
            err=aFs.Entry(fullName,entry);
        if (!err)
        {
            st->st_size = entry.iSize;
            st->st_dev = st->st_rdev = (dev_t)TDriveUnit(fullName);
            CFileDesc::MapStat(*st, entry.iModified, entry.iAtt);
            return 0;
        }
    }
    return MapError(err, anErrno);
}
// -----------------------------------------------------------------------------
// 
// -----------------------------------------------------------------------------
//
TInt CPhoneRingingTone::CheckToneFileSize( const TDesC& aFile, 
                                           TInt aSizeLimitKB )
    {
    __LOGMETHODSTARTEND( EPhoneControl, "CPhoneRingingtone::CheckToneFileSize()" );
    //return KErrNone;
    
    // Get file size
    TInt size = 0;

    RFs fs;   
    TInt error = fs.Connect();
    TEntry entry;
    if ( KErrNone == error )
        {
        if (KErrNone == fs.Entry( aFile, entry ))
            {
            size = entry.iSize;
            }    
            
        // Check
        aSizeLimitKB *= Kkilo;
        if ( aSizeLimitKB  &&  size > aSizeLimitKB )
            {
            error = KErrTooBig;
            }
        }

    fs.Close();
    __PHONELOG1( 
        EBasic,
        EPhoneControl, 
        "CPhoneRingingtonePlayer::CheckToneFileSize - size (%d)",
        size );    
    return error;
   
    }
TInt CDeploymentComponentData::DataLengthL() const
    {
    TInt ret( 0);
    if (iData == NULL)
        {
        if (iDataFileName.Length() > 0)
            {
            RFs fs;
            User::LeaveIfError(fs.Connect() );
            CleanupClosePushL(fs); // 1
            TEntry entry;
            TFileName fileName;
            fileName.Copy(iDataFileName);
            User::LeaveIfError(fs.Entry(fileName, entry) );
            ret = entry.iSize;
            CleanupStack::PopAndDestroy( &fs);
            }
        }
    else
        {
        ret = iData->Length();
        }
    return ret;
    }
예제 #18
0
//See TestUtils::DatabaseSizeL().
//Returns the LogEng database size.
static TInt DatabaseSizeL()
	{
	TEntry file;
	LEAVE_IF_ERROR(theFs.Entry(KLogDatabaseName, file));
	return file.iSize;
	}
예제 #19
0
static void TestWithCaps(TUint32 aCaps, TInt aExpectedError, const TDesC& aFileName)
/**
	Helper function for TestWithCaps(TUint32, TInt).  This function invokes
	a helper executable with the supplied capabilities and tells it to delete
	the supplied filename.
	
 	@param	aCapMask		Capabilities of process which calls RLoader::Delete.
	@param	aExpectedError	Expected error reason.  The launched executable is expected
							to panic with category KTldPanicCat and this reason, which
							is the expected return code from RLoader::Delete.
	@param	aFileName		The helper executable is told to delete this file.
*/
	{
	test.Printf(
		_L("TestWithCaps,aCaps=0x%x,aExpectedError=%d,aFileName=\"%S\"\n"),
		aCaps, aExpectedError, &aFileName);

	TInt r;

	// create the file to delete
	RFs fs;
	r = fs.Connect();
	test(r == KErrNone);

	// if this file is expected to exist then create it
	TPtrC dirName;
	TBool shouldExist = (aFileName == KTldTcbFile || aFileName == KTldAllFilesFile);
	if (shouldExist)
		{
		TParsePtrC pp(aFileName);
		dirName.Set(pp.DriveAndPath());
		r = fs.MkDirAll(dirName);
		test(r == KErrNone || r == KErrAlreadyExists);
		CreateTestFile(fs, aFileName);
		}

	SetHelperCaps(aCaps);
	RunHelper(aFileName, aExpectedError);

	if (shouldExist)
		{
		// if the file could not be deleted then delete it now
		TEntry e;
		// a C++ bool for the following equality operator
		bool exists = (fs.Entry(aFileName, e) == KErrNone);
		test(exists == (aExpectedError != KErrNone));
		
		if (exists)
			{
			r = fs.Delete(aFileName);
			test(r == KErrNone);
			}

		// delete the immediate containing directory.  The error code is not
		// used because the directory may be used for something else.
		fs.RmDir(dirName);
		}

	// delete the generated different-caps file
	r = fs.Delete(_L("c:\\sys\\bin\\tld_helper_caps.exe"));
	test(r == KErrNone);
	r = fs.Delete(_L("c:\\sys\\hash\\tld_helper_caps.exe"));
	test(r == KErrNone || r == KErrNotFound || r == KErrPathNotFound);

	fs.Close();
	}
void IntegrityDeleteFileL(const TDesC& aPath, CIntegrityTreeLeaf* aLeaf, RFs& aFs, 
							   RLoader& aLoader, CFileMan& aFileMan)
	{
    _LIT(KSysBin, "\\sys\\bin");
	RBuf name;
	name.CreateL(aPath, KMaxFileName);
	CleanupClosePushL(name);
	name.Append(aLeaf->Name());

	TEntry entry;
	TInt err = aFs.Entry(name, entry);
	if (err == KErrNone)
		{
		aFs.SetAtt(name, 0, KEntryAttReadOnly);
		if(entry.IsDir())
			{
			// Make sure to append slash before calling RmDir - otherwise it deletes the parent directory			
			if (name[name.Length()-1] != KPathDelimiter) 
	  			{
  				name.Append(KPathDelimiter);
  				}
			User::LeaveIfError(aFileMan.RmDir(name));
			}
		else
			{			
            if ( aLeaf->Type() == EBackupFile ) // Implies a commit operation is in progress
                {
                
                 if ( IsBinary(entry) )
                     {
                     // Forming the file name so the renamed file can be under sys/bin
					 // for special delete mechanism using RLoader::Delete
                     RBuf tmpName;
                     TParsePtrC fileName(name);
                     tmpName.CreateL(name.Length() + KSysBin.iTypeLength);
                     CleanupClosePushL(tmpName);

                     tmpName.Append(fileName.Drive());
                     tmpName.Append(KSysBin);
                     tmpName.Append(fileName.Path());
                     tmpName.Append(fileName.NameAndExt());

					 DEBUG_PRINTF3(_L("Integrity Services - Renaming %S to %S"), &name, &tmpName);
                     aFileMan.Rename(name,tmpName,CFileMan::EOverWrite);
                     User::LeaveIfError(aLoader.Delete(tmpName)); // Using RLoader delete for paged binaries
					 DEBUG_PRINTF2(_L("Integrity Services - Deleted renamed file %S"), &tmpName);

					 // prune the directory tree if possible
                     RemoveDirectoryTreeL(aFs, tmpName);
                     CleanupStack::PopAndDestroy(&tmpName);
                     }
                 else
                     {
                     User::LeaveIfError(aFileMan.Delete(name));
                     }
                }
            else
                {
				// Need to use RLoader Delete which can be used during deletion of Added files during Rollback
                User::LeaveIfError(aLoader.Delete(name));
                }
			}
			
		// prune the directory tree if possible
		RemoveDirectoryTreeL(aFs, name);
		}
	else if(err != KErrNotFound && err != KErrPathNotFound)
		{
		DEBUG_PRINTF3(_L("Integrity Services - error %d removing %S"), err, &name);
		User::Leave(err);
		}
	else
	    {

		DEBUG_PRINTF3(_L("Integrity Services - error %d removing %S"), err, &name);

	    // Check for any renamed files to move it to sys/bin for special delete mechanism
	    RBuf tmpName;
	    TParsePtrC fileName(name);
	    tmpName.CreateL(name.Length() + KSysBin.iTypeLength);
	    CleanupClosePushL(tmpName);

	    tmpName.Append(fileName.Drive());
	    tmpName.Append(KSysBin);
	    tmpName.Append(fileName.Path());
	    tmpName.Append(fileName.NameAndExt());
		DEBUG_PRINTF2(_L("Integrity Services - Removing  %S renamed binary files if any"), &tmpName);

	    aLoader.Delete(tmpName);
		// prune the directory tree if possible
	    RemoveDirectoryTreeL(aFs, tmpName);
	    CleanupStack::PopAndDestroy(&tmpName);
	    }

	CleanupStack::PopAndDestroy(&name);
	}
예제 #21
0
static void TestL()
	{
	CHlpFileList* masterList = new(ELeave) CHlpFileList(5);
	CleanupStack::PushL(masterList);

	TInt i = EDriveY;
	FOREVER
		{
		// Make sure we go from Y -> C, then do Z last
		if	(i < EDriveC)
			i = EDriveZ;
		
		if	(DiskPresent(i))
			{

			{
			TChar driveLetter = '?';
			RFs::DriveToChar(i, driveLetter);
			TheTest.Printf(_L("\n\nDisk %c: is installed..."), static_cast<TUint>(driveLetter));
			}

			// This generates a list for a specific directory on the specified drive.
			CHlpFileList* list = BuildListForDriveLC(TDriveUnit(i), TheFs);

			// We now compare this list with our 'master' list to check for duplicates,
			// better matches, etc.
			TInt masterCount = masterList->Count();
			for(TInt j=masterCount-1; j>=0; j--)
				{
				CHlpFileEntry* entry = masterList->At(j);

				// This bit checks to see if an entry in the master list 
				// collides with an entry in the list we have just generated...
				//TBool foundCollision = EFalse;
				TInt newListCount = list->Count();
				for(TInt k=newListCount-1; k>=0; k--)
					{
					CHlpFileEntry* newEntry = list->At(k);
					__PRINT_FILE_NO(_L("Performing drive resolution on entry"), *newEntry, k);

					if	(entry->Name().CompareF(newEntry->Name()) == 0)
						{
						// Names are the same, so compare priorities...
						if	(newEntry->Type() == entry->Type())
							{
							// A file with the same name AND extension is already present in the array,
							// but are the UID's the same? If they are NOT, then the file
							// should be treated as a different help file to that of the 
							// existing array entry.
							TFileName file;

							TEntry existingTEntry;
							entry->GetFullNameAndPath(file);
							User::LeaveIfError(TheFs.Entry(file, existingTEntry));

							TEntry newTEntry;
							newEntry->GetFullNameAndPath(file);
							User::LeaveIfError(TheFs.Entry(file, newTEntry));

							if	(existingTEntry.MostDerivedUid() == newTEntry.MostDerivedUid())
								{
								// The uids and names of the files are the same. If the extensions are also the same
								// then we load the file on the drive tending to C:. However, if the extensions differ
								// we load the file with the extension tending to 01, i.e. UK English.
								if	(entry->FileName().CompareF(newEntry->FileName()) == 0)
									{
									// Name, uid and extensions are the same, therefore load the file on the drive
									// nearest C:. We do this by setting the priority of the existing entry to
									// EDsicarded so that it will force the next 'if' statement to fire, and hence
									// the existing entry will be replaced by the new one.
									entry->SetType(CHlpFileEntry::EDiscarded);
									__PRINT_FILE(_L("Uid, name, extension match. Saving entry tending to C: which is"), *newEntry);
									}
								else
									{
									// Name and uid the same, extensions different therefore load the file with
									// extension nearest to 01. If the new entry is nearer 01, then we set the
									// existing entry to discarded and therefore it will be removed at the next
									// 'if' statement.
									if	(entry->HelpFileLocale() > newEntry->HelpFileLocale())
										{
										entry->SetType(CHlpFileEntry::EDiscarded);
										__PRINT_FILE(_L("Uid & name match, extensions differ.\n Saving entry tending to H01 which is"), *newEntry);
										}
									else
										{
										__PRINT_FILE(_L("Uid & name match, extensions differ.\n Discarding new entry because it tends to H99"), *newEntry);
										}
									}
								}
							else
								{
								// This entry should be treated as a separate entity from the current
								// existing entry because it has different uid's. Therefore, we just
								// move on to check against the next existing entry in the list
								__PRINT_FILE(_L("Duplicate name and extension, but different uids detected. New entry == "), *newEntry);
								continue;
								}
							}

						// Is the new entry a better match than the existing one?
						if	(newEntry->Type() < entry->Type())
							{
							// The new entry is of a better 'quality' than the existing
							// entry, so remove the old and add the new...
							__PRINT_FILE(_L("Removing stored (new better match found)"), *entry);

							//foundCollision = ETrue;
							masterList->Delete(j);
							delete entry;
							masterList->AppendL(newEntry);

							// Remove it from the new list as the master list now takes
							// ownership...
							list->Delete(k);
							break;
							}
						else
							{
							// This entry is of lower quality than an existing
							// entry in the master list, so we can safely discard it.
							delete newEntry;
							list->Delete(k);
							}
						continue;
						}
					}
				}

			// At this point, anything that is left int the new list should
			// be valid to add to the master list...
			TInt newListCount = list->Count();
			for(TInt k=newListCount-1; k>=0; k--)
				{
				__PRINT_FILE_NO(_L("Saving entry"), *list->At(k), k);
				masterList->AppendL(list->At(k));
				}

			// We only destroy the list, rather than list+contents because each element
			// in the new list is now guaranteed to be present in the master list.
			CleanupStack::PopAndDestroy(); // list
			}

		if	(i-- == EDriveZ)
			break;
		}


	// Print out the master list
	TheTest.Printf(_L("\n\nThe help files that would be loaded are:-"));
	TheTest.Printf(_L("\n========================================="));
	TInt masterCount = masterList->Count();
	for(i=0; i<masterCount; i++)
		__PRINT_FILE_NO(_L("Entry"), *masterList->At(i), i);

	masterList->ResetAndDestroy();
	CleanupStack::PopAndDestroy(); // masterList
	}
예제 #22
0
/*
-------------------------------------------------------------------------------

    Class: TStifUtil

    Method: CorrectFilePath

    Description: Checks if file path contains drive letter. If not file is serched
                 on all drives and first hit is added to file name.

    Parameters: TDes& aFilePath: in/out: file path to correct

    Return Values: None

    Errors/Exceptions: Leaves if some of called leaving methods leaves

-------------------------------------------------------------------------------
*/
EXPORT_C void TStifUtil::CorrectFilePathL( TDes& aFilePath )
	{
	_LIT( KDriveSelector, ":\\" );
	_LIT( KDriveSelectorFormat_1, "%c:" );                                                                  
	_LIT( KDriveSelectorFormat_2, "%c:\\" );                                                                
	TChar KDriveZ = EDriveZ;//'Z';                                                                          
	                                                                                                              
	_LIT( KBackslash, "\\" );                                                                              
	                                                                                                                
	TInt length = aFilePath.Length();                                                                      
	                                                                                                                
	if (length == 0 )                                                                                     
	   {                                                                                                  
	   return;                                                                                            
	   }                                                                                                  
	if (length > 2 )                                                                                      
	   {                                                                                                  
	   // Check if file path contains drive selector                                                      
	   if ( aFilePath.Mid( 1, 2 ) == KDriveSelector )                                                     
	       {                                                                                               
	       // File path contains selector letter so we have nothing to do here                             
	       return;                                                                                         
	       }                                                                                               
	   }                                                                                                  
	                                                                                                                
	// Check if file path contains backslash at the begining and                                          
	// select proper drive selector format according to this information                                  
	TInt driveSelectorFormat = 2;                                                                         
	if ( aFilePath.Mid( 0, 1 ) == KBackslash )                                                            
	   {                                                                                               
	   driveSelectorFormat = 1;                                                                        
	   }                                                                                               
	                                                                                                                
	RFs rfs;                                                                                              
	if ( rfs.Connect() != KErrNone )                                                                      
	   {                                                                                                  
	   return;                                                                                            
	   }                                                                                                  
	                                                                                                                
	// Get available drives list, revers it order and move z drive at                                     
	// the end of the list.  
	TDriveList drivesList; 
	rfs.DriveList(drivesList); 

	// Set drive variable to last drive (except for Z, which will be checked at the end)
	char drive = 'Y' ;

	// Loop through all the drives in following order: YX..CBAZ
	while(drive >= 'A' && drive <= 'Z')
	     {
	     // Do further action only if drive exists
	     TInt driveint;
	     rfs.CharToDrive(drive, driveint);
	     if(drivesList[driveint])
	          {
	          //further checking (drive selector and file existence)
	          
	          // Prepare drive selector                                                                         
	          TBuf<3> driveSelector;                                                                            
	          if ( driveSelectorFormat == 1 )                                                                   
	              {                                                                                           
	              driveSelector.Format( KDriveSelectorFormat_1, drive );                                    
	              }                                                                                           
	          else if ( driveSelectorFormat == 2 )                                                              
	              {                                                                                           
	              driveSelector.Format( KDriveSelectorFormat_2, drive );                                    
	              }                                                                                           
	                                                                                                                
	          aFilePath.Insert( 0, driveSelector );                                                             
	                                                                                                                
	          TEntry entry;                                                                                     
	          if ( rfs.Entry(aFilePath, entry) == KErrNone )                                                    
	              {                                                                                         
	              rfs.Close();                                                                                
	              return;                                                                                     
	              }                                                                                           
	                                                                                                                
	          // File does not exists on selected drive. Restoring orginal file path                            
	          aFilePath.Delete( 0, driveSelector.Length() );    	         
	          }//if(drivesList[driveint])       
	            
	   // Select next drive
	   if(drive == 'Z')
	       break; // the last driver
	   else if(drive ==  'A' )
	       drive = 'Z'; //after checking A check Z
	   else
	       drive =  (TChar)(TInt(drive)-1) ; //after checking Y check X and so on in reverse alphabetical order
	   } //while 
	rfs.Close(); 
	}
예제 #23
0
/**
@SYMTestCaseID			PDS-SQL-UT-4142
@SYMTestCaseDesc		RFileBuf64 OOM test.
						The test calls RFileBuf64:Create(), RFileBuf64:Open() and RFileBuf64:Temp() in an OOM
						simulation loop and verifies that no memory is leaked.
@SYMTestActions			RFileBuf64 OOM test.
@SYMTestExpectedResults Test must not fail
@SYMTestPriority		High
@SYMREQ					REQ12106
                        REQ12109
*/
void OomTest(TOomTestType aOomTestType)
	{
	(void)TheFs.Delete(KTestFile);
	
	if(aOomTestType == EOomOpenTest)
		{
		RFile64 file;
		TInt err2 = file.Create(TheFs, KTestFile, EFileWrite | EFileRead);	
		file.Close();
		TEST2(err2, KErrNone);
		}
	
	TFileName tmpFileName;
	TInt err = KErrNoMemory;
	TInt failingAllocationNo = 0;
	RFileBuf64 fbuf(1024);
	TheTest.Printf(_L("Iteration:\r\n"));
	while(err == KErrNoMemory)
		{
		TheTest.Printf(_L(" %d"), ++failingAllocationNo);
		
		MarkHandles();
		MarkAllocatedCells();
		
		__UHEAP_MARK;
		__UHEAP_SETBURSTFAIL(RAllocator::EBurstFailNext, failingAllocationNo, KBurstRate);
		
		switch(aOomTestType)
			{
			case EOomCreateTest:
				err = fbuf.Create(TheFs, KTestFile, EFileWrite | EFileRead);
				break;
			case EOomOpenTest:
				err = fbuf.Open(TheFs, KTestFile, EFileWrite | EFileRead);
				break;
			case EOomTempTest:
				{
				err = fbuf.Temp(TheFs, KTestDir, tmpFileName, EFileWrite | EFileRead);
				}
				break;
			default:
				TEST(0);
				break;
			}
		fbuf.Close();
		
		__UHEAP_RESET;
		__UHEAP_MARKEND;

		CheckAllocatedCells();
		CheckHandles();
		
		TEntry entry;
		if(err != KErrNoMemory)
			{
			TEST2(err, KErrNone);	
			}
		else if(aOomTestType == EOomCreateTest)
			{
			TInt err2 = TheFs.Entry(KTestFile, entry);
			TEST2(err2, KErrNotFound);
			}
		else if(aOomTestType == EOomTempTest)
			{
			if(tmpFileName.Size() > 0)
				{
				TInt err2 = TheFs.Entry(tmpFileName, entry);
				TEST2(err2, KErrNotFound);
				}
			}
		}
	TEST2(err, KErrNone);
	TheTest.Printf(_L("\r\n=== OOM Test succeeded at heap failure rate of %d ===\r\n"), failingAllocationNo);
	
	if(aOomTestType == EOomTempTest)
		{
		(void)TheFs.Delete(tmpFileName);
		}
	(void)TheFs.Delete(KTestFile);
	}
예제 #24
0
void CBtMsgViewerUtils::GetMessagePathL(TPtr aMsgPath, const TInt aMessageId )
    {
    CMsvEntry* messageEntry = iMsvSession->GetEntryL(aMessageId);
    CleanupStack::PushL(messageEntry);
    
    TMsvEntry entry = messageEntry->Entry();
    if(entry.MtmData1() == KUidMsgTypeBtTInt32)
        {
        CMsvStore* store = messageEntry->ReadStoreL();
        CleanupStack::PushL(store);
        
        TInt attachmentCount = store->AttachmentManagerL().AttachmentCount();
        RFile attachmentFile;
        if(attachmentCount != 0)
            {
            //get file handle for the attachment & the complete path of the file
            attachmentFile = store->AttachmentManagerL().GetAttachmentFileL(0);
            CleanupClosePushL(attachmentFile);
            User::LeaveIfError(attachmentFile.FullName(aMsgPath));
            CleanupStack::PopAndDestroy(&attachmentFile);
            StoreMessageMimeTypeL(aMsgPath);
            
            //mark attachment as Read
            TMsvEntry attachEntry = messageEntry->Entry();
            attachEntry.SetUnread(EFalse);
            messageEntry->ChangeL(attachEntry);
            }
        else
            {
            CClientMtmRegistry* mtmReg = CClientMtmRegistry::NewL(*iMsvSession);
            CleanupStack::PushL(mtmReg); //1st Push
            
            CBIOClientMtm* bioClientMtm = (CBIOClientMtm*) mtmReg->NewMtmL(KBioUidValueUid);
            CleanupStack::PushL(bioClientMtm); //2nd Push
            
            bioClientMtm->SwitchCurrentEntryL(aMessageId);
            
            CMsvEntry* attachmentEntry = CMsvEntry::NewL(bioClientMtm->Session(),
                                        aMessageId,
                                        TMsvSelectionOrdering());
            CleanupStack::PushL(attachmentEntry); //3rd Push
            
            bioClientMtm->LoadMessageL();
    
            CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
            CleanupStack::PushL(selection); //4th Push
    
            selection->AppendL(aMessageId);
    
            TBuf8<1> aParameter;
            CMsvOperationActiveSchedulerWait* wait = CMsvOperationActiveSchedulerWait::NewLC();
            //5th Push
    
            CMsvOperation* operation = bioClientMtm->InvokeAsyncFunctionL(KBiosMtmParse, *selection,
                aParameter, wait->iStatus);
    
            wait->Start();
    
            CMsvStore* store = attachmentEntry->ReadStoreL();
            CleanupStack::PushL(store); //6th Push
            MMsvAttachmentManager& attachMan = store->AttachmentManagerL();
            
            attachmentFile = attachMan.GetAttachmentFileL(0);
            CleanupClosePushL(attachmentFile); //7th Push
            User::LeaveIfError(attachmentFile.FullName(aMsgPath));
            CleanupStack::PopAndDestroy(&attachmentFile);
            StoreMessageMimeTypeL(aMsgPath);
            
            //mark attachment as Read
            TMsvEntry attachEntry = attachmentEntry->Entry();
            attachEntry.SetUnread(EFalse);
            attachmentEntry->ChangeL(attachEntry);
            
            delete operation;
            CleanupStack::PopAndDestroy(6);
            }
        CleanupStack::PopAndDestroy(store);
        }
    else
        {
        CMsvEntry* attachmentEntry = iMsvSession->GetEntryL((*messageEntry)[0].Id());
        CleanupStack::PushL(attachmentEntry); //1st push
            
        CMsvStore* store = attachmentEntry->ReadStoreL();
        CleanupStack::PushL(store);  //2nd push
        
        TBuf<KMaxPath> attachmentName(store->AttachmentManagerL().GetAttachmentInfoL(0)->AttachmentName());
        RFs fs;
        User::LeaveIfError(fs.Connect());
        CleanupClosePushL(fs);
        TEntry entry;
        User::LeaveIfError(fs.Entry(attachmentName, entry));
        CleanupStack::PopAndDestroy(&fs);
        
        //get file handle for the attachment & the complete path of the file
        RFile attachmentFile;
        attachmentFile = store->AttachmentManagerL().GetAttachmentFileL(0);
        CleanupClosePushL(attachmentFile); //3rd Push
        User::LeaveIfError(attachmentFile.FullName(aMsgPath));
        CleanupStack::PopAndDestroy(&attachmentFile);
        StoreMessageMimeTypeL(aMsgPath);
        
        //mark attachment as Read
        TMsvEntry attachEntry = attachmentEntry->Entry();
        attachEntry.SetUnread(EFalse);
        attachmentEntry->ChangeL(attachEntry);
        
        CleanupStack::PopAndDestroy(store);
        CleanupStack::PopAndDestroy(attachmentEntry);
        }
    CleanupStack::PopAndDestroy(messageEntry);
    }