lowlevellibsandfws/pluginfw/Framework/EcomTestUtils/t_processrfsreplacefile.cpp
changeset 0 e4d67989cc36
child 44 97b0fb8a2cc2
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Helper process with high capability to perform copying of using Rfs
       
    15 // files for test harness. 
       
    16 // 
       
    17 //
       
    18 
       
    19 #include <f32file.h>
       
    20 #include <e32debug.h>
       
    21 
       
    22 
       
    23 _LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames
       
    24 
       
    25 TInt DoReplaceFileL(const TDesC& anOld,const TDesC& aNew)
       
    26 	{
       
    27 	RFs fs;
       
    28 	fs.Connect();
       
    29 
       
    30 	// Ensure the path exists
       
    31 	TInt err = fs.MkDirAll(aNew);
       
    32     // Make the new file writeable 
       
    33     err = fs.SetAtt(aNew, 0, KEntryAttReadOnly);
       
    34 	// Replace
       
    35     err = fs.Replace(anOld, aNew);
       
    36     RDebug::Print(_L("RFs Replace file %S to %S - err = %d\n"), &anOld, &aNew, err);
       
    37     
       
    38     fs.Close();
       
    39 	return err;
       
    40 	}
       
    41 
       
    42 	
       
    43 // Copy the files specified.  Format of aFileNames is [srcFile]|[dstFile].
       
    44 static TInt ReplaceFile(const TDesC& aFileNames)
       
    45 	{	
       
    46 	TInt pos = aFileNames.Find(KSeparator);
       
    47 	
       
    48 	TFileName srcFile(aFileNames.Mid(0,pos));
       
    49 	TFileName dstFile(aFileNames.Mid(pos+1, aFileNames.Length()-(pos+1)));
       
    50 			
       
    51 	TRAPD(err,DoReplaceFileL(srcFile, dstFile));
       
    52 	return err;
       
    53 	}
       
    54 
       
    55 
       
    56 GLDEF_C TInt E32Main()
       
    57 	{
       
    58 	CTrapCleanup* cleanup =	CTrapCleanup::New(); 
       
    59 	
       
    60 	TBuf<KMaxFileName*2> names;
       
    61 	User::CommandLine(names);
       
    62 	TInt err = ReplaceFile(names);
       
    63 	delete cleanup;
       
    64 	return err;
       
    65 	}