os/ossrv/lowlevellibsandfws/pluginfw/Framework/EcomTestUtils/t_processfilemanrename.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/lowlevellibsandfws/pluginfw/Framework/EcomTestUtils/t_processfilemanrename.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,71 @@
1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Helper process with high capability to perform renaming of files or folders for
1.18 +// test harnesses.
1.19 +//
1.20 +//
1.21 +
1.22 +#include <f32file.h>
1.23 +#include <e32debug.h>
1.24 +
1.25 +
1.26 +_LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames
1.27 +
1.28 +TInt DoRenameFileL(const TDesC& anOld,const TDesC& aNew)
1.29 + {
1.30 + TInt r = KErrNone;
1.31 + RFs fs;
1.32 + r = fs.Connect();
1.33 + if (r != KErrNone)
1.34 + {
1.35 + User::Leave(r);
1.36 + }
1.37 + CFileMan* fileMan = CFileMan::NewL(fs);
1.38 + CleanupStack::PushL(fileMan);
1.39 + // Ensure the path exists
1.40 + TInt err = fs.MkDirAll(aNew);
1.41 + // Make the destination file writeable
1.42 + err = fileMan->Attribs(aNew, 0, KEntryAttReadOnly, TTime(0), 0);
1.43 + // To process
1.44 + err = fileMan->Rename(anOld, aNew);
1.45 + RDebug::Print(_L("CFileMan Rename file or folder from %S to %S - err = %d\n"), &anOld, &aNew, err);
1.46 +
1.47 + CleanupStack::PopAndDestroy(fileMan);
1.48 + fs.Close();
1.49 +
1.50 + return err;
1.51 + }
1.52 +
1.53 +// Copy the files specified. Format of aFileNames is [srcFile]|[dstFile].
1.54 +static TInt RenameFile(const TDesC& aFileNames)
1.55 + {
1.56 + TInt pos = aFileNames.Find(KSeparator);
1.57 + TFileName srcFile(aFileNames.Mid(0,pos));
1.58 + TFileName dstFile(aFileNames.Mid(pos+1, aFileNames.Length()-(pos+1)));
1.59 +
1.60 + TRAPD(err,DoRenameFileL(srcFile, dstFile));
1.61 + return err;
1.62 + }
1.63 +
1.64 +
1.65 +GLDEF_C TInt E32Main()
1.66 + {
1.67 + CTrapCleanup* cleanup = CTrapCleanup::New();
1.68 +
1.69 + TBuf<KMaxFileName*2> names;
1.70 + User::CommandLine(names);
1.71 + TInt err = RenameFile(names);
1.72 + delete cleanup;
1.73 + return err;
1.74 + }