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; } }
/** * 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); }
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); } }
// Reset Mail Store(Mail2) so that old messages are deleted when new index file created.. void CMsvIndexContext::ResetAndCreateNewMailStoreL(TBool aDelete) { CFileMan* fileMan = CFileMan::NewL(iServer.FileSession()); CleanupStack::PushL(fileMan); if(aDelete) { //Check if the mailfolder exists.. if(BaflUtils::FileExists(iServer.FileSession(), iMessageFolder)) { // Remove the readonly attribute.. (void)fileMan->Attribs(iMessageFolder,0, KEntryAttReadOnly, TTime(0), CFileMan::ERecurse); // Remove old message store if exists.. User::LeaveIfError(fileMan->RmDir(iMessageFolder)); } } // Create the folder for the message store TInt err = iServer.FileSession().MkDirAll(iMessageFolder); if(err != KErrAlreadyExists) { User::LeaveIfError(err); } 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 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); } }
void CenrepSwiOOMTest::UninstallROMUpgradeL(TBool aIsSetup) { if(aIsSetup) { // Install rev 2 UpgradeROMRev2L(ETrue); UpgradeROMRev2L(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(KUpgradeFile,0,KEntryAttReadOnly,TTime(0))); TInt err=fs.Delete(KUpgradeFile); if((err!=KErrNone)&&(err!=KErrNotFound)) User::Leave(err); CleanupStack::PopAndDestroy(2); // fs and fm } else { iSwiWatcher->HandleSWIEventL(ESASwisUninstall | ESASwisStatusSuccess); } }
//The function deletes a directory, identified by the aFullPath argument. //The function leaves if the delete operation error is different than KErrNone and KErrNotFound. static void DoDeleteTestDirL(CFileMan& aFm, const TDesC& aFullPath) { TInt err = aFm.Attribs(aFullPath, 0, KEntryAttReadOnly, TTime(0)); if(err == KErrNone) { err = aFm.RmDir(aFullPath); } if(err != KErrNone && err != KErrNotFound) { User::Leave(err); } }
// 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 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); } }
/** * UpdateDriveStatusL() * @param TUint: The index of the said drive in preferred * drive list. */ void CMsvIndexContext::UpdateDriveStatusL(TUint aDriveIndex, TDriveState& aStoreStatus) { aStoreStatus = EMsvInvalidDriveStatus; TBool deleteStore = EFalse; TMsvPreferredDrive driveEntry; CMsvPreferredDriveList::GetDriveList()->DriveInfoL(aDriveIndex, driveEntry); // Check if the media is available in the drive. TVolumeInfo volume; if (iServer.FileSession().Volume(volume, driveEntry.driveNum) != KErrNone) { CMsvPreferredDriveList::GetDriveList()->UpdateDriveStatusL(aDriveIndex, EMsvDriveDiskNotAvailableStatus); aStoreStatus = EMsvDriveDiskNotAvailableStatus; return; } // Validate the database. The function opens the database // and check its version and returns appropriate error. TRAPD(err, CMsvDBAdapter::ValidateDatabaseL(driveEntry.driveNum)); // If no error, database is available. if(KErrNone == err) { CMsvPreferredDriveList::GetDriveList()->UpdateDriveStatusL(aDriveIndex, EMsvMessageStoreAvailableStatus); return; } // If the database is not found in the drive. if(KErrNotFound == err) { // Check if index file exists. RFile file; TParse parse; TPtrC drive(TDriveUnit(driveEntry.driveNum).Name()); parse.Set(KMsvDefaultIndexFile2, &drive, NULL); TFileName indexFileName = parse.FullName(); err = file.Open(iServer.FileSession(), indexFileName, EFileShareAny|EFileWrite); //file.Close(); // If index file exists, set drive status to NOT SUPPORTED. if(KErrNone == err) { CPermanentFileStore* fileStoreIndex = NULL; TRAPD(permError, fileStoreIndex = CPermanentFileStore::FromL(file)); if(KErrNone == permError) { // Check if the store is corrupt. If so then delete it. if (fileStoreIndex->Type() != TUidType(KPermanentFileStoreLayoutUid, KUidMsvIndexFile)) { deleteStore = ETrue; } } // There was an error in getting a permanent filestore object. // Mark the message store for deletion. else { deleteStore = ETrue; } delete fileStoreIndex; //If message store is corrupted, wipe it. if(deleteStore) { TFileName mail2Folder = parse.DriveAndPath(); CFileMan* fileMan = CFileMan::NewL(iServer.FileSession()); // Remove the readonly attribute.. (void)fileMan->Attribs(mail2Folder, 0, KEntryAttReadOnly, TTime(0), CFileMan::ERecurse); CleanupStack::PushL(fileMan); //Check if the mailfolder exists.. TBool mail2FolderExists = BaflUtils::FileExists(iServer.FileSession(), mail2Folder); if(mail2FolderExists) { // Remove old message store if exists.. User::LeaveIfError(fileMan->RmDir(mail2Folder)); } CleanupStack::PopAndDestroy(fileMan); CMsvPreferredDriveList::GetDriveList()->UpdateDriveStatusL(aDriveIndex, EMsvMessageStoreUnavailableStatus); aStoreStatus = EMsvMessageStoreCorruptStatus; // Create store delete file in the respective drive. CreateStoreDeleteFile(driveEntry.driveNum); } //Else only set status as EMsvMessageStoreNotSupportedStatus. else { CMsvPreferredDriveList::GetDriveList()->UpdateDriveStatusL(aDriveIndex, EMsvMessageStoreNotSupportedStatus); aStoreStatus = EMsvMessageStoreNotSupportedStatus; } file.Close(); return; } // If index file does not exists, set drive status to STORE UNAVAILABLE. if((KErrNotFound == err) || (KErrPathNotFound == err)) { CMsvPreferredDriveList::GetDriveList()->UpdateDriveStatusL(aDriveIndex, EMsvMessageStoreUnavailableStatus); aStoreStatus = EMsvMessageStoreUnavailableStatus; return; } User::Leave(err); } //If a database exists, but is corrupt. if( (KSqlErrCorrupt == err) || (KSqlErrNotDb == err) ) { // If the database is corrupt, delete // the database and old message store. // Delete the database. TParse parse; TPtrC drive(TDriveUnit(driveEntry.driveNum).Name()); parse.Set(KDBFileName, &drive, NULL); TFileName dBFile = parse.FullName(); RSqlDatabase::Delete(dBFile); // Delete the message store. //ISSUE Can we use ResetAndCreateNewMailStore()? parse.Set(KMsvDefaultIndexFile2, &drive, NULL); TFileName mail2Folder = parse.DriveAndPath(); CFileMan* fileMan = CFileMan::NewL(iServer.FileSession()); // Remove the readonly attribute.. (void)fileMan->Attribs(mail2Folder, 0, KEntryAttReadOnly, TTime(0), CFileMan::ERecurse); CleanupStack::PushL(fileMan); //Check if the mailfolder exists.. TBool mail2FolderExists = BaflUtils::FileExists(iServer.FileSession(), mail2Folder); if( mail2FolderExists) { // Remove old message store if exists.. User::LeaveIfError(fileMan->RmDir(mail2Folder)); } CleanupStack::PopAndDestroy(fileMan); // Update the drive status. CMsvPreferredDriveList::GetDriveList()->UpdateDriveStatusL(aDriveIndex, EMsvMessageStoreUnavailableStatus); aStoreStatus = EMsvMessageStoreCorruptStatus; // Create store delete file in the respective drive. CreateStoreDeleteFile(driveEntry.driveNum); return; } //If the database version is not supported. if(KErrNotSupported == err) { // If the drive as old version of database. CMsvPreferredDriveList::GetDriveList()->UpdateDriveStatusL(aDriveIndex, EMsvMessageStoreNotSupportedStatus); aStoreStatus = EMsvMessageStoreNotSupportedStatus; return; } // Do not return DB error. if(err <= KSqlErrGeneral) { // If DB Error, return KErrGeneral. User::LeaveIfError(KErrGeneral); } else { User::LeaveIfError(err); } }
LOCAL_C void DoOOMTestsL() { TheTest.Next (_L (" @SYMTestCaseID:SYSLIB-CENTRALREPOSITORY-LEGACY-T_OOMCENREP-0001 Starting CENREPSRV OOM Test ")); RFs fs; User::LeaveIfError(fs.Connect()); CleanupClosePushL(fs); CFileMan* fm = CFileMan::NewL(fs); CleanupStack::PushL(fm); //Clear any files in the persist directory CleanupCDriveL(); //First Testuid=KTestRepositoryUid KCurrentTestUid=KTestRepositoryUid; DoOOMTestL(&CenrepSrvOOMTest::GetL,_L("Get Basic Test"),EFalse); DoOOMTestL(&CenrepSrvOOMTest::FindL,_L("FindL Basic Test"),EFalse); DoOOMTestL(&CenrepSrvOOMTest::NotifyL,_L("NotifyL Basic Test"),EFalse); DoOOMTestL(&CenrepSrvOOMTest::ResetL,_L("ResetL Basic Test"),EFalse); // Save file without timestamp User::LeaveIfError(fm->Copy(KPersistsFile, KPersistsFileNoUpgrade)); DoOOMTestL(&CenrepSrvOOMTest::SetL,_L("SetL Basic Test"),EFalse); DoOOMTestL(&CenrepSrvOOMTest::CreateL,_L("CreateL Basic Test"),EFalse); DoOOMTestL(&CenrepSrvOOMTest::DeleteL,_L("DeleteL Basic Test"),EFalse); DoOOMTestL(&CenrepSrvOOMTest::MoveL,_L("MoveL Basic Test"),EFalse); //Clear any files in the persist directory CleanupCDriveL(); // Simulate response to SWI rom-upgrade and downgrade events DoOOMSwiTestL(&CenrepSwiOOMTest::UpgradeROMRev1L,_L("SwiUpgradeROMRev1L Basic Test"),EFalse); // Save file with timestamp User::LeaveIfError(fm->Copy(KPersistsFile, KPersistsFileUpgraded)); DoOOMSwiTestL(&CenrepSwiOOMTest::UpgradeROMRev2L,_L("SwiUpgradeROMRev2L Basic Test"),EFalse); DoOOMSwiTestL(&CenrepSwiOOMTest::UninstallROMUpgradeL,_L("SwiUninstallROMUpgradeL Basic Test"),EFalse); // Simulate response to SWI new rep install/uninstall event events DoOOMSwiTestL(&CenrepSwiOOMTest::InstallL,_L("SwiInstallL Basic Test"),EFalse); DoOOMSwiTestL(&CenrepSwiOOMTest::UpgradeInstallL,_L("SwiUpgradeInstallL Basic Test"),EFalse); DoOOMSwiTestL(&CenrepSwiOOMTest::UninstallL,_L("SwiUninstallL Basic Test"),EFalse); // Simulate SWI events before server startup DoOOMNoServReposL(&StartupUpgradeL, _L("Startup Upgrade Basic Test"), EFalse); DoOOMNoServReposL(&StartupDowngradeL, _L("Startup Downgrade Basic Test"), EFalse); DoOOMNoServReposL(&StartupUninstallL,_L("Startup Uninstall Basic Test"), EFalse); //OOM Test aOOMMode=ETrue DoOOMNoServReposL(&CreateDeleteL, _L("Create Delete OOM Test"),ETrue); DoOOMNoServReposL(&CreateDeleteCorruptL, _L("Create Delete Corrupt OOM Test"),ETrue); DoOOMTestL(&CenrepSrvOOMTest::GetL,_L("Get OOM Test"),ETrue); DoOOMTestL(&CenrepSrvOOMTest::FindL,_L("FindL OOM Test"),ETrue); DoOOMTestL(&CenrepSrvOOMTest::NotifyL,_L("NotifyL OOM Test"),ETrue); DoOOMTestL(&CenrepSrvOOMTest::ResetL,_L("ResetL OOM Test"),ETrue); DoOOMTestL(&CenrepSrvOOMTest::SetL,_L("SetL OOM Test"),ETrue); DoOOMTestL(&CenrepSrvOOMTest::CreateL,_L("CreateL OOM Test"),ETrue); DoOOMTestL(&CenrepSrvOOMTest::DeleteL,_L("DeleteL OOM Test"),ETrue); DoOOMTestL(&CenrepSrvOOMTest::MoveL,_L("MoveL OOM Test"),ETrue); //Clear any files in the persist directory CleanupCDriveL(); DoOOMSwiTestL(&CenrepSwiOOMTest::UpgradeROMRev1L,_L("SwiUpgradeROMRev1L OOM Test"),ETrue); DoOOMSwiTestL(&CenrepSwiOOMTest::UpgradeROMRev2L,_L("SwiUpgradeROMRev2L OOM Test"),ETrue); DoOOMSwiTestL(&CenrepSwiOOMTest::UninstallROMUpgradeL,_L("SwiUninstallROMUpgradeL OOM Test"),ETrue); DoOOMSwiTestL(&CenrepSwiOOMTest::InstallL,_L("SwiInstallL OOM Test"),ETrue); DoOOMSwiTestL(&CenrepSwiOOMTest::UpgradeInstallL,_L("SwiUpgradeInstallL OOM Test"),ETrue); DoOOMSwiTestL(&CenrepSwiOOMTest::UninstallL,_L("SwiUninstallL OOM Test"),ETrue); DoOOMNoServReposL(&StartupUpgradeL, _L("Startup Upgrade OOM Test"), ETrue); DoOOMNoServReposL(&StartupDowngradeL, _L("Startup Downgrade OOM Test"), ETrue); DoOOMNoServReposL(&StartupUninstallL, _L("Startup Uninstall OOM Test"), ETrue); #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS DoPersistedVersionCheckingL(); DoOOMMultiRofsTestL(); #endif // Delete files from bur dir User::LeaveIfError(fm->Attribs(KPersistsFileNoUpgrade,0,KEntryAttReadOnly,TTime(0))); TInt err=fs.Delete(KPersistsFileNoUpgrade); if((err!=KErrNone)&&(err!=KErrNotFound)) User::Leave(err); User::LeaveIfError(fm->Attribs(KPersistsFileUpgraded,0,KEntryAttReadOnly,TTime(0))); err=fs.Delete(KPersistsFileUpgraded); if((err!=KErrNone)&&(err!=KErrNotFound)) User::Leave(err); //Clear any files in the persist directory CleanupCDriveL(); CleanupStack::PopAndDestroy (2); // fs and fm }