Esempio n. 1
0
int PosixFilesystem::chmod (RFs& aFs, const wchar_t* name, int perms, int& anErrno)
{
    TFullName fullName;
    TInt err=GetFullFile(fullName,(const TText16*)name,aFs);
    if (!err)
    {
        if ((perms&S_IWUSR)==0)
            err=aFs.SetAtt(fullName,KEntryAttReadOnly,0);
        else
            err=aFs.SetAtt(fullName,0,KEntryAttReadOnly);
    }
    return MapError(err, anErrno);
}
void CTestPostDeleteIni::deleteFileL(const TDesC& aFileName) 
	{
	// create a fileserver
	RFs  fileSystem;
	CTestExecuteLogger log = Logger();

	User::LeaveIfError(fileSystem.Connect());
	CleanupClosePushL(fileSystem);

	// Remove read only flag
	TInt ret = fileSystem.SetAtt(aFileName, 0, KEntryAttReadOnly);
	if (ret == KErrNotFound)
		{
		// If file already removed then no need to delete it
		log.Write(_L("File not found"));
		CleanupStack::PopAndDestroy(&fileSystem);
		return;
		}
	User::LeaveIfError(ret);

	log.Write(_L("Set file to read only"));

	// Delete file
	User::LeaveIfError(fileSystem.Delete(aFileName));
	log.Write(_L("deleted file"));

	// clean up
	CleanupStack::PopAndDestroy(&fileSystem);
	}
//See TestUtils::CopyCorruptDbL().
//See TestUtils::CopyOldDbL(). 
//See TestUtils::CopyCorruptDamagedDbL()
//
//The LogEng database will be replaced with a the database which name is passed as a parameter (for testing purposes).
//The LogEng server will be stopped.
//This call works only in debug mode.
static void CopyDatabaseL(const TDesC& aNewDatabase)
	{
	StopLogServerL();
	
	CFileMan* fileMan=CFileMan::NewL(theFs);
	CleanupStack::PushL(fileMan);
	
	DeleteDatabaseL(ETrue); // it won't be replaced as the server has stopped

  	TInt err = fileMan->Copy(aNewDatabase, KLogDatabaseName);
	if(err != KErrNone)
		{
		// Note this only works on textshell ROMs, techview ROMs fail here with KErrInUse (-14)
		RDebug::Print(_L("CopyDatabaseL(), File copy \"%S\" to \"%S\", err=%d\n"), &aNewDatabase, &KLogDatabaseName, err);
		LEAVE(err);
		}
	// files copied are sometimes read-only, so make read-write	
	err = theFs.SetAtt(KLogDatabaseName, 0, KEntryAttReadOnly);
	if(err != KErrNone)
		{
		RDebug::Print(_L("CopyDatabaseL(), Set \"%S\" file attributes err=%d\n"), &KLogDatabaseName, err);
		LEAVE(err);
		}

	CleanupStack::PopAndDestroy(); // fileMan
	}
Esempio n. 4
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);
		}
	}
LOCAL_C void ModifyTimeStampL(RFs &fs, TDesC *fileName, TTime aTime)
	{
	// Reset read-only bit
	User::LeaveIfError(fs.SetAtt(*fileName, 0, KEntryAttReadOnly));
	TTimeIntervalHours interval(1);
	TTime newTime=aTime+interval;
	User::LeaveIfError(fs.SetModified(*fileName, newTime));
	}
Esempio n. 6
0
void RmDir(const TDesC& aDirName)
	{
	TFileName filename_dir = aDirName;
	TInt r = 0;
	r = TheFs.SetAtt(filename_dir, 0, KEntryAttReadOnly);
	test_KErrNone(r);
	r=gFileMan->RmDir(filename_dir);
	test_Value(r, r == KErrNone || r==KErrNotFound || r==KErrPathNotFound || r==KErrInUse);
	}
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);
	}
Esempio n. 8
0
void DeleteFileL(const TDesC& aFile)
   {
   RFs fs;
   fs.Connect();
   CleanupClosePushL(fs);	
   fs.SetAtt(aFile, 0, KEntryAttReadOnly);
   //Ignore any errors as the file or path may not exist
   fs.Delete( aFile );
   CleanupStack::PopAndDestroy(&fs);
   
   }
Esempio n. 9
0
int PosixFilesystem::mkdir (RFs& aFs, const wchar_t* aPath, int perms, int& anErrno)
{
    TParse name;
    TInt err=GetFullPath(name,(const TText16 *)aPath,aFs,NULL);
    if (!err)
    {
        TPtrC path=name.DriveAndPath();
        err=aFs.MkDir(path);
        if (!err)
        {
            if ((perms&S_IWUSR)==0)
                err=aFs.SetAtt(path,KEntryAttReadOnly,0);
        }
    }
    return MapError(err,anErrno);
}
Esempio n. 10
0
void MakeFile(const TDesC& aFileName,TInt anAttributes)
//
// Make a file and write something in it
//
	{
	RFile file;
	TInt r=file.Replace(TheFs,aFileName,0);
	test_Value(r, r == KErrNone || r==KErrPathNotFound);
	if (r==KErrPathNotFound)
		{
		r=TheFs.MkDirAll(aFileName);
		test_KErrNone(r);
		r=file.Replace(TheFs,aFileName,0);
		test_KErrNone(r);
		}
	file.Close();
	r=TheFs.SetAtt(aFileName,anAttributes,0);
	test_KErrNone(r);
	}
TInt DoDeleteFileL(const TDesC& aFile)
	{
	TInt r = KErrNone;
	RFs fs;
	r = fs.Connect();
	if (r != KErrNone)
		{
			User::Leave(r);
		}
	
    // Make the file writeable 
    fs.SetAtt(aFile, 0, KEntryAttReadOnly);
	// Delete file using RFs
	TInt err = fs.Delete(aFile);
	RDebug::Print(_L("RFs Delete file %S - err = %d\n"), &aFile, err);
	
    fs.Close();
	return err;
	}
void CTcFileHandlerSession::DoDeleteFileL( const RMessage2& aMessage ) const
    {
    TFileName destinationPath;
    ReadFileNameL( 0, aMessage, destinationPath );
    
    // Connect to file server
	RFs fs;
	User::LeaveIfError( fs.Connect() );
	CleanupClosePushL( fs );

	// Clear read-only and system flags in order to be able to delete the file
	// Ignore errors.
	fs.SetAtt( destinationPath, 0, KEntryAttReadOnly | KEntryAttSystem );

	// Try deleting the file, report errors (typically KErrNotFound)
	User::LeaveIfError( fs.Delete( destinationPath ) );

	// Close file server session
	CleanupStack::PopAndDestroy();	// fs
    }
Esempio n. 13
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);
		}
	}
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);
	}
void SetReadOnly(RFs &fileSys, const TDesC16 &file, TBool attr)
{
	if(attr) fileSys.SetAtt(file, KEntryAttReadOnly, KEntryAttNormal);
	else fileSys.SetAtt(file, KEntryAttNormal, KEntryAttReadOnly);
}
Esempio n. 16
0
/**
@SYMTestCaseID			SYSLIB-SQL-UT-4060
@SYMTestCaseDesc		Private database and compaction configuration test.
						The test verifies that a private database can be created using auto, background or 
						manual compaction mode and that the compaction mode does not chage after reopening 
						the database.
						The test also verifies that if the database is legacy, read-only, then the compaction
						mode is auto.
						The test also verifies that if the database is legacy, r/w, then the compaction
						mode will be changed from auto to background.
@SYMTestPriority		Medium
@SYMTestActions			Private database and compaction configuration test.
@SYMTestExpectedResults Test must not fail
@SYMREQ					REQ10273
                        REQ10274
                        REQ10400
                        REQ10402
*/
void CompactConfigTest5L()
	{
	//Create a private test database with "auto" compaction mode
	_LIT8(KConfigStr1, "encoding=utf-8;compaction=auto");
	TInt err = TheDb.Create(KTestPrivDbName, &KConfigStr1);
	TEST2(err, KErrNone);
	//Check the vacuum mode. The SQLite vacuum mode should be "auto"
	TSqlScalarFullSelectQuery scalarQuery(TheDb);
	TInt compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum"));
	TEST2(compact, KAutoVacuum);
	TheDb.Close();
	//Close and open the database again. The SQLite vacuum mode should be "auto".
	err = TheDb.Open(KTestPrivDbName);
	TEST2(err, KErrNone);
	scalarQuery.SetDatabase(TheDb);
	compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum"));
	TEST2(compact, KAutoVacuum);
	TheDb.Close();
	//Close and open the database again with a config string with "background" compaction mode. 
	//The SQLite vacuum mode should stay unchanged.
	_LIT8(KConfigStr2, "compaction=background");
	err = TheDb.Open(KTestPrivDbName, &KConfigStr2);
	TEST2(err, KErrNone);
	scalarQuery.SetDatabase(TheDb);
	compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum"));
	TEST2(compact, KAutoVacuum);
	TheDb.Close();
	//Delete database
	err = RSqlDatabase::Delete(KTestPrivDbName);
	TEST2(err, KErrNone);
	//Create a private test database - no config string
	err = TheDb.Create(KTestPrivDbName);
	TEST2(err, KErrNone);
	//Check the vacuum mode. The SQLite vacuum mode should be KSqlDefaultVacuum
	scalarQuery.SetDatabase(TheDb);
	compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum"));
	TEST2(compact, KSqlDefaultVacuum);
	TheDb.Close();
	//Close and open the database again. The SQLite vacuum mode should be KSqlDefaultVacuum.
	err = TheDb.Open(KTestPrivDbName);
	TEST2(err, KErrNone);
	scalarQuery.SetDatabase(TheDb);
	compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum"));
	TEST2(compact, KSqlDefaultVacuum);
	TheDb.Close();
	//Close and open the database again with a config string with "auto" compaction mode. 
	//The SQLite vacuum mode should stay unchanged.
	err = TheDb.Open(KTestPrivDbName, &KConfigStr1);
	TEST2(err, KErrNone);
	scalarQuery.SetDatabase(TheDb);
	compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum"));
	TEST2(compact, KSqlDefaultVacuum);
	TheDb.Close();
	//Delete database
	err = RSqlDatabase::Delete(KTestPrivDbName);
	TEST2(err, KErrNone);
	//Open an existing private database that is read-only (on drive Z:)
	err = TheDb.Open(KTestPrivDbNameZ, &KConfigStr1);
	TEST2(err, KErrNone);
	//Check the vacuum mode. The SQLite compact mode should be "auto" (this is an old database (pre-"background compact" era))
	scalarQuery.SetDatabase(TheDb);
	compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum"));
	TEST2(compact, KAutoVacuum);
	TheDb.Close();
	//Open the same database after copying it to drive C: (r/w private database). The compaction mode should change from auto to background.
	RFs fs;
	err = fs.Connect();
	TEST2(err, KErrNone);
	CFileMan* fm = CFileMan::NewL(fs);
	TEST(fm != NULL);
	err = fm->Copy(KTestPrivDbNameZ, KTestPrivDbNameC);
	TEST2(err, KErrNone);
	//"Copy" operation executed without errors. Now it is a time to turn off the read-only
	//flag of the target file (which may be on if the source file is on a read-only drive)
	err = fs.SetAtt(KTestPrivDbNameC, 0, KEntryAttReadOnly);
	TEST2(err, KErrNone);
	delete fm;
	fs.Close();
	err = TheDb.Open(KTestPrivDbNameC);
	TEST2(err, KErrNone);
	scalarQuery.SetDatabase(TheDb);
	compact = scalarQuery.SelectIntL(_L("PRAGMA auto_vacuum"));
	TEST2(compact, KSqlDefaultVacuum);
	TheDb.Close();
	(void)RSqlDatabase::Delete(KTestPrivDbNameC);
	}