|
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 files for |
|
15 // test harnesses. |
|
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 |
|
26 // Copy the files specified. |
|
27 void CopyFileL(const TDesC& anOld, const TDesC& aNew) |
|
28 { |
|
29 RFs fs; |
|
30 fs.Connect(); |
|
31 CleanupClosePushL(fs); |
|
32 |
|
33 CFileMan* fileMan = CFileMan::NewL(fs); |
|
34 CleanupStack::PushL(fileMan); |
|
35 |
|
36 // Ensure the path exists |
|
37 TInt err = fs.MkDirAll(aNew); |
|
38 if ((err != KErrNone) && (err != KErrAlreadyExists)) |
|
39 User::Leave(err); |
|
40 |
|
41 // Make the destination file writeable |
|
42 err = fileMan->Attribs(aNew, 0, KEntryAttReadOnly, TTime(0), 0); |
|
43 if ((err != KErrNone) && (err != KErrNotFound)) |
|
44 User::Leave(err); |
|
45 |
|
46 // Do the file copy |
|
47 User::LeaveIfError(fileMan->Copy(anOld, aNew)); |
|
48 |
|
49 CleanupStack::PopAndDestroy(2); |
|
50 } |
|
51 |
|
52 |
|
53 // Format of aFileNames is [srcFile]|[dstFile] |
|
54 GLDEF_C TInt E32Main() |
|
55 { |
|
56 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
57 |
|
58 TBuf<KMaxFileName*2> names; |
|
59 User::CommandLine(names); |
|
60 TInt pos = names.Find(KSeparator); |
|
61 TFileName srcFile(names.Mid(0,pos)); |
|
62 TFileName dstFile(names.Mid(pos+1, names.Length()-(pos+1))); |
|
63 |
|
64 TInt err = KErrNone; |
|
65 TRAP(err,CopyFileL(srcFile, dstFile)); |
|
66 if (err == KErrNone) |
|
67 RDebug::Print(_L("CFileMan Copy file '%S' to '%S' succeeded.\n"), &srcFile, &dstFile); |
|
68 else |
|
69 RDebug::Print(_L("CFileMan Copy file '%S' to '%S' failed with error = %d.\n"), &srcFile, &dstFile, err); |
|
70 |
|
71 delete cleanup; |
|
72 return err; |
|
73 } |