author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 15 Sep 2010 13:42:27 +0300 | |
branch | RCL_3 |
changeset 268 | 345b1ca54e88 |
parent 257 | 3e88ff8f41d5 |
child 294 | 039a3e647356 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1996-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 the License "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 |
// |
|
15 |
||
16 |
#include "cl_std.h" |
|
17 |
||
257 | 18 |
#define RETURNIFERROR(a,b,t) \ |
19 |
{ \ |
|
20 |
if ((a=b)!=KErrNone) \ |
|
21 |
{ \ |
|
22 |
if(iStatus) \ |
|
23 |
User::RequestComplete(iStatus,a); \ |
|
24 |
TInt _t = t; \ |
|
25 |
if (_t) {TRACE1(UTF::EBorder, t, MODULEUID, a);} \ |
|
26 |
return(a); \ |
|
27 |
} \ |
|
28 |
} |
|
29 |
||
30 |
#define RETURNIFERRORD(a,b,t) \ |
|
31 |
TInt a; \ |
|
32 |
RETURNIFERROR(a,b,t) |
|
0 | 33 |
|
34 |
const TUint KRecurseFlag = 0x40000000; |
|
35 |
const TUint KScanDownFlag = 0x20000000; |
|
36 |
const TUint KFManBusyFlag = 0x10000000; |
|
37 |
const TUint KOverWriteFlag = 0x08000000; |
|
38 |
const TUint KMoveRenameFlag = 0x04000000; |
|
39 |
const TUint KCopyFromHandle = 0x00000001; |
|
40 |
||
41 |
const TInt KPathIncGran=32; |
|
42 |
||
43 |
const TUint KMovingFilesMask = KEntryAttMatchExclude | KEntryAttDir; |
|
44 |
||
45 |
TInt ShrinkNames(RFs& aFs, TFileName& aParent, TFileName& aItem, TBool aAppend); |
|
46 |
||
47 |
LOCAL_C HBufC8* AllocateBuffer(TInt64 aLength) |
|
48 |
{ |
|
49 |
const TInt KBigBufSize = 512 * 1024; |
|
50 |
const TInt KMediumBufSize = 32 * 1024; |
|
51 |
const TInt KSmallBufSize = 4 * 1024; |
|
52 |
// Min result shall be of TInt size |
|
53 |
// Hence to suppress warning |
|
54 |
TInt big = (TInt)(Min(aLength,(TInt64)KBigBufSize)); |
|
55 |
HBufC8* bufPtr=HBufC8::New(big); |
|
56 |
if (bufPtr==NULL) |
|
57 |
bufPtr=HBufC8::New(KMediumBufSize); |
|
58 |
if (bufPtr==NULL) |
|
59 |
bufPtr=HBufC8::New(KSmallBufSize); |
|
60 |
return(bufPtr); |
|
61 |
} |
|
62 |
||
63 |
LOCAL_C TInt IncPathLength(TInt aLen) |
|
64 |
{ |
|
65 |
return(((aLen+KPathIncGran-1)/KPathIncGran)*KPathIncGran); |
|
66 |
} |
|
67 |
||
68 |
LOCAL_C TInt CreateTargetNameFromSource(TDes& aTrgName, const TDesC& aTrgMask, const TDesC& aSrcName) |
|
69 |
// Replace the wildcards with letters from the matched file. |
|
70 |
{ |
|
71 |
TFileName destName; |
|
72 |
TParsePtrC trg(aTrgMask); |
|
73 |
TParsePtrC src(aSrcName); |
|
74 |
TPtrC mask(trg.NameAndExt()); |
|
75 |
TPtrC source(src.NameAndExt()); |
|
76 |
TInt steps = 1; |
|
77 |
TBool starCharFound = EFalse; |
|
78 |
if(mask.LocateReverse('.')!=KErrNotFound || aTrgMask.Right(1)==_L("*")) |
|
79 |
{ |
|
80 |
mask.Set(trg.Name()); |
|
81 |
source.Set(src.Name()); |
|
82 |
steps = 2; |
|
83 |
} |
|
84 |
for(TInt i = 0; i < steps; |
|
85 |
i++, mask.Set(trg.ExtPresent() ? trg.Ext() : _L(".*")) , source.Set(src.Ext())) |
|
86 |
{ |
|
87 |
TInt offset = 0; |
|
88 |
starCharFound = EFalse; |
|
89 |
while(offset < mask.Length()) |
|
90 |
{ |
|
91 |
TChar currentChar = mask[offset]; |
|
92 |
switch(currentChar) |
|
93 |
{ |
|
94 |
case KMatchAny: |
|
95 |
if(offset < source.Length() && !starCharFound) |
|
96 |
{ |
|
97 |
destName.Append(source.Mid(offset)); |
|
98 |
starCharFound = ETrue; |
|
99 |
} |
|
100 |
break; |
|
101 |
case KMatchOne: |
|
102 |
if(offset < source.Length()) |
|
103 |
{ |
|
104 |
destName.Append(source[offset]); |
|
105 |
} |
|
106 |
break; |
|
107 |
default: |
|
108 |
destName.Append(currentChar); |
|
109 |
break; |
|
110 |
} |
|
111 |
offset++; |
|
112 |
} |
|
113 |
} |
|
114 |
if(destName.Right(1) == _L(".")) |
|
115 |
{ |
|
116 |
destName.SetLength(destName.Length()-1); |
|
117 |
} |
|
118 |
if(aTrgName.Length()+destName.Length() > KMaxFileName) |
|
119 |
{ |
|
120 |
return KErrBadName; |
|
121 |
} |
|
122 |
aTrgName.Append(destName); |
|
123 |
return KErrNone; |
|
124 |
} |
|
125 |
||
126 |
EXPORT_C MFileManObserver::TControl MFileManObserver::NotifyFileManStarted() |
|
127 |
/** |
|
128 |
Inform the observer that an operation is about to start. |
|
129 |
||
130 |
This is done immediately before each entry is processed. |
|
131 |
||
132 |
@return The implementation of this function should return: |
|
133 |
MFileManObserver::EContinue, to allow processing of the current file |
|
134 |
to proceed; |
|
135 |
MFileManObserver::ECancel, to skip processing the current file and move |
|
136 |
to the next file; |
|
137 |
MFileManObserver::EAbort to abort the entire operation. |
|
138 |
The default return value is MFileManObserver::EContinue. |
|
139 |
*/ |
|
140 |
{ |
|
141 |
||
142 |
return(EContinue); |
|
143 |
} |
|
144 |
||
145 |
||
146 |
||
147 |
||
148 |
EXPORT_C MFileManObserver::TControl MFileManObserver::NotifyFileManOperation() |
|
149 |
/** |
|
150 |
Informs the observer that an operation, i.e. a copy or a move, is proceeding. |
|
151 |
||
152 |
Large files are copied and moved in stages. |
|
153 |
After each portion of the source file has been copied to the target, this |
|
154 |
function is called. |
|
155 |
||
156 |
It may be useful to call CFileMan::BytesTransferredByCopyStep() from this |
|
157 |
function to retrieve the current status of the operation. |
|
158 |
||
159 |
@return The implementation of this function should return: |
|
160 |
MFileManObserver::ECancel, to cancel the current operation, closing the current source |
|
161 |
and target files, the current target file is deleted. |
|
162 |
If the operation is performed on several files, cancelling one will not abort whole batch. |
|
163 |
||
164 |
MFileManObserver::EContinue, to continue with the operation. |
|
165 |
The default return value is MFileManObserver::EContinue. |
|
166 |
||
167 |
@see CFileMan |
|
168 |
*/ |
|
169 |
{ |
|
170 |
||
171 |
return(EContinue); |
|
172 |
} |
|
173 |
||
174 |
||
175 |
||
176 |
||
177 |
EXPORT_C MFileManObserver::TControl MFileManObserver::NotifyFileManEnded() |
|
178 |
/** |
|
179 |
Informs the observer that an operation is complete. |
|
180 |
||
181 |
This is done immediately after a directory entry has been processed. |
|
182 |
||
183 |
It may be useful to call CFileBase::GetLastError() |
|
184 |
and CFileBase::GetMoreInfoAboutError() from this function to retrieve |
|
185 |
information about how the operation ended. |
|
186 |
||
187 |
@return The implementation of this function should return: |
|
188 |
MFileManObserver::EContinue or MFileManObserver::ECancel, to proceed |
|
189 |
with processing the next entry. MFileManObserver::ECancel will not |
|
190 |
cancel processing the current entry; |
|
191 |
MFileManObserver::ERetry, to re-attempt processing the previous file; |
|
192 |
MFileManObserver::EAbort, to abort the entire operation. |
|
193 |
The default return value is MFileManObserver::EContinue. |
|
194 |
||
195 |
@see CFileBase |
|
196 |
*/ |
|
197 |
{ |
|
198 |
||
199 |
return(EContinue); |
|
200 |
} |
|
201 |
||
202 |
||
203 |
||
204 |
||
205 |
EXPORT_C CFileBase::CFileBase(RFs& aFs) |
|
206 |
/** |
|
207 |
Protected default constructor. |
|
208 |
||
209 |
Note that the class is intended only as an abstract base for other classes. |
|
210 |
||
211 |
@param aFs File server session. |
|
212 |
*/ |
|
213 |
: iFs(aFs) |
|
214 |
{ |
|
215 |
} |
|
216 |
||
217 |
||
218 |
||
219 |
||
220 |
EXPORT_C void CFileBase::ConstructL() |
|
221 |
/** |
|
222 |
Second phase constructor. |
|
223 |
*/ |
|
224 |
{ |
|
225 |
||
226 |
iScanner=CDirScan::NewL(iFs); |
|
227 |
User::LeaveIfError(iSynchronizer.CreateLocal(0)); |
|
228 |
} |
|
229 |
||
230 |
||
231 |
||
232 |
||
233 |
EXPORT_C CFileBase::~CFileBase() |
|
234 |
/** |
|
235 |
Destructor. |
|
236 |
||
237 |
Frees resources prior to destruction of the object. |
|
238 |
*/ |
|
239 |
{ |
|
240 |
||
241 |
delete iScanner; |
|
242 |
delete iDirList; |
|
243 |
iSynchronizer.Close(); |
|
244 |
User::Free(iSessionPath); |
|
245 |
} |
|
246 |
||
247 |
||
248 |
||
249 |
||
250 |
GLDEF_C void DoFManBaseOperationL(TAny* aPtr) |
|
251 |
// |
|
252 |
// File manager asynchronous thread |
|
253 |
// |
|
254 |
{ |
|
255 |
||
256 |
CFileBase& fMan=*(CFileBase*)aPtr; |
|
257 |
User::LeaveIfError(fMan.iFs.Connect()); |
|
258 |
User::LeaveIfError(fMan.iFs.SetSessionPath(*fMan.iSessionPath)); |
|
259 |
fMan.iNumberOfFilesProcessed = 0; |
|
260 |
fMan.RunL(); |
|
261 |
} |
|
262 |
||
263 |
GLDEF_C TInt FManBaseThreadFunction(TAny* aPtr) |
|
264 |
// |
|
265 |
// Initialise New thread |
|
266 |
// |
|
267 |
{ |
|
268
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
268 |
TInt r = KErrNoMemory; // return value if a trap harness cannot be created |
0 | 269 |
CTrapCleanup* cleanup=CTrapCleanup::New(); |
270 |
CFileBase& fMan=*(CFileBase*)aPtr; |
|
268
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
271 |
|
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
272 |
if (cleanup != NULL) |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
273 |
{ |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
274 |
fMan.iSynchronizer.Wait(); |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
275 |
TRAP(r,DoFManBaseOperationL(aPtr)); |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
276 |
if (r == KErrNone) |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
277 |
r = fMan.iLastError; |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
278 |
delete cleanup; |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
279 |
} |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
280 |
|
0 | 281 |
fMan.iSwitches=0; |
282 |
fMan.iFs=fMan.iFsOld; |
|
283 |
fMan.iStatus=NULL; |
|
284 |
fMan.iFManThread.Close(); |
|
268
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
285 |
return (r); |
0 | 286 |
} |
287 |
||
288 |
||
289 |
||
290 |
||
291 |
EXPORT_C void CFileBase::RunInSeparateThreadL(TThreadFunction aThreadFunction) |
|
292 |
/** |
|
293 |
Creates a separate thread to run the command. |
|
294 |
||
295 |
@param aThreadFunction The thread function. |
|
296 |
*/ |
|
297 |
{ |
|
298 |
TFileName sessionPath; |
|
299 |
User::LeaveIfError(iFs.SessionPath(sessionPath)); |
|
300 |
if (iSessionPath==NULL) |
|
301 |
iSessionPath=HBufC::NewL((sessionPath.Length())); |
|
302 |
else if (iSessionPath->Des().MaxLength()<sessionPath.Length()) |
|
303 |
iSessionPath=iSessionPath->ReAllocL(IncPathLength(sessionPath.Length())); |
|
304 |
iSessionPath->Des()=sessionPath; |
|
268
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
305 |
|
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
306 |
User::LeaveIfError(iFManThread.Create(KNullDesC,aThreadFunction,KDefaultStackSize,NULL,this)); |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
307 |
|
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
308 |
// The code won't leave anymore after this. |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
309 |
// The effect of any further state changes to this instance |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
310 |
// should be undone / completed by the thread function. |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
311 |
iFManThread.SetPriority(EPriorityMuchLess); |
345b1ca54e88
Revision: 201036
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
257
diff
changeset
|
312 |
iSwitches|=KFManBusyFlag; |
0 | 313 |
iFsOld=iFs; |
314 |
iLastError=KErrNone; |
|
315 |
iFManThread.Logon(*iStatus); |
|
316 |
iFManThread.Resume(); |
|
317 |
} |
|
318 |
||
319 |
||
320 |
||
321 |
||
322 |
EXPORT_C void CFileBase::RunL() |
|
323 |
/** |
|
324 |
Executes a command. |
|
325 |
||
326 |
@capability Dependent the capabilities required by this method, of the abstract class CFileBase, |
|
327 |
will be dependent on and provided by the concrete-class implementation of |
|
328 |
the DoOperationL method |
|
329 |
||
330 |
*/ |
|
331 |
{ |
|
332 |
if (iStatus && (iSwitches&KFManBusyFlag)==EFalse) |
|
333 |
{ |
|
334 |
RunInSeparateThreadL(FManBaseThreadFunction); |
|
335 |
return; |
|
336 |
} |
|
337 |
||
338 |
TBool copyFromHandle = (iSwitches & KCopyFromHandle)?(TBool)ETrue:(TBool)EFalse; |
|
339 |
||
340 |
CDirScan::TScanDirection scanDir=(iSwitches&KScanDownFlag) ? CDirScan::EScanDownTree : CDirScan::EScanUpTree; |
|
341 |
||
342 |
if (!copyFromHandle) |
|
343 |
{ |
|
344 |
TRAP(iLastError,iScanner->SetScanDataL(iSrcFile.FullName(),iMatchEntry,ESortByName|EAscending,scanDir)); |
|
345 |
if (iLastError==KErrNone) |
|
346 |
TRAP(iLastError,iScanner->NextL(iDirList)); |
|
347 |
||
348 |
if (iLastError!=KErrNone) |
|
349 |
{ |
|
350 |
iErrorInfo=EInitializationFailed; |
|
351 |
User::Leave(iLastError); |
|
352 |
} |
|
353 |
} |
|
354 |
||
355 |
FOREVER |
|
356 |
{ |
|
357 |
if (copyFromHandle || iDirList->Count()) |
|
358 |
{ |
|
359 |
iLastError=KErrNone; |
|
360 |
iErrorInfo=ENoExtraInformation; |
|
361 |
TInt action=(iObserver) ? iObserver->NotifyFileManStarted() : MFileManObserver::EContinue; |
|
362 |
// Check if NotifyFileManStarted returned ECancel. |
|
363 |
if ( action == MFileManObserver::ECancel) |
|
364 |
iLastError=KErrCancel; |
|
365 |
if (action==MFileManObserver::EContinue) |
|
366 |
{ |
|
367 |
iNumberOfFilesProcessed++; |
|
368 |
TRAP(iLastError,DoOperationL()); |
|
369 |
action=(iObserver) ? iObserver->NotifyFileManEnded() : MFileManObserver::EContinue; |
|
370 |
} |
|
371 |
else if(action==MFileManObserver::ERetry) |
|
372 |
{ |
|
373 |
Panic(EFManBadValueFromObserver); |
|
374 |
} |
|
375 |
||
376 |
||
377 |
switch(action) |
|
378 |
{ |
|
379 |
case MFileManObserver::EContinue: |
|
380 |
case MFileManObserver::ECancel: |
|
381 |
break; |
|
382 |
case MFileManObserver::ERetry: |
|
383 |
continue; |
|
384 |
case MFileManObserver::EAbort: |
|
385 |
delete iDirList; |
|
386 |
iDirList=NULL; |
|
387 |
iCurrentEntry = 0; |
|
388 |
User::Leave(KErrCancel); |
|
389 |
default: |
|
390 |
Panic(EFManBadValueFromObserver); |
|
391 |
} |
|
392 |
} |
|
393 |
iCurrentEntry++; |
|
394 |
if (copyFromHandle || iCurrentEntry>=iDirList->Count()) |
|
395 |
{ |
|
396 |
delete iDirList; |
|
397 |
iDirList=NULL; |
|
398 |
iCurrentEntry=0; |
|
399 |
||
400 |
if (iSwitches&KRecurseFlag) |
|
401 |
{ |
|
402 |
TRAPD(ret,iScanner->NextL(iDirList)); |
|
403 |
if (ret!=KErrNone && ret!=KErrPathNotFound) |
|
404 |
{ |
|
405 |
iErrorInfo=EScanNextDirectoryFailed; |
|
406 |
iLastError = ret; |
|
407 |
User::Leave(iLastError); |
|
408 |
} |
|
409 |
} |
|
410 |
if (iDirList==NULL) |
|
411 |
{ |
|
412 |
CompleteOperationL(); |
|
413 |
return; |
|
414 |
} |
|
415 |
} |
|
416 |
} |
|
417 |
} |
|
418 |
||
419 |
||
420 |
||
421 |
||
422 |
EXPORT_C void CFileBase::SetObserver(MFileManObserver* anObserver) |
|
423 |
/** |
|
424 |
Sets the observer. |
|
425 |
||
426 |
Use this function to provide CFileMan with an MFileManObserver, or, if one |
|
427 |
already exists, to change the observer. |
|
428 |
||
429 |
@param anObserver File management observer. |
|
430 |
||
431 |
@see CFileMan |
|
432 |
@see MFileManObserver |
|
433 |
*/ |
|
434 |
{ |
|
435 |
||
436 |
iObserver=anObserver; |
|
437 |
} |
|
438 |
||
439 |
||
440 |
||
441 |
||
442 |
EXPORT_C const TEntry& CFileBase::CurrentEntry() |
|
443 |
/** |
|
444 |
Gets the entry currently being processed. |
|
445 |
||
446 |
@return Contains the current entry. |
|
447 |
*/ |
|
448 |
{ |
|
449 |
||
450 |
__ASSERT_ALWAYS(iDirList && iCurrentEntry>=0 && iCurrentEntry<iDirList->Count(),Panic(EFManCurrentEntryInvalid)); |
|
451 |
return (*iDirList)[iCurrentEntry]; |
|
452 |
} |
|
453 |
||
454 |
||
455 |
||
456 |
||
457 |
EXPORT_C TPtrC CFileBase::AbbreviatedPath() |
|
458 |
/** |
|
459 |
Gets the abbreviated path of the file or directory currently being processed. |
|
460 |
||
461 |
The abbreviated path is its path relative to the top level directory |
|
462 |
specified in the operation. |
|
463 |
||
464 |
@return The abbreviated path. |
|
465 |
*/ |
|
466 |
{ |
|
467 |
||
468 |
return iScanner->AbbreviatedPath(); |
|
469 |
} |
|
470 |
||
471 |
||
472 |
||
473 |
||
474 |
EXPORT_C TPtrC CFileBase::FullPath() |
|
475 |
/** |
|
476 |
Gets the full path of the file or directory currently being processed. |
|
477 |
||
478 |
The full path includes the drive letter, path and filename. |
|
479 |
||
480 |
@return The full path. |
|
481 |
*/ |
|
482 |
{ |
|
483 |
||
484 |
return iScanner->FullPath(); |
|
485 |
} |
|
486 |
||
487 |
||
488 |
||
489 |
||
490 |
EXPORT_C TInt CFileBase::GetLastError() |
|
491 |
/** |
|
492 |
Gets the latest error code returned during a CFileMan |
|
493 |
operation. |
|
494 |
||
495 |
This function may be called from MFileManObserver::NotifyFileManEnded(). |
|
496 |
||
497 |
@return KErrNone, or another error code that might have been |
|
498 |
returned by a CFileMan operation. |
|
499 |
*/ |
|
500 |
{ |
|
501 |
||
502 |
return(iLastError); |
|
503 |
} |
|
504 |
||
505 |
||
506 |
||
507 |
||
508 |
EXPORT_C TFileManError CFileBase::GetMoreInfoAboutError() |
|
509 |
/** |
|
510 |
Gets additional information about the latest error returned during |
|
511 |
a CFileMan operation. |
|
512 |
||
513 |
For example, if a rename fails, this function |
|
514 |
can be used to report whether the source or target name caused the problem. |
|
515 |
This information supplements that provided GetLastError(). |
|
516 |
||
517 |
@return The extra information about the last CFileMan error. |
|
518 |
||
519 |
@see CFileMan |
|
520 |
@see CFileBase::GetLastError() |
|
521 |
*/ |
|
522 |
{ |
|
523 |
||
524 |
return(iErrorInfo); |
|
525 |
} |
|
526 |
||
527 |
||
528 |
||
529 |
||
530 |
EXPORT_C CFileMan* CFileMan::NewL(RFs& aFs) |
|
531 |
/** |
|
532 |
Constructs and allocates memory for a new CFileMan object. |
|
533 |
||
534 |
@param aFs File server session. |
|
535 |
||
536 |
@return Newly created CFileMan object. |
|
537 |
*/ |
|
538 |
{ |
|
257 | 539 |
TRACE1(UTF::EBorder, UTraceModuleEfsrv::ECFileManNewL1, MODULEUID, aFs.Handle()); |
0 | 540 |
|
541 |
CFileMan* fileMan=new(ELeave) CFileMan(aFs); |
|
542 |
CleanupStack::PushL(fileMan); |
|
543 |
fileMan->CFileBase::ConstructL(); |
|
544 |
CleanupStack::Pop(); |
|
545 |
||
257 | 546 |
TRACE1(UTF::EBorder, UTraceModuleEfsrv::ECFileManNewL1Return, MODULEUID, fileMan); |
0 | 547 |
return fileMan; |
548 |
} |
|
549 |
||
550 |
||
551 |
||
552 |
||
553 |
EXPORT_C CFileMan* CFileMan::NewL(RFs& aFs,MFileManObserver* anObserver) |
|
554 |
/** |
|
555 |
Constructs and allocates memory for a new CFileMan object with an observer. |
|
556 |
||
557 |
@param aFs File server session. |
|
558 |
@param anObserver File management observer. |
|
559 |
||
560 |
@return Newly created CFileMan object. |
|
561 |
*/ |
|
562 |
{ |
|
257 | 563 |
TRACE2(UTF::EBorder, UTraceModuleEfsrv::ECFileManNewL2, MODULEUID, aFs.Handle(), anObserver); |
0 | 564 |
|
565 |
CFileMan* fileMan=new(ELeave) CFileMan(aFs); |
|
566 |
CleanupStack::PushL(fileMan); |
|
567 |
fileMan->CFileBase::ConstructL(); |
|
568 |
CleanupStack::Pop(); |
|
569 |
fileMan->SetObserver(anObserver); |
|
570 |
||
257 | 571 |
TRACE1(UTF::EBorder, UTraceModuleEfsrv::ECFileManNewL2Return, MODULEUID, fileMan); |
0 | 572 |
return fileMan; |
573 |
} |
|
574 |
||
575 |
||
576 |
||
577 |
||
578 |
CFileMan::CFileMan(RFs& aFs) |
|
579 |
// |
|
580 |
// Constructor and destructor |
|
581 |
// |
|
582 |
: CFileBase(aFs) |
|
583 |
{ |
|
584 |
} |
|
585 |
CFileMan::~CFileMan() |
|
586 |
{ |
|
257 | 587 |
TRACE1(UTF::EBorder, UTraceModuleEfsrv::ECFileManDestructor, MODULEUID, this); |
588 |
||
589 |
TRACE0(UTF::EBorder, UTraceModuleEfsrv::ECFileManDestructorReturn, MODULEUID); |
|
0 | 590 |
} |
591 |
||
592 |
||
593 |
EXPORT_C CFileMan::TAction CFileMan::CurrentAction() |
|
594 |
/** |
|
595 |
Gets the action which CFileMan is currently carrying out. |
|
596 |
||
597 |
@return The action which CFileMan is carrying out. |
|
598 |
*/ |
|
599 |
{ |
|
257 | 600 |
TRACE1(UTF::EBorder, UTraceModuleEfsrv::ECFileManCurrentAction, MODULEUID, this); |
0 | 601 |
|
602 |
TAction action = ENone; |
|
603 |
||
604 |
// Mapping table between internal and external action indicators. |
|
605 |
switch(iAction) |
|
606 |
{ |
|
607 |
case EInternalNone: |
|
608 |
action = ENone; |
|
609 |
break; |
|
610 |
case EInternalAttribs: |
|
611 |
action = EAttribs; |
|
612 |
break; |
|
613 |
case EInternalCopy: |
|
614 |
action = ECopy; |
|
615 |
break; |
|
616 |
case EInternalCopyForMove: |
|
617 |
action = EMove; |
|
618 |
break; |
|
619 |
case EInternalDelete: |
|
620 |
action = EDelete; |
|
621 |
break; |
|
622 |
case EInternalRenameInvalidEntry: |
|
623 |
action = ERenameInvalidEntry; |
|
624 |
break; |
|
625 |
case EInternalRenameForMove: |
|
626 |
case EInternalRename: |
|
627 |
action = ERename; |
|
628 |
break; |
|
629 |
case EInternalRmDir: |
|
630 |
action = ERmDir; |
|
631 |
break; |
|
632 |
case EInternalCopyFromHandle: |
|
633 |
action = ECopyFromHandle; |
|
634 |
break; |
|
635 |
default: |
|
636 |
Panic(EFManUnknownAction); |
|
637 |
} |
|
638 |
||
257 | 639 |
TRACE1(UTF::EBorder, UTraceModuleEfsrv::ECFileManCurrentActionReturn, MODULEUID, action); |
0 | 640 |
return (action); |
641 |
} |
|
642 |
||
643 |
||
644 |
||
645 |
||
646 |
EXPORT_C void CFileMan::GetCurrentTarget(TFileName& aTrgName) |
|
647 |
/** |
|
648 |
Gets the name of the target file for the CFileMan operation currently |
|
649 |
being carried out. |
|
650 |
||
651 |
This function is relevant when copying, moving or renaming files. |
|
652 |
||
653 |
@param aTrgName The full path and filename of the target file for |
|
654 |
the current CFileMan operation |
|
655 |
*/ |
|
656 |
{ |
|
257 | 657 |
TRACE1(UTF::EBorder, UTraceModuleEfsrv::ECFileManGetCurrentTarget, MODULEUID, this); |
0 | 658 |
|
659 |
GetSrcAndTrg(iTmpParse, aTrgName); |
|
660 |
||
257 | 661 |
TRACEMULT1(UTF::EBorder, UTraceModuleEfsrv::ECFileManGetCurrentTargetReturn, MODULEUID, aTrgName); |
0 | 662 |
} |
663 |
||
664 |
||
665 |
||
666 |
||
667 |
EXPORT_C void CFileMan::GetCurrentSource(TFileName& aSrcName) |
|
668 |
/** |
|
669 |
Gets the name of the source file or directory for the CFileMan operation |
|
670 |
currently being carried out. |
|
671 |
||
672 |
The source is the file or directory which is being copied, moved or deleted. |
|
673 |
||
674 |
@param aSrcName The full path and filename of the source file for the current |
|
675 |
CFileMan operation. |
|
676 |
*/ |
|
677 |
{ |
|
257 | 678 |
TRACE1(UTF::EBorder, UTraceModuleEfsrv::ECFileManGetCurrentSource, MODULEUID, this); |
0 | 679 |
|
680 |
TPtrC fullPath(FullPath()); |
|
681 |
iTmpParse.Set(CurrentEntry().iName, &fullPath, NULL); |
|
682 |
aSrcName = iTmpParse.FullName(); |
|
683 |
||
257 | 684 |
TRACEMULT1(UTF::EBorder, UTraceModuleEfsrv::ECFileManGetCurrentSourceReturn, MODULEUID, aSrcName); |
0 | 685 |
} |
686 |
||
687 |
void CFileMan::GetSrcAndTrg(TParse& aSrcName,TFileName& aTrgName) |
|
688 |
// |
|
689 |
// Get the current target for the operation |
|
690 |
// |
|
691 |
{ |
|
692 |
TFileName fullpath = FullPath(); |
|
693 |
TInt ret = aSrcName.Set(CurrentEntry().iName, &fullpath, NULL); |
|
694 |
if(ret == KErrBadName) |
|
695 |
{ |
|
696 |
// Try heap variables first |
|
697 |
TBool done = EFalse; |
|
698 |
TFileName* current = new TFileName; |
|
699 |
if (current != NULL) |
|
700 |
{ |
|
701 |
current->Copy(CurrentEntry().iName); |
|
702 |
||
703 |
ret = ShrinkNames(iFs, fullpath, *current, EFalse); |
|
704 |
if(ret == KErrNone) |
|
705 |
{ |
|
706 |
ret = aSrcName.Set(*current, &fullpath, NULL); |
|
707 |
done = ETrue; |
|
708 |
} |
|
709 |
delete current; |
|
710 |
} |
|
711 |
||
712 |
if (!done) //heap method failed |
|
713 |
{ |
|
714 |
TFileName current = CurrentEntry().iName; |
|
715 |
ret = ShrinkNames(iFs, fullpath, current, EFalse); |
|
716 |
if(ret == KErrNone) |
|
717 |
{ |
|
718 |
ret = aSrcName.Set(current, &fullpath, NULL); |
|
719 |
} |
|
720 |
} |
|
721 |
} |
|
722 |
__ASSERT_DEBUG(ret == KErrNone, Panic(EBadLength)); |
|
723 |
aTrgName=iTrgFile.DriveAndPath(); |
|
724 |
TPtrC relPath=iScanner->AbbreviatedPath(); |
|
725 |
aTrgName.Append(relPath.Right(relPath.Length()-1)); |
|
726 |
CreateTargetNameFromSource(aTrgName,iTrgFile.NameAndExt(),aSrcName.NameAndExt()); |
|
727 |
} |
|
728 |
||
729 |
||
730 |
||
731 |
||
732 |
EXPORT_C TInt CFileMan::BytesTransferredByCopyStep() |
|
733 |
/** |
|
734 |
Gets the number of bytes transferred during a copy or move operation. |
|
735 |
||
736 |
Large files are copied and moved in stages. After each portion of |
|
737 |
the source file has been copied to the target, the number of bytes |
|
738 |
transferred is updated. This function may be called |
|
739 |
from MFileManObserver::NotifyFileManOperation() |
|
740 |
and may be used to support the increment of progress bars. |
|
741 |
||
742 |
@return The number of bytes transferred. |
|
743 |
*/ |
|
744 |
{ |
|
257 | 745 |
TRACE2(UTF::EBorder, UTraceModuleEfsrv::ECFileManBytesTransferredByCopyStep, MODULEUID, this, iBytesTransferred); |
0 | 746 |
|
747 |
return(iBytesTransferred); |
|
748 |
} |
|
749 |
||
750 |
||
751 |
||
752 |
||
753 |
LOCAL_C void MakeParseWild(TParse& aParse, TFileName& aName) |
|
754 |
// |
|
755 |
// Append _L("\\*") or _L("*") to aParse |
|
756 |
// |
|
757 |
{ |
|
758 |
if(!aParse.IsWild()) |
|
759 |
{ |
|
760 |
aName = aParse.FullName(); |
|
761 |
if (aParse.NamePresent() || aParse.ExtPresent()) |
|
762 |
{ |
|
763 |
if (aName.Length()<=254) |
|
764 |
aName.Append(_L("\\*")); |
|
765 |
} |
|
766 |
else |
|
767 |
{ |
|
768 |
if (aName.Length()<=255) |
|
769 |
aName.Append(_L("*")); |
|
770 |
} |
|
771 |
aParse.Set(aName,NULL,NULL); |
|
772 |
} |
|
773 |
} |
|
774 |
||
775 |
||
776 |
void CFileMan::CheckForDirectory() |
|
777 |
// |
|
778 |
// If iTrgFile is a directory set target to iTrgFile\\* |
|
779 |
// |
|
780 |
{ |
|
781 |
TInt trg = iFs.Entry(iTrgFile.FullName(), iTmpEntry); |
|
782 |
if (trg==KErrNone && iTmpEntry.iAtt&KEntryAttDir) |
|
783 |
MakeParseWild(iTrgFile, iTmpName1); |
|
784 |
TInt src = iFs.Entry(iSrcFile.FullName(), iTmpEntry); |
|
785 |
if (src==KErrNone && iTmpEntry.iAtt&KEntryAttDir) |
|
786 |
{ |
|
787 |
MakeParseWild(iSrcFile, iTmpName1); |
|
788 |
if (trg==KErrNotFound && (iSwitches&KRecurseFlag)) |
|
789 |
MakeParseWild(iTrgFile, iTmpName1); |
|
790 |
} |
|
791 |
} |
|
792 |
||
793 |
void CFileMan::DoSynchronize(TInt aRetValue) |
|
794 |
// |
|
795 |
// Synchronise with fmanthread |
|
796 |
// |
|
797 |
{ |
|
798 |
||
799 |
if (iStatus && aRetValue==KErrNone) |
|
800 |
iSynchronizer.Signal(); // FManThread started |
|
801 |
if (iStatus && aRetValue!=KErrNone) |
|
802 |
iStatus=NULL; // FManThread failed to start |
|
803 |
} |
|
804 |
||
805 |
LOCAL_C void NextInPath(const TDesC& aPath,TPtrC& anEntry,TInt& aPos) |
|
806 |
// |
|
807 |
// Returns the next entry in the path |
|
808 |
// |
|
809 |
{ |
|
810 |
||
811 |
anEntry.Set(NULL,0); |
|
812 |
if ((aPos+1)>=aPath.Length()) |
|
813 |
return; |
|
814 |
TPtrC path(aPath.Mid(aPos+1)); // Skip delimiter |
|
815 |
TInt delimiterPos=path.Locate(KPathDelimiter); |
|
816 |
if (delimiterPos==KErrNotFound) |
|
817 |
delimiterPos=aPath.Length()-(aPos+1); |
|
818 |
if (delimiterPos<=0) |
|
819 |
return; |
|
820 |
||
821 |
if (path[delimiterPos-1]==KExtDelimiter) // return "F32." as "F32" |
|
822 |
anEntry.Set(aPath.Mid(aPos+1,delimiterPos-1)); |
|
823 |
else |
|
824 |
anEntry.Set(aPath.Mid(aPos+1,delimiterPos)); |
|
825 |
aPos+=delimiterPos+1; |
|
826 |
} |
|
827 |
||
828 |
LOCAL_C TBool ComparePaths(const TDesC& aPath1,const TDesC& aPath2) |
|
829 |
// |
|
830 |
// Return ETrue if the paths are identical |
|
831 |
// To catch case "\\F32.\\GROUP\\" == "\\F32\\GROUP\\" |
|
832 |
// |
|
833 |
{ |
|
834 |
||
835 |
TPtrC entry1(NULL,0); |
|
836 |
TPtrC entry2(NULL,0); |
|
837 |
TInt pos1=0; |
|
838 |
TInt pos2=0; |
|
839 |
||
840 |
do { |
|
841 |
NextInPath(aPath1,entry1,pos1); |
|
842 |
NextInPath(aPath2,entry2,pos2); |
|
843 |
if (entry1.MatchF(entry2)==KErrNotFound) |
|
844 |
return(EFalse); |
|
845 |
} while (entry1.Length() && entry2.Length()); |
|
846 |
||
847 |
return(ETrue); |
|
848 |
} |
|
849 |
||
850 |
EXPORT_C TBool FileNamesIdentical(const TDesC& aFileName1,const TDesC& aFileName2) |
|
851 |
// |
|
852 |
// Return ETrue if the filenames (and paths) are identical |
|
853 |
// NB "Agenda" == "AGENda." |
|
854 |
// |
|
855 |
{ |
|
856 |
||
857 |
TParsePtrC file1(aFileName1); |
|
858 |
TParsePtrC file2(aFileName2); |
|
859 |
if (file1.Drive().MatchF(file2.Drive())==KErrNotFound) |
|
860 |
return(EFalse); |
|
861 |
if (file1.Name().MatchF(file2.Name())==KErrNotFound) |
|
862 |
return(EFalse); |
|
863 |
if (ComparePaths(file1.Path(),file2.Path())==EFalse) |
|
864 |
return(EFalse); |
|
865 |
if (file1.Ext().Length()==0 || file2.Ext().Length()==0) |
|
866 |
{ // Agenda == Agenda. |
|
867 |
if (file1.Ext().Length()==1 || file2.Ext().Length()==1) |
|
868 |
return(ETrue); |
|
869 |
} |
|
870 |
if (file1.Ext().MatchF(file2.Ext())==KErrNotFound && |
|
871 |
file1.NameAndExt().MatchF(file2.NameAndExt())==KErrNotFound) |
|
872 |
return(EFalse); |
|
873 |
return(ETrue); |
|
874 |
} |
|
875 |
||
876 |
||
877 |
||
878 |
||
879 |
EXPORT_C TInt CFileMan::Attribs(const TDesC& aName,TUint aSetMask,TUint aClearMask,const TTime& aTime,TUint aSwitches,TRequestStatus& aStatus) |
|
880 |
/** |
|
881 |
Sets or clears attributes for one or more files using two bitmasks. |
|
882 |
||
883 |
This is an asynchronous function. |
|
884 |
Its behaviour is the same as the synchronous overload. |
|
885 |
||
886 |
@param aName Path indicating the file(s) whose attributes are to be |
|
887 |
changed. Any path components which are not specified |
|
888 |
here will be taken from the session path. |
|
889 |
Use wildcards to specify more than one file. |
|
890 |
@param aSetMask Bitmask indicating the attributes to be set. |
|
891 |
@param aClearMask Bitmask indicating the attributes to be cleared. |
|
892 |
For more information, see KEntryAttNormal and the other |
|
893 |
file/directory attributes. |
|
894 |
@param aTime Contains the new modification date and time for the files, in UTC. |
|
895 |
To preserve the file's timestamps, specify a TTime value of 0. |
|
896 |
@param aSwitches Specify zero for no recursion; |
|
897 |
CFileMan::ERecurse for recursion. |
|
898 |
By default, the synchronous variant of this function operates |
|
899 |
non-recursively. |
|
900 |
@param aStatus The request status object. On request completion, |
|
901 |
indicates how the request completed: |
|
902 |
KErrNone, if successful, otherwise one of the other system-wide error |
|
903 |
codes. |
|
904 |
||
905 |
@return KErrNone if the asynchronous request is made successfully; KErrInUse if an asynchronous request |
|
906 |
is still pending; otherwise one of the other system-wide error codes |
|
907 |
||
908 |
@capability Dependent If aName is /Sys then Tcb capability is required. |
|
909 |
@capability Dependent If aName begins with /Private and does not match |
|
910 |
this process' SID then AllFiles capability is required. |
|
911 |
@capability Dependent If aName is /Resource then Tcb capability is required. |
|
912 |
||
913 |
*/ |
|
914 |
{ |
|
257 | 915 |
TRACEMULT8(UTF::EBorder, UTraceModuleEfsrv::ECFileManAttribs1, MODULEUID, |
916 |
(TUint) this, aName, aSetMask, aClearMask, I64LOW(aTime.Int64()), I64HIGH(aTime.Int64()), aSwitches, (TUint) &aStatus); |
|
0 | 917 |
|
918 |
TInt r; |
|
919 |
if (iSwitches&KFManBusyFlag) |
|
920 |
{ |
|
921 |
r = KErrInUse; |
|
922 |
} |
|
923 |
else |
|
924 |
{ |
|
925 |
iStatus=&aStatus; |
|
926 |
r = Attribs(aName,aSetMask,aClearMask,aTime,aSwitches); |
|
927 |
} |
|
928 |
||
257 | 929 |
TRACERET1(UTF::EBorder, UTraceModuleEfsrv::ECFileManAttribs1Return, MODULEUID, r); |
0 | 930 |
return r; |
931 |
} |
|
932 |
||
933 |
||
934 |
||
935 |
||
936 |
EXPORT_C TInt CFileMan::Attribs(const TDesC& aName,TUint aSetMask,TUint aClearMask,const TTime& aTime,TUint aSwitches) |
|
937 |
/** |
|
938 |
Sets or clears attributes for one or more files using two bitmasks |
|
939 |
||
940 |
This is a synchronous function. |
|
941 |
||
942 |
The first bitmask specifies the attributes to be set. |
|
943 |
The second specifies the attributes to be cleared. |
|
944 |
The date and time of the files' last modification can also be changed. |
|
945 |
||
946 |
The function can operate recursively or non-recursively. |
|
947 |
When operating non-recursively, only the matching files located in the directory |
|
948 |
specified in aName are affected. When operating recursively, all matching files |
|
949 |
in the directory hierarchy below the directory specified in aName will be affected. |
|
950 |
||
951 |
Notes: |
|
952 |
||
953 |
1. A panic is raised if any attribute is specified in both bitmasks. |
|
954 |
||
955 |
2. Attempting to change the attributes for an open file results in an error |
|
956 |
for that file, as retrieved by CFileBase::GetLastError(). |
|
957 |
||
958 |
3. An attempt to set or clear the KEntryAttDir or KEntryAttVolume attribute |
|
959 |
for a file or directory will have no effect. |
|
960 |
||
961 |
@param aName Path indicating the file(s) whose attributes are to be |
|
962 |
changed. Any path components which are not specified |
|
963 |
here will be taken from the session path. |
|
964 |
Use wildcards to specify more than one file. |
|
965 |
@param aSetMask Bitmask indicating the attributes to be set. |
|
966 |
@param aClearMask Bitmask indicating the attributes to be cleared. |
|
967 |
For more information, see KEntryAttNormal and the other |
|
968 |
file/directory attributes. |
|
969 |
@param aTime Contains the new modification date and time for the files, in UTC. |
|
970 |
To preserve the file's timestamps, specify a TTime value of 0. |
|
971 |
@param aSwitches Specify zero for no recursion; |
|
972 |
CFileMan::ERecurse for recursion. |
|
973 |
By default, the synchronous variant of this function operates |
|
974 |
non-recursively. |
|
975 |
||
976 |
@return KErrNone if successful, otherwise one of the other system-wide error codes. |
|
977 |
||
978 |
@capability Dependent If aName is /Sys then Tcb capability is required. |
|
979 |
@capability Dependent If aName begins with /Private and does not match |
|
980 |
this process' SID then AllFiles capability is required. |
|
981 |
@capability Dependent If aName is /Resource then Tcb capability is required. |
|
982 |
||
983 |
*/ |
|
984 |
{ |
|
257 | 985 |
TRACEMULT7(UTF::EBorder, UTraceModuleEfsrv::ECFileManAttribs2, MODULEUID, |
986 |
(TUint) this, aName, aSetMask, aClearMask, I64LOW(aTime.Int64()), I64HIGH(aTime.Int64()), aSwitches); |
|
0 | 987 |
|
988 |
TInt ret; |
|
989 |
if (iSwitches&KFManBusyFlag) |
|
990 |
{ |
|
991 |
ret = KErrInUse; |
|
992 |
} |
|
993 |
else |
|
994 |
{ |
|
995 |
SetFlags(aSwitches&EOverWrite,aSwitches&ERecurse,ETrue,EFalse); |
|
257 | 996 |
RETURNIFERRORD(r,iFs.Parse(aName,iSrcFile),UTraceModuleEfsrv::ECFileManAttribs2Return); |
0 | 997 |
iSetMask=aSetMask; |
998 |
iClearMask=aClearMask; |
|
999 |
iTime=aTime; |
|
1000 |
iAction = EInternalAttribs; |
|
1001 |
iMatchEntry=KEntryAttMaskSupported; // all entries |
|
1002 |
iNumberOfFilesProcessed = 0; |
|
1003 |
TRAP(r,RunL()); |
|
1004 |
ret=(r==KErrNone) ? iLastError : r; |
|
1005 |
DoSynchronize(r); |
|
1006 |
} |
|
1007 |
||
257 | 1008 |
TRACERET1(UTF::EBorder, UTraceModuleEfsrv::ECFileManAttribs2Return, MODULEUID, ret); |
0 | 1009 |
return(ret); |
1010 |
} |
|
1011 |
||
1012 |
||
1013 |
||
1014 |
||
1015 |
EXPORT_C TInt CFileMan::Copy(const TDesC& anOld,const TDesC& aNew,TUint aSwitches,TRequestStatus& aStatus) |
|
1016 |
/** |
|
1017 |
Copies one or more files. |
|
1018 |
||
1019 |
This is an asynchronous function. |
|
1020 |
Its behaviour is the same as the synchronous overload. |
|
1021 |
||
1022 |
@param anOld Path indicating the file(s) to be copied. |
|
1023 |
Any path components which are not specified here will be |
|
1024 |
taken from the session path. |
|
1025 |
@param aNew Path indicating the directory into which the file(s) are to be copied. |
|
1026 |
Any path components which are not specified here will be |
|
1027 |
taken from the session path |
|
1028 |
@param aSwitches Specify zero for no overwriting and no recursion; |
|
1029 |
CFileMan::EOverWrite to overwrite files with the same name; |
|
1030 |
CFileMan::ERecurse for recursion. |
|
1031 |
By default, the synchronous variant of this function operates |
|
1032 |
non-recursively and with overwriting. |
|
1033 |
@param aStatus The request status object. On request completion, |
|
1034 |
indicates how the request completed: |
|
1035 |
KErrNone, if successful, otherwise one of the other system-wide error |
|
1036 |
codes. |
|
1037 |
||
1038 |
@return KErrNone if the asynchronous request is made successfully; KErrInUse if an asynchronous request |
|
1039 |
is still pending; otherwise one of the other system-wide error codes |
|
1040 |
||
1041 |
@capability AllFiles |
|
1042 |
||
1043 |
@capability Dependent If the path for aNew begins with /Sys then Tcb capability is required. |
|
1044 |
@capability Dependent If the path for aNew begins with /Resource then Tcb capability is required |
|
1045 |
||
1046 |
*/ |
|
1047 |
{ |
|
257 | 1048 |
TRACEMULT5(UTF::EBorder, UTraceModuleEfsrv::ECFileManCopy1, MODULEUID, |
1049 |
(TUint) this, anOld, aNew, aSwitches, (TUint) &aStatus); |
|
0 | 1050 |
|
1051 |
TInt r; |
|
1052 |
if (iSwitches&KFManBusyFlag) |
|
1053 |
r = KErrInUse; |
|
1054 |
else |
|
1055 |
{ |
|
1056 |
iStatus=&aStatus; |
|
1057 |
r = Copy(anOld,aNew,aSwitches); |
|
1058 |
} |
|
1059 |
||
257 | 1060 |
TRACERET1(UTF::EBorder, UTraceModuleEfsrv::ECFileManCopy1Return, MODULEUID, r); |
0 | 1061 |
return(r); |
1062 |
} |
|
1063 |
||
1064 |
||
1065 |
||
1066 |
||
1067 |
EXPORT_C TInt CFileMan::Copy(const TDesC& anOld,const TDesC& aNew,TUint aSwitches) |
|
1068 |
/** |
|
1069 |
Copies one or more files. |
|
1070 |
||
1071 |
This is a synchronous function. |
|
1072 |
||
1073 |
NB the following applies to files greater than or equal to 2GBytes in size |
|
1074 |
(2,147,483,648 bytes) : |
|
1075 |
- Only files smaller than 2GBytes will be copied; any larger files will be skipped and |
|
1076 |
processing will continue with the next file. |
|
1077 |
- If at least one file is smaller than 2GBytes, then KErrNone will be returned. |
|
1078 |
- If all files are greater than or equal to 2GBytes ,then KErrTooBig will be returned. |
|
1079 |
||
1080 |
One way to detect the presence of any large file(s) is to use an observer: calling |
|
1081 |
CFileBase::GetLastError() from MFileManObserver::NotifyFileManEnded() will return |
|
1082 |
KErrToBig for any file >= 2GBytes in size. |
|
1083 |
||
1084 |
Note: the copy operation behaves differently when MFileManObserver is used. |
|
1085 |
MFileManObserver should be used with multiple files as it enables you to capture the results of all file copy operations. |
|
1086 |
||
1087 |
If MFileManObserver is NOT used then only the result of the last |
|
1088 |
file copy operation is returned because the results of previous file copy operations are overwritten. |
|
1089 |
||
1090 |
Optionally, this function can be set to overwrite any files with the same name |
|
1091 |
which exist in the target directory. If the flag is set for no overwriting, |
|
1092 |
then any files with the same name will not be overwritten, and an error |
|
1093 |
(KErrAlreadyExists) will be returned for that file. Error codes may be retrieved |
|
1094 |
using CFileBase::GetLastError(). |
|
1095 |
||
1096 |
If recursive operation is set, all intermediate directories will be created, |
|
1097 |
including any directories in the path specified by aNew which do not |
|
1098 |
already exist. |
|
1099 |
||
257 | 1100 |
If the source (anOld) is a file and the recursive operation is set, |
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1101 |
then all the files with the same name as anOld in the source directory |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1102 |
including those in subdirectories will be copied to the destination. |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1103 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1104 |
For example, the initial directory structure is as follows: |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1105 |
C:\dir1\file.txt |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1106 |
C:\dir1\subdirA\file.txt |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1107 |
C:\dir1\subdirB\file.txt |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1108 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1109 |
@code |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1110 |
CFileMan* fm(CFileMan::NewL(iFs)); // Where iFs is an RFs handle |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1111 |
fm->Copy(_L("C:\\dir1\\file.txt"), _L("C:\\dir2\\file.txt"), CFileMan::ERecurse); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1112 |
// OR without specifying the filename in aNew: |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1113 |
fm->Copy(_L("C:\\dir1\\file.txt"), _L("C:\\dir2\\"), CFileMan::ERecurse); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1114 |
@endcode |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1115 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1116 |
Because of the recursive behaviour, the final directory structure after |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1117 |
either one of the copy operations above will be as follows: |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1118 |
C:\dir1\file.txt |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1119 |
C:\dir1\subdirA\file.txt |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1120 |
C:\dir1\subdirB\file.txt |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1121 |
C:\dir2\file.txt |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1122 |
C:\dir2\subdirA\file.txt |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1123 |
C:\dir2\subdirB\file.txt |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1124 |
|
0 | 1125 |
If recursive operation is not set, only the matching files located in |
1126 |
the single directory specified in anOld are copied. |
|
1127 |
No intermediate directories will be created; if any directories in |
|
1128 |
the destination path do not exist, no files will be copied, and this function |
|
1129 |
will return KErrPathNotFound. |
|
1130 |
||
1131 |
Notes: |
|
1132 |
1. This function operates on files only, therefore: |
|
1133 |
1.1 In contrast to the way CFileMan::Move() and CFileMan::Rename() |
|
1134 |
behave, the behaviour of the copy operation does not depend on the presence |
|
1135 |
or absence of a trailing backslash ("\") character. Therefore it is only |
|
1136 |
possible to copy the content of the source path. It is NOT |
|
1137 |
possible by use of a trailing backslash ("\") character to request that the |
|
1138 |
last directory level plus its content be copied to the target path. |
|
1139 |
||
1140 |
This means that the following two example copy operations will behave |
|
1141 |
identically |
|
1142 |
||
1143 |
@code |
|
1144 |
CFileMan* fm(CFileMan::NewL(iFs)); // Where iFs is an RFs handle |
|
1145 |
... |
|
1146 |
fm->Copy(_L("C:\\SRC\\"), _L("C:\\TRG\\"), CFileMan::ERecurse); |
|
1147 |
fm->Copy(_L("C:\\SRC"), _L("C:\\TRG\\"), CFileMan::ERecurse); |
|
1148 |
@endcode |
|
1149 |
||
1150 |
because they will be interpreted as follows: |
|
1151 |
@code |
|
1152 |
fm->Copy(_L("C:\\SRC\\*"),_L("C:\\TRG\\"), CFileMan::ERecurse); |
|
1153 |
@endcode |
|
1154 |
||
1155 |
1.2 If there is no file to operate on i.e. if source directory is empty, the |
|
1156 |
function will do nothing and return error code KErrNotFound. |
|
1157 |
||
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1158 |
2. Files can be copied across drives. |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1159 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1160 |
3. Open files can be copied if they have been opened using |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1161 |
the EFileShareReadersOnly file share mode. |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1162 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1163 |
4. Read-only, hidden and system files can be copied and |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1164 |
the source file's attributes are preserved in the target file. |
0 | 1165 |
|
1166 |
@param anOld Path indicating the file(s) to be copied. |
|
1167 |
Any path components which are not specified here will be |
|
1168 |
taken from the session path. |
|
1169 |
@param aNew Path indicating the directory into which the file(s) are to be copied. |
|
1170 |
Any path components which are not specified here will be |
|
1171 |
taken from the session path |
|
1172 |
@param aSwitches Specify zero for no overwriting and no recursion; |
|
1173 |
CFileMan::EOverWrite to overwrite files with the same name; |
|
1174 |
CFileMan::ERecurse for recursion. |
|
1175 |
By default, the synchronous variant of this function operates |
|
1176 |
non-recursively and with overwriting. |
|
1177 |
||
1178 |
@return KErrNone if successful, KErrNotFound if source directory is empty, otherwise one of the other system-wide error codes. |
|
1179 |
||
1180 |
@see CFileBase::GetLastError() |
|
1181 |
||
1182 |
@capability AllFiles |
|
1183 |
||
1184 |
@capability Dependent If the path for anOld begins with /Sys then Tcb capability is required. |
|
1185 |
@capability Dependent If the path for anOld begins with /Resource then Tcb capability is required |
|
1186 |
||
1187 |
*/ |
|
1188 |
{ |
|
257 | 1189 |
TRACEMULT4(UTF::EBorder, UTraceModuleEfsrv::ECFileManCopy2, MODULEUID, (TUint) this, anOld, aNew, aSwitches); |
0 | 1190 |
|
1191 |
if (iSwitches&KFManBusyFlag) |
|
1192 |
{ |
|
257 | 1193 |
TRACE1(UTF::EBorder, UTraceModuleEfsrv::ECFileManCopy2Return, MODULEUID, KErrInUse); |
0 | 1194 |
return(KErrInUse); |
1195 |
} |
|
1196 |
SetFlags(aSwitches&EOverWrite,aSwitches&ERecurse,ETrue,EFalse); |
|
257 | 1197 |
RETURNIFERRORD(r,iFs.Parse(anOld,iSrcFile),UTraceModuleEfsrv::ECFileManCopy2Return); |
1198 |
RETURNIFERROR(r,iFs.Parse(aNew,_L("*"),iTrgFile),UTraceModuleEfsrv::ECFileManCopy2Return); |
|
0 | 1199 |
CheckForDirectory(); |
1200 |
||
1201 |
if((iSwitches&KRecurseFlag) && iTrgFile.DriveAndPath().MatchF(iSrcFile.FullName()) != KErrNotFound) |
|
1202 |
{ |
|
257 | 1203 |
TRACE1(UTF::EBorder, UTraceModuleEfsrv::ECFileManCopy2Return, MODULEUID, KErrArgument); |
0 | 1204 |
return(KErrArgument); |
1205 |
} |
|
1206 |
||
1207 |
iAction = EInternalCopy; |
|
1208 |
iMatchEntry=KEntryAttMaskSupported; |
|
1209 |
iNumberOfFilesProcessed = 0; |
|
1210 |
TRAP(r,RunL()); |
|
1211 |
TInt ret=(r==KErrNone) ? iLastError : r; |
|
1212 |
DoSynchronize(r); |
|
1213 |
||
257 | 1214 |
TRACERET1(UTF::EBorder, UTraceModuleEfsrv::ECFileManCopy2Return, MODULEUID, ret); |
0 | 1215 |
return(ret); |
1216 |
} |
|
1217 |
||
1218 |
||
1219 |
||
1220 |
||
1221 |
EXPORT_C TInt CFileMan::Delete(const TDesC& aName,TUint aSwitches,TRequestStatus& aStatus) |
|
1222 |
/** |
|
1223 |
Deletes one or more files. |
|
1224 |
||
1225 |
This is an asynchronous function. |
|
1226 |
Its behaviour is the same as the synchronous overload. |
|
1227 |
||
1228 |
@param aName Path indicating the file(s) to be deleted. |
|
1229 |
May either be a full path, or relative to the session path. |
|
1230 |
Use wildcards to specify more than one file. |
|
1231 |
NOTE: if you pass KNullDesC, the empty (or null) descriptor, |
|
1232 |
then the function interprets this to mean \\*.* |
|
1233 |
@param aSwitches Specify: |
|
1234 |
zero for no recursion; |
|
1235 |
CFileMan::ERecurse for recursion. |
|
1236 |
By default, the synchronous variant of this function |
|
1237 |
operates non-recursively. |
|
1238 |
@param aStatus The request status object. On request completion, |
|
1239 |
indicates how the request completed: |
|
1240 |
KErrNone, if successful, otherwise one of the other system-wide error |
|
1241 |
codes. |
|
1242 |
||
1243 |
@return KErrNone if the asynchronous request is made successfully; KErrInUse if an asynchronous request |
|
1244 |
is still pending; otherwise one of the other system-wide error codes |
|
1245 |
||
1246 |
@capability Dependent If aName is /Sys then Tcb capability is required. |
|
1247 |
@capability Dependent If aName begins with /Private and does not match this process' SID |
|
1248 |
then AllFiles capability is required. |
|
1249 |
@capability Dependent If aName is /Resource then Tcb capability is required. |
|
1250 |
||
1251 |
@see KNullDesC |
|
1252 |
*/ |
|
1253 |
{ |
|
257 | 1254 |
TRACEMULT4(UTF::EBorder, UTraceModuleEfsrv::ECFileManDelete1, MODULEUID, (TUint) this, aName, aSwitches, (TUint) &aStatus); |
0 | 1255 |
|
1256 |
TInt r; |
|
1257 |
if (iSwitches&KFManBusyFlag) |
|
1258 |
{ |
|
1259 |
r = KErrInUse; |
|
1260 |
} |
|
1261 |
else |
|
1262 |
{ |
|
1263 |
iStatus=&aStatus; |
|
1264 |
r = Delete(aName,aSwitches); |
|
1265 |
} |
|
1266 |
||
257 | 1267 |
TRACERET1(UTF::EBorder, UTraceModuleEfsrv::ECFileManDelete1Return, MODULEUID, r); |
0 | 1268 |
return(r); |
1269 |
} |
|
1270 |
||
1271 |
||
1272 |
||
1273 |
||
1274 |
EXPORT_C TInt CFileMan::Delete(const TDesC& aName,TUint aSwitches) |
|
1275 |
/** |
|
1276 |
Deletes one or more files. |
|
1277 |
||
1278 |
This is a synchronous function. |
|
1279 |
||
1280 |
This function can operate recursively or non-recursively. |
|
1281 |
When operating non-recursively, only the matching files located in |
|
1282 |
the directory specified in aName are affected. |
|
1283 |
When operating recursively, all matching files in the directory hierarchy |
|
1284 |
below the directory specified in aName will be deleted. |
|
1285 |
||
1286 |
Note that read-only and open files may not be deleted. |
|
1287 |
Attempting to do so will return an error for that file. |
|
1288 |
Error codes may be retrieved using CFileBase::GetLastError(). |
|
1289 |
||
1290 |
@param aName Path indicating the file(s) to be deleted. |
|
1291 |
May either be a full path, or relative to the session path. |
|
1292 |
Use wildcards to specify more than one file. |
|
1293 |
NOTE: if you pass KNullDesC, the empty (or null) descriptor, |
|
1294 |
then the function interprets this to mean \\*.* |
|
1295 |
@param aSwitches Specify: |
|
1296 |
zero for no recursion; |
|
1297 |
CFileMan::ERecurse for recursion. |
|
1298 |
By default, the synchronous variant of this function |
|
1299 |
operates non-recursively. |
|
1300 |
||
1301 |
@return KErrNone if successful, otherwise one of the other system-wide error |
|
1302 |
codes. |
|
1303 |
||
1304 |
@see CFileBase::GetLastError() |
|
1305 |
||
1306 |
@capability Dependent If aName is /Sys then Tcb capability is required. |
|
1307 |
@capability Dependent If aName begins with /Private and does not match this process' SID |
|
1308 |
then AllFiles capability is required. |
|
1309 |
@capability Dependent If aName is /Resource then Tcb capability is required. |
|
1310 |
||
1311 |
@see KNullDesC |
|
1312 |
*/ |
|
1313 |
{ |
|
257 | 1314 |
TRACEMULT3(UTF::EBorder, UTraceModuleEfsrv::ECFileManDelete2, MODULEUID, (TUint) this, aName, aSwitches); |
0 | 1315 |
|
1316 |
TInt ret; |
|
1317 |
if (iSwitches&KFManBusyFlag) |
|
1318 |
{ |
|
1319 |
ret = KErrInUse; |
|
1320 |
} |
|
1321 |
else |
|
1322 |
{ |
|
1323 |
SetFlags(aSwitches&EOverWrite,aSwitches&ERecurse,ETrue,EFalse); |
|
257 | 1324 |
RETURNIFERRORD(r,iFs.Parse(aName,iSrcFile),UTraceModuleEfsrv::ECFileManDelete2Return); |
0 | 1325 |
iAction = EInternalDelete; |
1326 |
iMatchEntry=KEntryAttHidden|KEntryAttMatchExclude|KEntryAttDir; |
|
1327 |
// Exclude directories and system files - include hidden files |
|
1328 |
iNumberOfFilesProcessed = 0; |
|
1329 |
TRAP(r,RunL()); |
|
1330 |
ret=(r==KErrNone) ? iLastError : r; |
|
1331 |
DoSynchronize(r); |
|
1332 |
} |
|
1333 |
||
257 | 1334 |
TRACERET1(UTF::EBorder, UTraceModuleEfsrv::ECFileManDelete2Return, MODULEUID, ret); |
0 | 1335 |
return(ret); |
1336 |
} |
|
1337 |
||
1338 |
||
1339 |
||
1340 |
||
1341 |
EXPORT_C TInt CFileMan::Move(const TDesC& anOld,const TDesC& aNew,TUint aSwitches,TRequestStatus& aStatus) |
|
1342 |
/** |
|
1343 |
Moves one or more files. |
|
1344 |
||
1345 |
This is an asynchronous function. |
|
1346 |
Its behaviour is the same as the synchronous overload. |
|
1347 |
||
1348 |
@param anOld Path indicating the files to be moved. May be either |
|
1349 |
a full path, or relative to the session path. Any path |
|
1350 |
components which are not specified here will be taken |
|
1351 |
from the session path. |
|
1352 |
@param aNew Path indicating the directory into which the file(s) are |
|
1353 |
to be moved. Any path components which are not specified |
|
1354 |
here will be taken from the session path. |
|
1355 |
@param aSwitches Specify zero for no overwriting and no recursion; |
|
1356 |
CFileMan::EOverWrite to overwrite files with the same name; |
|
1357 |
CFileMan::ERecurse for recursion. |
|
1358 |
By default, the synchronous variant of this function operates |
|
1359 |
non-recursively and with overwriting. |
|
1360 |
@param aStatus The request status object. On request completion, |
|
1361 |
indicates how the request completed: |
|
1362 |
KErrNone, if successful, otherwise one of the other system-wide error |
|
1363 |
codes. |
|
1364 |
||
1365 |
@return KErrNone if the asynchronous request is made successfully; KErrInUse if an asynchronous request |
|
1366 |
is still pending; otherwise one of the other system-wide error codes |
|
1367 |
||
1368 |
@capability Dependent If the path in aNew starts with /Sys then capability Tcb is required |
|
1369 |
@capability Dependent If the path in aNew starts with /Resource then capability Tcb is required |
|
1370 |
||
1371 |
@capability AllFiles |
|
1372 |
||
1373 |
@capability Dependent If the path in anOld starts with /Sys then Tcb capability is required. |
|
1374 |
@capability Dependent If the path in anOld starts with /Resource then Tcb capability is required. |
|
1375 |
||
1376 |
*/ |
|
1377 |
{ |
|
257 | 1378 |
TRACEMULT5(UTF::EBorder, UTraceModuleEfsrv::ECFileManMove1, MODULEUID, |
1379 |
(TUint) this, anOld, aNew, aSwitches, (TUint) &aStatus); |
|
0 | 1380 |
|
1381 |
TInt r; |
|
1382 |
if (iSwitches&KFManBusyFlag) |
|
1383 |
{ |
|
1384 |
r = KErrInUse; |
|
1385 |
} |
|
1386 |
else |
|
1387 |
{ |
|
1388 |
iStatus=&aStatus; |
|
1389 |
r = Move(anOld,aNew,aSwitches); |
|
1390 |
} |
|
1391 |
||
257 | 1392 |
TRACERET1(UTF::EBorder, UTraceModuleEfsrv::ECFileManMove1Return, MODULEUID, r); |
0 | 1393 |
return r; |
1394 |
} |
|
1395 |
||
1396 |
||
1397 |
||
1398 |
||
1399 |
EXPORT_C TInt CFileMan::Move(const TDesC& anOld,const TDesC& aNew,TUint aSwitches) |
|
1400 |
/** |
|
1401 |
Moves one or more files. |
|
1402 |
||
1403 |
This is a synchronous function. |
|
1404 |
||
1405 |
Optionally, this function can be set to overwrite any files with the same name |
|
1406 |
which exist in the target directory. If the flag is set for no overwriting, |
|
1407 |
then any files with the same name will not be overwritten, and |
|
1408 |
an error (KErrAlreadyExists) will be returned for that file. |
|
1409 |
Error codes may be retrieved using CFileBase::GetLastError(). |
|
1410 |
By default, when the function is operating synchronously, files are overwritten. |
|
1411 |
||
1412 |
When this function is operating recursively, all intermediate directories will |
|
1413 |
be created, including all directories in the destination path specified |
|
1414 |
by aNew which do not already exist. |
|
1415 |
||
1416 |
If recursive operation is not set, only the matching files located in |
|
1417 |
the single directory specified in anOld are moved. No intermediate directories |
|
1418 |
will be created; if any directories in the destination path do not exist, |
|
1419 |
no files will be moved, and this function will return KErrPathNotFound. |
|
1420 |
||
1421 |
The behaviour of the move operation is sensitive to the presence (or absence) |
|
1422 |
of a trailing backslash ("\") character on the end of the source path: |
|
1423 |
- if there is a trailing backslash ("\") character, then the operation moves |
|
1424 |
the content of the last directory level only. |
|
1425 |
- if there is no trailing backslash ("\") character, then the operation behaves |
|
1426 |
recursively by default and moves both the last directory level and all of its content. |
|
1427 |
Notice that no trailing backslash ("\") implies moving files recursively automatically. |
|
1428 |
||
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1429 |
For example, if the directory level "b" contains the files F1, F2 and F3, then: |
0 | 1430 |
@code |
1431 |
CFileMan* fm(CFileMan::NewL(iFs)); // Where iFs is an RFs handle |
|
1432 |
... |
|
1433 |
fm->Move(_L("C:\\a\\b\\"), _L("C:\\x\\y\\"), CFileMan::ERecurse); |
|
1434 |
@endcode |
|
1435 |
||
1436 |
results in files F1, F2 and F3 being moved from C:\\a\\b to C:\\x\\y, leaving the |
|
1437 |
path C:\\a\\b unchanged, except that it no longer contains the files |
|
1438 |
F1, F2 and F3. |
|
1439 |
||
1440 |
If there is no trailing backslash character, for example: |
|
1441 |
@code |
|
1442 |
CFileMan* fm(CFileMan::NewL(iFs)); // Where iFs is an RFs handle |
|
1443 |
... |
|
1444 |
fm->Move(_L("C:\\a\\b"), _L("C:\\x\\y\\"), CFileMan::ERecurse); |
|
1445 |
@endcode |
|
1446 |
||
1447 |
then both the directory level "b" and its contents are moved. This means that |
|
1448 |
there is no longer a directory "b" under C:\\a. Instead there is a new |
|
1449 |
directory structure C:\\x\\y\\b and the files F1, F2, and F3 now exist |
|
1450 |
under C:\\x\\y\\b. Also if "b" contains subdirectories, then these are also |
|
1451 |
moved along with "b". |
|
1452 |
||
1453 |
If there is no trailing backslash character and the switch is not set, i.e. |
|
1454 |
0 is passed as an argument, the operation behaves the same way as by passing |
|
1455 |
CFileMan::ERecurse flag. |
|
1456 |
||
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1457 |
For example: |
0 | 1458 |
@code |
1459 |
CFileMan* fm(CFileMan::NewL(iFs)); // Where iFs is an RFs handle |
|
1460 |
... |
|
1461 |
fm->Move(_L("C:\\a\\b"), _L("C:\\x\\y\\"), 0); |
|
1462 |
@endcode |
|
1463 |
||
1464 |
The example above produces the same output as: |
|
1465 |
||
1466 |
@code |
|
1467 |
CFileMan* fm(CFileMan::NewL(iFs)); // Where iFs is an RFs handle |
|
1468 |
... |
|
1469 |
fm->Move(_L("C:\\a\\b"), _L("C:\\x\\y\\"), CFileMan::ERecurse); |
|
1470 |
@endcode |
|
1471 |
||
257 | 1472 |
If the source (anOld) is a file and the recursive operation is set, |
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1473 |
then all the files with the same name as anOld in the source directory |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1474 |
including those in subdirectories will be moved to the destination. |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1475 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1476 |
For example, the initial directory structure is as follows: |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1477 |
C:\src\file.txt |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1478 |
C:\src\subdirA\file.txt |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1479 |
C:\src\subdirB\file.txt |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1480 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1481 |
@code |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1482 |
CFileMan* fm(CFileMan::NewL(iFs)); // Where iFs is an RFs handle |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1483 |
fm->Move(_L("C:\\src\\file.txt"), _L("C:\\dest\\file.txt"), CFileMan::ERecurse); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1484 |
// OR without specifying the filename in aNew: |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1485 |
fm->Move(_L("C:\\src\\file.txt"), _L("C:\\dest\\"), CFileMan::ERecurse); |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1486 |
@endcode |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1487 |
|
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1488 |
Because of the recursive behaviour, the final directory structure after |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1489 |
either one of the move operations above will be as follows: |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1490 |
C:\src\ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1491 |
C:\src\subdirA\ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1492 |
C:\src\subdirB\ |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1493 |
C:\dest\file.txt |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1494 |
C:\dest\subdirA\file.txt |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1495 |
C:\dest\subdirB\file.txt |
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1496 |
|
0 | 1497 |
Notes: |
1498 |
||
1499 |
-# Read-only, hidden and system files can be moved and the source file's |
|
1500 |
attributes are preserved in the target file, but open files cannot |
|
1501 |
be moved. Attempting to move an open file will return an error for |
|
1502 |
that file, as retrieved by CFileBase::GetLastError(). |
|
1503 |
||
117
5b5d147c7838
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1504 |
@param anOld Path indicating the directory/files to be moved. May be either a full path, or |
0 | 1505 |
relative to the session path. Note that if you specify a directory level, |
1506 |
then the behaviour of the move operation is sensitive to the presence |
|
1507 |
(or absence) of a trailing backslash ("\") character. Any path components |
|
1508 |
which are not specified here will be taken from the session path. See the |
|
1509 |
main description for the detailed explanation. |
|
1510 |
@param aNew Path indicating the directory into which the file(s) are to be moved. |
|
1511 |
Any path components which are not specified here will be taken from the session path. |
|
1512 |
@param aSwitches CFileMan::EOverWrite to overwrite files with the same name; |
|
1513 |
CFileMan::ERecurse for recursion. |
|
1514 |
By default, the synchronous variant of this function operates non-recursively and |
|
1515 |
with overwriting. And no trailing backslash ("\") character at the end of source path |
|
1516 |
always means CFileMan::ERecurse. |
|
1517 |
||
1518 |
@return KErrNone if successful, otherwise one of the other system-wide error |
|
1519 |
codes. |
|
1520 |
||
1521 |
@capability Dependent If the path in aNew starts with /Sys then capability Tcb is required |
|
1522 |
@capability Dependent If the path in aNew starts with /Resource then capability Tcb is required |
|
1523 |
||
1524 |
@capability AllFiles |
|
1525 |
||
1526 |
@capability Dependent If the path in anOld starts with /Sys then Tcb capability is required. |
|
1527 |
@capability Dependent If the path in anOld starts with /Resource then Tcb capability is required. |
|
1528 |
||
1529 |
@see CFileBase::GetLastError() |
|
1530 |
*/ |
|
1531 |
{ |
|
257 | 1532 |
TRACEMULT4(UTF::EBorder, UTraceModuleEfsrv::ECFileManMove2, MODULEUID, |
1533 |
(TUint) this, anOld, aNew, aSwitches); |
|
0 | 1534 |
|
1535 |
||
1536 |
if (iSwitches&KFManBusyFlag) |
|
1537 |
{ |
|
257 | 1538 |
TRACE1(UTF::EBorder, UTraceModuleEfsrv::ECFileManMove2Return, MODULEUID, KErrInUse); |
0 | 1539 |
return(KErrInUse); |
1540 |
} |
|
1541 |
||
1542 |
iNumberOfFilesProcessed = 0; |
|
1543 |
||
257 | 1544 |
RETURNIFERRORD(r,iFs.Parse(anOld,iSrcFile),UTraceModuleEfsrv::ECFileManMove2Return); |
1545 |
RETURNIFERROR(r,iFs.Parse(aNew,_L("*"),iTrgFile),UTraceModuleEfsrv::ECFileManMove2Return); |
|
0 | 1546 |
|
1547 |
TInt ret = KErrNone; |
|
1548 |
TBool aComplete = EFalse; |
|
1549 |
if(SrcTrgDrivesIdentical()) |
|
1550 |
{ |
|
1551 |
ret = SetupMoveOnSameDrive(aSwitches, aComplete); |
|
1552 |
} |
|
1553 |
else |
|
1554 |
{ |
|
1555 |
ret = SetupMoveAcrossDrives(aSwitches); |
|
1556 |
} |
|
1557 |
||
1558 |
if(ret != KErrNone || aComplete) |
|
1559 |
{ |
|
1560 |
if (iStatus) |
|
1561 |
{ |
|
1562 |
User::RequestComplete(iStatus, ret); |
|
1563 |
} |
|
257 | 1564 |
TRACERET1(UTF::EBorder, UTraceModuleEfsrv::ECFileManMove2Return, MODULEUID, ret); |
0 | 1565 |
return(ret); |
1566 |
} |
|
1567 |
||
1568 |
iMatchEntry = KEntryAttMaskSupported; |
|
1569 |
if((aSwitches&ERecurse)==0 && iMovingContents) |
|
1570 |
{ |
|
1571 |
iMatchEntry = KMovingFilesMask; |
|
1572 |
} |
|
1573 |
||
1574 |
// Do the Move or Rename Operation |
|
1575 |
TRAP(r,RunL()); |
|
1576 |
ret = (r==KErrNone) ? iLastError : r; |
|
1577 |
DoSynchronize(r); |
|
1578 |
||
257 | 1579 |
TRACERET1(UTF::EBorder, UTraceModuleEfsrv::ECFileManMove2Return, MODULEUID, ret); |
0 | 1580 |
return(ret); |
1581 |
} |
|
1582 |
||
1583 |
||
1584 |
TBool CFileMan::SrcTrgDrivesIdentical() |
|
1585 |
// |
|
1586 |
// Returns ETrue if the source and target drives are the same |
|
1587 |
// - Used by CFileMan::Move operations to determine whether to rename or move the files |
|
1588 |
// |
|
1589 |
{ |
|
1590 |
return iSrcFile.Drive().MatchF(iTrgFile.Drive()) != KErrNotFound; |
|
1591 |
} |
|
1592 |
||
1593 |
||
1594 |
TInt CFileMan::SetupDirectoryForMove(TBool& aSrcIsDir) |
|
1595 |
/** |
|
1596 |
* Sets up the target specification to include the new target directory if required. |
|
1597 |
* |
|
1598 |
* @param aSrcIsDir Set to ETrue if the source specifies that the directory is to be moved in its entirety, |
|
1599 |
* or EFalse if only the contents of the directory need to be moved. |
|
1600 |
* |
|
1601 |
* @return KErrNone if successful, otherwise one of the system wide error codes. |
|
1602 |
*/ |
|
1603 |
{ |
|
1604 |
iMovingContents = ETrue; |
|
1605 |
aSrcIsDir = EFalse; |
|
1606 |
||
1607 |
TPtrC nameAndExt(iSrcFile.NameAndExt()); |
|
1608 |
if (nameAndExt == _L("*") || nameAndExt == _L("*.*")) |
|
1609 |
{ |
|
1610 |
// Wildcard specification - Move the entire contents of the directory to the target |
|
1611 |
aSrcIsDir = ETrue; |
|
1612 |
} |
|
1613 |
else |
|
1614 |
{ |
|
1615 |
TInt src = iFs.Entry(iSrcFile.FullName(), iTmpEntry); |
|
1616 |
if ((src == KErrNone && iTmpEntry.iAtt&KEntryAttDir) || (!iSrcFile.NamePresent() && iSrcFile.IsRoot())) |
|
1617 |
{ |
|
1618 |
aSrcIsDir = ETrue; |
|
1619 |
||
1620 |
// A directory is specified. |
|
1621 |
// - Mandatory recursion with Wildcard Copy |
|
1622 |
// - Target is a directory (Enforced by MakeParseWild) |
|
1623 |
||
1624 |
MakeParseWild(iTrgFile, iTmpName1); |
|
1625 |
||
1626 |
// Construct the target name by parsing |
|
1627 |
// the source path for the directory name. |
|
1628 |
TPtrC srcPath(iSrcFile.FullName()); |
|
1629 |
TInt srcPathLen = srcPath.Length() - 1; |
|
1630 |
||
1631 |
iMovingContents = (srcPath[srcPathLen] == KPathDelimiter); // Moving the directory itself, or the contents? |
|
1632 |
||
1633 |
if(!iMovingContents) |
|
1634 |
{ |
|
1635 |
// No path delimiter specified |
|
1636 |
// - move the whole directory (if specified) |
|
1637 |
TInt len = srcPath.Length(); |
|
1638 |
||
1639 |
TInt idx = srcPath.Left(len).LocateReverse(KPathDelimiter); |
|
1640 |
||
1641 |
if((idx >= 2) && (idx != KErrNotFound)) |
|
1642 |
{ |
|
1643 |
// Source path is a directory (not just the drive) |
|
1644 |
TPtrC mid(srcPath.Left(len).Mid(1+idx)); |
|
1645 |
TInt r = iTrgFile.AddDir(mid); |
|
1646 |
if (r != KErrNone) |
|
1647 |
return r; |
|
1648 |
} |
|
1649 |
} |
|
1650 |
} |
|
1651 |
} |
|
1652 |
||
1653 |
return KErrNone; |
|
1654 |
} |
|
1655 |
||
1656 |
||
1657 |
TInt CFileMan::SetupTargetDirectory(TBool aOverWrite, TBool& aComplete) |
|
1658 |
{ |
|
1659 |
aComplete = EFalse; |
|
1660 |
||
1661 |
TInt trgErr = iFs.Entry(iTrgFile.DriveAndPath(), iTmpEntry); |
|
1662 |
||
1663 |
TEntry srcEntry; |
|
1664 |
TInt srcErr = iFs.Entry(iSrcFile.FullName(), srcEntry); |
|
1665 |
||
1666 |
if(srcErr == KErrNone && trgErr == KErrNone) |
|
1667 |
{ |
|
1668 |
if ((srcEntry.iAtt&KEntryAttDir) != (iTmpEntry.iAtt&KEntryAttDir)) |
|
1669 |
{ |
|
1670 |
// return KErrAccessDenied if it is trying to overwrite a file to a dir or vice versa. |
|
1671 |
return KErrAccessDenied; |
|
1672 |
} |
|
1673 |
} |
|
1674 |
||
1675 |
if(trgErr == KErrNone) |
|
1676 |
{ |
|
1677 |
// Already Exists - Overwrite if flags set |
|
1678 |
if(!aOverWrite) |
|
1679 |
{ |
|
1680 |
trgErr = KErrAlreadyExists; |
|
1681 |
} |
|
1682 |
else |
|
1683 |
{ |
|
1684 |
iNumberOfFilesProcessed++; |
|
1685 |
} |
|
1686 |
} |
|
1687 |
else if((trgErr == KErrNotFound) || (trgErr == KErrPathNotFound)) |
|
1688 |
{ |
|
1689 |
if(SrcTrgDrivesIdentical()) |
|
1690 |
{ |
|
1691 |
// When moving a directory on the same drive, the directory can simply be renamed... |
|
1692 |
TParse& midDir = iTmpParse; |
|
1693 |
midDir = iTrgFile; |
|
1694 |
if(midDir.PopDir() == KErrNone) |
|
1695 |
{ |
|
1696 |
// ...before renaming, ensure that all intermediate directories exist |
|
1697 |
trgErr = iFs.MkDirAll(midDir.DriveAndPath()); |
|
1698 |
if(trgErr == KErrAlreadyExists) |
|
1699 |
{ |
|
1700 |
trgErr = KErrNone; |
|
1701 |
} |
|
1702 |
} |
|
1703 |
||
1704 |
if (trgErr == KErrNone) |
|
1705 |
{ |
|
1706 |
// ...and finally rename the source directory |
|
1707 |
trgErr = iFs.Rename(iSrcFile.FullName(),iTrgFile.DriveAndPath()); |
|
1708 |
aComplete = ETrue; |
|
1709 |
} |
|
1710 |
} |
|
1711 |
else |
|
1712 |
{ |
|
1713 |
trgErr = iFs.MkDirAll(iTrgFile.FullName()); |
|
1714 |
} |
|
1715 |
iNumberOfFilesProcessed++; |
|
1716 |
} |
|
1717 |
||
1718 |
return(trgErr); |
|
1719 |
} |
|
1720 |
||
1721 |
||
1722 |
TInt CFileMan::SetupMoveOnSameDrive(TUint aSwitches, TBool& aComplete) |
|
1723 |
{ |
|
1724 |
// Moving on the same drive. |
|
1725 |
||
1726 |
aComplete = EFalse; |
|
1727 |
||
1728 |
TBool srcIsDir = EFalse; |
|
1729 |
TInt ret = SetupDirectoryForMove(srcIsDir); |
|
1730 |
if (ret != KErrNone) |
|
1731 |
{ |
|
1732 |
return ret; |
|
1733 |
} |
|
1734 |
||
1735 |
TBool scanDown = ETrue; |
|
1736 |
TBool recurse = (aSwitches & ERecurse); |
|
1737 |
||
1738 |
iAction = EInternalRenameForMove; |
|
1739 |
||
1740 |
TFileName& srcpath = iTmpName1; |
|
1741 |
srcpath.Copy(iSrcFile.FullName()); |
|
1742 |
if(srcpath.Length()<KMaxFileName && srcpath.Length()>1 && srcpath[srcpath.Length()-1]!=KPathDelimiter) |
|
1743 |
{ |
|
1744 |
srcpath.Append(KPathDelimiter); |
|
1745 |
} |
|
1746 |
||
1747 |
// If the source path is a subset of the target path then Move operation is not allowed |
|
1748 |
if((srcIsDir && recurse) || (srcIsDir && !iTrgFile.IsRoot() && !iMovingContents)) |
|
1749 |
{ |
|
1750 |
if(iTrgFile.FullName().Left(srcpath.Length()).MatchF(srcpath)==0) |
|
1751 |
{ |
|
1752 |
aComplete = ETrue; |
|
1753 |
return KErrInUse; |
|
1754 |
} |
|
1755 |
} |
|
1756 |
// if any of the SRC folders already existing in TRG, scan upwards |
|
1757 |
if(iMovingContents) |
|
1758 |
{ |
|
1759 |
CDirScan* srcScanDir = NULL; |
|
1760 |
CDirScan* trgScanDir = NULL; |
|
1761 |
CDir* srcEntryList = NULL; |
|
1762 |
CDir* trgEntryList = NULL; |
|
1763 |
TInt trgCnt = 0; |
|
1764 |
TInt srcCnt = 0; |
|
1765 |
||
1766 |
TRAP(ret,(srcScanDir = CDirScan::NewL(iFs))); |
|
1767 |
if (ret!=KErrNone) |
|
1768 |
{ |
|
1769 |
goto CleanUp; |
|
1770 |
} |
|
1771 |
TRAP(ret,srcScanDir->SetScanDataL(iSrcFile.FullName(),KEntryAttMaskSupported,ESortByName)); |
|
1772 |
if (ret!=KErrNone) |
|
1773 |
{ |
|
1774 |
goto CleanUp; |
|
1775 |
} |
|
1776 |
TRAP(ret,srcScanDir->NextL(srcEntryList)); |
|
1777 |
if(ret!=KErrNone) |
|
1778 |
{ |
|
1779 |
goto CleanUp; |
|
1780 |
} |
|
1781 |
TRAP(ret,(trgScanDir=CDirScan::NewL(iFs))); |
|
1782 |
if (ret!=KErrNone) |
|
1783 |
{ |
|
1784 |
goto CleanUp; |
|
1785 |
} |
|
1786 |
TRAP(ret,trgScanDir->SetScanDataL(iTrgFile.FullName(),KEntryAttMaskSupported,ESortByName)); |
|
1787 |
if (ret!=KErrNone) |
|
1788 |
{ |
|
1789 |
goto CleanUp; |
|
1790 |
} |
|
1791 |
TRAP(ret,trgScanDir->NextL(trgEntryList)); |
|
1792 |
if(ret!=KErrNone) |
|
1793 |
{ |
|
1794 |
goto CleanUp; |
|
1795 |
} |
|
1796 |
for(trgCnt=trgEntryList->Count()-1; trgCnt>-1; trgCnt--) |
|
1797 |
{ |
|
1798 |
for(srcCnt=srcEntryList->Count()-1; srcCnt>-1; srcCnt--) |
|
1799 |
{ |
|
1800 |
if( (*srcEntryList)[srcCnt].iName == (*trgEntryList)[trgCnt].iName |
|
1801 |
&& ((*srcEntryList)[srcCnt].iAtt & KEntryAttDir) |
|
1802 |
&& ((*trgEntryList)[trgCnt].iAtt & KEntryAttDir)) |
|
1803 |
{ |
|
1804 |
// Set scan upwards |
|
1805 |
scanDown = EFalse; |
|
1806 |
goto CleanUp; |
|
1807 |
} |
|
1808 |
}// end inner for loop |
|
1809 |
} // end outer for loop |
|
1810 |
CleanUp: |
|
1811 |
// clean up |
|
1812 |
if(srcEntryList!=NULL) |
|
1813 |
delete srcEntryList; |
|
1814 |
if(trgEntryList!=NULL) |
|
1815 |
delete trgEntryList; |
|
1816 |
if(srcScanDir!=NULL) |
|
1817 |
delete srcScanDir; |
|
1818 |
if(trgScanDir!=NULL) |
|
1819 |
delete trgScanDir; |
|
1820 |
}// end if(iMovingContents) |
|
1821 |
||
1822 |
if(srcIsDir && !iTrgFile.IsRoot() && !iMovingContents) |
|
1823 |
{ |
|
1824 |
ret = SetupTargetDirectory(aSwitches & EOverWrite, aComplete); |
|
1825 |
if(ret != KErrNone || aComplete) |
|
1826 |
{ |
|
1827 |
return(ret); |
|
1828 |
} |
|
1829 |
} |
|
1830 |
if(!iMovingContents) |
|
1831 |
{ |
|
1832 |
recurse = ETrue; |
|
1833 |
scanDown = EFalse; |
|
1834 |
} |
|
1835 |
if(srcIsDir) |
|
1836 |
{ |
|
1837 |
MakeParseWild(iSrcFile, iTmpName1); |
|
1838 |
} |
|
1839 |
||
1840 |
SetFlags(aSwitches & EOverWrite, recurse, scanDown, ETrue); |
|
1841 |
return(KErrNone); |
|
1842 |
} |
|
1843 |
||
1844 |
||
1845 |
TInt CFileMan::SetupMoveAcrossDrives(TUint aSwitches) |
|
1846 |
{ |
|
1847 |
// Moving across drives. We may need to recurse, |
|
1848 |
// depending on the supplied source path. |
|
1849 |
||
1850 |
TBool srcIsDir = EFalse; |
|
1851 |
TInt ret = SetupDirectoryForMove(srcIsDir); |
|
1852 |
if (ret != KErrNone) |
|
1853 |
{ |
|
1854 |
return ret; |
|
1855 |
} |
|
1856 |
||
1857 |
TBool recurse = (aSwitches & ERecurse); |
|
1858 |
TBool scanDown = (recurse) ? (TBool)EFalse : (TBool)ETrue; |
|
1859 |
||
1860 |
if(srcIsDir) |
|
1861 |
{ |
|
1862 |
if(!iMovingContents) |
|
1863 |
{ |
|
1864 |
recurse = ETrue; |
|
1865 |
if(!iTrgFile.IsRoot()) |
|
1866 |
{ |
|
1867 |
TBool complete = EFalse; |
|
1868 |
ret = SetupTargetDirectory(aSwitches & EOverWrite, complete); |
|
1869 |
if(ret != KErrNone || complete) |
|
1870 |
{ |
|
1871 |
return(ret); |
|
1872 |
} |
|
1873 |
} |
|
1874 |
} |
|
1875 |
} |
|
1876 |
||
1877 |
CheckForDirectory(); |
|
1878 |
iAction = EInternalCopyForMove; |
|
1879 |
SetFlags(aSwitches & EOverWrite, recurse, scanDown, EFalse); |
|
1880 |
return(KErrNone); |
|
1881 |
} |
|
1882 |
||
257 | 1883 |
TInt CFileMan::RenameInvalidEntry(const TDesC& /*aName*/,const TDesC& /*aNewName*/,TUint /*aSwitches*/) |
1884 |
// |
|
1885 |
// Start rename operation |
|
1886 |
// |
|
1887 |
{ |
|
1888 |
return KErrNotSupported; |
|
1889 |
} |
|
1890 |
||
1891 |
||
0 | 1892 |
|
1893 |
||
1894 |
EXPORT_C TInt CFileMan::Rename(const TDesC& aName,const TDesC& aNewName,TUint aSwitches,TRequestStatus& aStatus) |
|
1895 |
/** |
|
1896 |
Renames one or more files. |
|
1897 |
||
1898 |
This is an asynchronous function. |
|
1899 |
Its behaviour is the same as the synchronous overload. |
|
1900 |
||
1901 |
@param aName Path specifying the file(s) to be renamed. Any path components |
|
1902 |
which are not specified |
|
1903 |
here will be taken from the session path. |
|
1904 |
@param aNewName Path specifying the new name for the files and/or |
|
1905 |
the new directory. Any directories specified in this path |
|
1906 |
that do not exist, will be created. Any path components |
|
1907 |
which are not specified here will be taken from the session path. |
|
1908 |
@param aSwitches Specify zero for no overwriting; |
|
1909 |
CFileMan::EOverWrite to overwrite files with the same name. |
|
1910 |
This function cannot operate recursively. |
|
1911 |
@param aStatus The request status object. On request completion, |
|
1912 |
indicates how the request completed: |
|
1913 |
KErrNone, if successful, otherwise one of the other system-wide error |
|
1914 |
codes. |
|
1915 |
||
1916 |
@return KErrNone if the asynchronous request is made successfully; KErrInUse if an asynchronous request |
|
1917 |
is still pending; otherwise one of the other system-wide error codes |
|
1918 |
||
1919 |
@capability Dependent If either aName or aNewName is /Sys then Tcb capability is required. |
|
1920 |
@capability Dependent If either aName or aNewName begins with /Private and does not match |
|
1921 |
this process' SID then AllFiles capability is required. |
|
1922 |
@capability Dependent If either aName or aNewName is /Resource then Tcb capability is required. |
|
1923 |
||
1924 |
*/ |
|
1925 |
{ |
|
257 | 1926 |
TRACEMULT5(UTF::EBorder, UTraceModuleEfsrv::ECFileManRename1, MODULEUID, |
1927 |
(TUint) this, aName, aNewName, aSwitches, (TUint) &aStatus); |
|
0 | 1928 |
|
1929 |
TInt r; |
|
1930 |
if (iSwitches&KFManBusyFlag) |
|
1931 |
{ |
|
1932 |
r = KErrInUse; |
|
1933 |
} |
|
1934 |
else |
|
1935 |
{ |
|
1936 |
iStatus=&aStatus; |
|
1937 |
r = Rename(aName,aNewName,aSwitches); |
|
1938 |
} |
|
1939 |
||
257 | 1940 |
TRACERET1(UTF::EBorder, UTraceModuleEfsrv::ECFileManRename1Return, MODULEUID, r); |
0 | 1941 |
return(r); |
1942 |
} |
|
1943 |
||
1944 |
||
1945 |
||
1946 |
||
1947 |
EXPORT_C TInt CFileMan::Rename(const TDesC& aName,const TDesC& aNewName,TUint aSwitches) |
|
1948 |
/** |
|
1949 |
Renames one or more files, or a directory |
|
1950 |
||
1951 |
This is a synchronous function. |
|
1952 |
||
1953 |
The function can also be used to move files by specifying different destination |
|
1954 |
and source directories. |
|
1955 |
||
1956 |
Some rules for using CFileMan::Rename(): |
|
1957 |
||
1958 |
1. General rules: |
|
1959 |
||
1960 |
1.1. Trailing backslash ("\") in either source path (aName) or target path (aNewName) |
|
1961 |
will be interpreted to "\*.*"; |
|
1962 |
||
1963 |
For example, following code should behave identically: |
|
1964 |
@code |
|
1965 |
CFileMan* fm(CFileMan::NewL(iFs)); // Where iFs is an RFs handle |
|
1966 |
... |
|
1967 |
fm->Rename(_L("C:\\SRC\\"), _L("C:\\TRG\\")); |
|
1968 |
fm->Rename(_L("C:\\SRC\\*.*"), _L("C:\\TRG\\")); |
|
1969 |
fm->Rename(_L("C:\\SRC\\"), _L("C:\\TRG\\*.*")); |
|
1970 |
fm->Rename(_L("C:\\SRC\\*.*"), _L("C:\\TRG\\*.*")); |
|
1971 |
@endcode |
|
1972 |
||
1973 |
1.2 The behaviour of the rename operation is sensitive to the presence (or absence) of |
|
1974 |
a trailing backslash ("\") character on the end of the target path (aNewName); |
|
1975 |
||
1976 |
For example, under all other constraints (see rules 2. and 3.), |
|
1977 |
@code |
|
1978 |
CFileMan* fm(CFileMan::NewL(iFs)); // Where iFs is an RFs handle |
|
1979 |
... |
|
1980 |
fm->Rename(_L("C:\\SRC"), _L("C:\\TRG\")); |
|
1981 |
@endcode |
|
1982 |
will result in renaming "C:\\SRC" to "C:\\TRG\\SRC", while |
|
1983 |
@code |
|
1984 |
CFileMan* fm(CFileMan::NewL(iFs)); // Where iFs is an RFs handle |
|
1985 |
... |
|
1986 |
fm->Rename(_L("C:\\SRC"), _L("C:\\TRG")); |
|
1987 |
@endcode |
|
1988 |
will result in renaming "C:\\SRC" to "C:\\TRG". |
|
1989 |
||
1990 |
2. Renaming file(s): |
|
1991 |
||
1992 |
2.1 Wildcards: |
|
1993 |
||
1994 |
A file's name and extension are interpreted separately, for example: |
|
1995 |
||
1996 |
@code |
|
1997 |
CFileMan* fm(CFileMan::NewL(iFs)); // Where iFs is an RFs handle |
|
1998 |
... |
|
1999 |
fm->Rename(_L("C:\\SRC\\1234.567"), _L("C:\\TRG\\AB*CD.TXT")); |
|
2000 |
@endcode |
|
2001 |
renames the source file to file "C:\\TRG\\AB34CD.TXT". |
|
2002 |
||
2003 |
Wildcards can be used for renaming multiple files, for example; |
|
2004 |
@code |
|
2005 |
CFileMan* fm(CFileMan::NewL(iFs)); // Where iFs is an RFs handle |
|
2006 |
... |
|
2007 |
fm->Rename(_L("C:\\SRC\\*.567"), _L("C:\\TRG\\*.TXT")); |
|
2008 |
@endcode |
|
2009 |
renames all the file under "C:\\SRC\\" having extension ".567" to the files under |
|
2010 |
"C:\\TRG\\" having extension ".TXT". |
|
2011 |
||
2012 |
2.2 An option is provided to allow the user to overwrite any files with the same |
|
2013 |
name which may exist in the target directory; If the flag is set for no overwriting, |
|
2014 |
any files with the same name will not be overwritten, and an error (KErrAlreadyExists) |
|
2015 |
will be returned for that file, as retrieved by CFileBase::GetLastError(). |
|
2016 |
||
2017 |
2.3 It can only operate non-recursively, so that only the matching files located |
|
2018 |
in the single directory specified by anOld may be renamed. |
|
2019 |
||
2020 |
2.4 Trying to rename file(s) to existing directory(ies) will fail; |
|
2021 |
||
2022 |
For example, giving following directory structure: |
|
2023 |
@code |
|
2024 |
C:\SRC\ITEM01 |
|
2025 |
C:\SRC\ITEM02 |
|
2026 |
C:\TRG\ITEM01\ |
|
2027 |
C:\TRG\ITEM02\ |
|
2028 |
@endcode |
|
2029 |
||
2030 |
Following code will fail: |
|
2031 |
@code |
|
2032 |
CFileMan* fm(CFileMan::NewL(iFs)); // Where iFs is an RFs handle |
|
2033 |
... |
|
2034 |
fm->Rename(_L("C:\\SRC\\ITEM01"), _L("C:\\TRG\\ITEM01")); |
|
2035 |
fm->Rename(_L("C:\\SRC\\ITEM*"), _L("C:\\TRG\\ITEM*")); |
|
2036 |
fm->Rename(_L("C:\\SRC\\"), _L("C:\\TRG\\")); |
|
2037 |
@endcode |
|
2038 |
||
2039 |
3. When renamnig a directory: |
|
2040 |
||
2041 |
3.1. Only when the trailing backslash ("\") is missing from the source path (aName), |
|
2042 |
will the source directory be renamed, otherwise, see rule 1.1. |
|
2043 |
||
2044 |
For example, following code will result in moving "C:\SRC" directory including all |
|
2045 |
its contents: |
|
2046 |
@code |
|
2047 |
CFileMan* fm(CFileMan::NewL(iFs)); // Where iFs is an RFs handle |
|
2048 |
... |
|
2049 |
fm->Rename(_L("C:\\SRC"), _L("C:\\TRG")); |
|
2050 |
fm->Rename(_L("C:\\SRC"), _L("C:\\TRG\\")); |
|
2051 |
fm->Rename(_L("C:\\SRC"), _L("C:\\TRG\\*.*")); |
|
2052 |
@endcode |
|
2053 |
||
2054 |
3.2. Wildcards can not be used for moving directories; |
|
2055 |
||
2056 |
3.3. Overwriting is not permitted; |
|
2057 |
||
2058 |
For example, giving directory structure as following: |
|
2059 |
@code |
|
2060 |
C:\SRC\FILE.TXT |
|
2061 |
C:\TRG\ |
|
2062 |
C:\TRG\SRC\ |
|
2063 |
@endcode |
|
2064 |
||
2065 |
following code will fail: |
|
2066 |
@code |
|
2067 |
CFileMan* fm(CFileMan::NewL(iFs)); // Where iFs is an RFs handle |
|
2068 |
... |
|
2069 |
fm->Rename(_L("C:\\SRC"), _L("C:\\TRG")); |
|
2070 |
fm->Rename(_L("C:\\SRC"), _L("C:\\TRG\\")); |
|
2071 |
fm->Rename(_L("C:\\SRC"), _L("C:\\TRG\\*.*")); |
|
2072 |
@endcode |
|
2073 |
||
2074 |
4. Notes: |
|
2075 |
||
2076 |
4.1. The target and source directories must be on the same drive. |
|
2077 |
||
2078 |
4.2. Read-only, hidden and system files can be moved and the source file's |
|
2079 |
attributes are preserved in the target file, but open files cannot |
|
2080 |
be moved. Attempting to move an open file will return an error for |
|
2081 |
that file, as retrieved by CFileBase::GetLastError(). |
|
2082 |
||
2083 |
@param aName Path specifying the file(s) to be renamed. Any path components |
|
2084 |
which are not specified |
|
2085 |
here will be taken from the session path. |
|
2086 |
@param aNewName Path specifying the new name for the files and/or |
|
2087 |
the new directory. Any directories specified in this path |
|
2088 |
that do not exist, will be created. Any path components which |
|
2089 |
are not specified here will be taken from the session path. |
|
2090 |
@param aSwitches Specify zero for no overwriting; |
|
2091 |
CFileMan::EOverWrite to overwrite files with the same name. |
|
2092 |
This function cannot operate recursively. |
|
2093 |
||
2094 |
@return KErrNone if successful, otherwise one of the other system-wide error |
|
2095 |
codes. |
|
2096 |
||
2097 |
@see CFileBase::GetLastError() |
|
2098 |
||
2099 |
@capability Dependent If either aName or aNewName is /Sys then Tcb capability is required. |
|
2100 |
@capability Dependent If either aName or aNewName begins with /Private and does not match |
|
2101 |
this process' SID then AllFiles capability is required. |
|
2102 |
@capability Dependent If either aName or aNewName is /Resource then Tcb capability is required. |
|
2103 |
||
2104 |
*/ |
|
2105 |
{ |
|
257 | 2106 |
TRACEMULT4(UTF::EBorder, UTraceModuleEfsrv::ECFileManRename2, MODULEUID, |
2107 |
(TUint) this, aName, aNewName, aSwitches); |
|
0 | 2108 |
|
2109 |
TInt ret; |
|
2110 |
if (iSwitches&KFManBusyFlag) |
|
2111 |
{ |
|
2112 |
ret = KErrInUse; |
|
2113 |
} |
|
2114 |
else |
|
2115 |
{ |
|
2116 |
SetFlags(aSwitches&EOverWrite,EFalse,ETrue,EFalse); |
|
257 | 2117 |
RETURNIFERRORD(r,iFs.Parse(aName,iSrcFile),UTraceModuleEfsrv::ECFileManRename2Return); |
2118 |
RETURNIFERROR(r,iFs.Parse(aNewName,_L("*"),iTrgFile),UTraceModuleEfsrv::ECFileManRename2Return); |
|
0 | 2119 |
|
2120 |
iAction = EInternalRename; |
|
2121 |
iMatchEntry=KEntryAttMaskSupported; |
|
2122 |
iNumberOfFilesProcessed = 0; |
|
2123 |
TRAP(r,RunL()); |
|
2124 |
ret=(r==KErrNone) ? iLastError : r; |
|
2125 |
DoSynchronize(r); |
|
2126 |
} |
|
2127 |
||
257 | 2128 |
TRACERET1(UTF::EBorder, UTraceModuleEfsrv::ECFileManRename2Return, MODULEUID, ret); |
0 | 2129 |
return(ret); |
2130 |
} |
|
2131 |
||
2132 |
||
2133 |
EXPORT_C TInt CFileMan::RmDir(const TDesC& aDirName,TRequestStatus& aStatus) |
|
2134 |
/** |
|
2135 |
Deletes a directory and all files and directories contained in the |
|
2136 |
directory structure below it. |
|
2137 |
||
2138 |
Other than being asynchronous, the behaviour of this function is the same |
|
2139 |
as is documented in its synchronous overload. |
|
2140 |
||
2141 |
@param aDirName Path specifying the directory to be deleted. Any path components |
|
2142 |
which are not specified here will be taken from the session path. |
|
2143 |
@param aStatus The request status object. On request completion, indicates how |
|
2144 |
the request completed: |
|
2145 |
KErrNone if successful, otherwise one of the other system-wide |
|
2146 |
error codes. |
|
2147 |
||
2148 |
@return KErrNone if the asynchronous request is made successfully; KErrInUse if an asynchronous request |
|
2149 |
is still pending; otherwise one of the other system-wide error codes |
|
2150 |
||
2151 |
@capability Dependent If aDirName starts with /Sys then Tcb capability is required. |
|
2152 |
@capability Dependent If aDirName begins with /Private and does not match this process' SID |
|
2153 |
then AllFiles capability is required. |
|
2154 |
@capability Dependent If aDirName starts with /Resource then Tcb capability is required. |
|
2155 |
||
2156 |
*/ |
|
2157 |
{ |
|
257 | 2158 |
TRACEMULT3(UTF::EBorder, UTraceModuleEfsrv::ECFileManRmDir1, MODULEUID, (TUint) this, aDirName, (TUint) &aStatus); |
0 | 2159 |
|
2160 |
TInt r; |
|
2161 |
if (iSwitches&KFManBusyFlag) |
|
2162 |
{ |
|
2163 |
r = KErrInUse; |
|
2164 |
} |
|
2165 |
else |
|
2166 |
{ |
|
2167 |
iStatus=&aStatus; |
|
2168 |
r = RmDir(aDirName); |
|
2169 |
} |
|
2170 |
||
257 | 2171 |
TRACERET1(UTF::EBorder, UTraceModuleEfsrv::ECFileManRmDir1Return, MODULEUID, r); |
0 | 2172 |
return r; |
2173 |
} |
|
2174 |
||
2175 |
||
2176 |
EXPORT_C TInt CFileMan::RmDir(const TDesC& aDirName) |
|
2177 |
/** |
|
2178 |
Deletes a directory and all files and directories contained in the |
|
2179 |
directory structure below it. |
|
2180 |
||
2181 |
This is a synchronous function. |
|
2182 |
||
2183 |
The function cannot be used non-recursively. For a non-recursive |
|
2184 |
directory deletion, use RFs::RmDir(). |
|
2185 |
||
2186 |
Note: |
|
2187 |
||
2188 |
1. All files in the directory hierarchy to be deleted must be closed and |
|
2189 |
none may have the read-only attribute. Otherwise, not all of the hierarchy will |
|
2190 |
be deleted, and this function will return KErrInUse. |
|
2191 |
||
2192 |
@param aDirName Path specifying the directory to be deleted. Any path components |
|
2193 |
which are not specified here will be taken from the session path. |
|
2194 |
||
2195 |
@return KErrNone if successful, otherwise one of the other system-wide error |
|
2196 |
codes. |
|
2197 |
||
2198 |
@capability Dependent If aDirName starts with /Sys then Tcb capability is required. |
|
2199 |
@capability Dependent If aDirName begins with /Private and does not match this process' SID |
|
2200 |
then AllFiles capability is required. |
|
2201 |
@capability Dependent If aDirName starts with /Resource then Tcb capability is required. |
|
2202 |
||
2203 |
||
2204 |
*/ |
|
2205 |
{ |
|
257 | 2206 |
TRACEMULT2(UTF::EBorder, UTraceModuleEfsrv::ECFileManRmDir2, MODULEUID, (TUint) this, aDirName); |
0 | 2207 |
|
2208 |
TInt ret; |
|
2209 |
if (iSwitches&KFManBusyFlag) |
|
2210 |
{ |
|
2211 |
ret = KErrInUse; |
|
2212 |
} |
|
2213 |
else |
|
2214 |
{ |
|
2215 |
SetFlags(ETrue,ETrue,EFalse,EFalse); |
|
257 | 2216 |
RETURNIFERRORD(r,iFs.Parse(aDirName,iTrgFile),UTraceModuleEfsrv::ECFileManRmDir2Return); |
0 | 2217 |
iSrcFile.Set(iTrgFile.DriveAndPath(),NULL,NULL); |
2218 |
iAction = EInternalRmDir; |
|
2219 |
iMatchEntry=KEntryAttMaskSupported; |
|
2220 |
iNumberOfFilesProcessed = 0; |
|
2221 |
TRAP(r,RunL()); |
|
2222 |
DoSynchronize(r); |
|
2223 |
ret = (r!=KErrNone) ? iLastError : KErrNone; |
|
2224 |
} |
|
2225 |
||
257 | 2226 |
TRACERET1(UTF::EBorder, UTraceModuleEfsrv::ECFileManRmDir2Return, MODULEUID, ret); |
0 | 2227 |
return ret; |
2228 |
} |
|
2229 |
||
2230 |
||
2231 |
void CFileMan::DoOperationL() |
|
2232 |
// Call the action in progress. |
|
2233 |
{ |
|
2234 |
switch (iAction) |
|
2235 |
{ |
|
2236 |
case EInternalAttribs: |
|
2237 |
DoAttribsL(); |
|
2238 |
break; |
|
2239 |
case EInternalCopy: |
|
2240 |
case EInternalCopyForMove: |
|
2241 |
DoCopyOrMoveL(); |
|
2242 |
break; |
|
2243 |
case EInternalDelete: |
|
2244 |
DoDeleteL(); |
|
2245 |
break; |
|
2246 |
case EInternalRenameInvalidEntry: |
|
2247 |
case EInternalRenameForMove: |
|
2248 |
case EInternalRename: |
|
2249 |
DoRenameL(); |
|
2250 |
break; |
|
2251 |
case EInternalRmDir: |
|
2252 |
DoRmDirL(); |
|
2253 |
break; |
|
2254 |
case EInternalCopyFromHandle: |
|
2255 |
DoCopyFromHandleL(); |
|
2256 |
break; |
|
2257 |
default: |
|
2258 |
Panic(EFManUnknownAction); |
|
2259 |
} |
|
2260 |
} |
|
2261 |
||
2262 |
void CFileMan::DoAttribsL() |
|
2263 |
// |
|
2264 |
// Do attribs operation step |
|
2265 |
// |
|
2266 |
{ |
|
2267 |
TPtrC fullPath(FullPath()); |
|
2268 |
iTmpParse.Set(CurrentEntry().iName, &fullPath, NULL); |
|
2269 |
User::LeaveIfError(iFs.SetEntry(iTmpParse.FullName(), iTime, iSetMask, iClearMask)); |
|
2270 |
} |
|
2271 |
||
2272 |
void CFileMan::DoCopyOrMoveL() |
|
2273 |
// |
|
2274 |
// Do copy or move operation |
|
2275 |
// |
|
2276 |
{ |
|
2277 |
// Following 'if' statements are to prevent incorrect recursive Move() or Copy() from "destination" |
|
2278 |
// to "destination", this problem occurs when the initial source directory contains destination |
|
2279 |
// directory. |
|
2280 |
// (e.g. CFileMan::Move(_L("C:\\SRC\\*.TXT"), _L("C:\\SRC\\Sub\\"), CFileMan::ERecurse);) |
|
2281 |
// Note that CFileMan::Rename() does not suffer from this particular case, as CFileMan::Rename() API |
|
2282 |
// can only operate non-recursively. |
|
2283 |
if (iSrcFile.DriveAndPath().Length() < iTrgFile.DriveAndPath().Length()) |
|
2284 |
{ |
|
2285 |
if (iTrgFile.DriveAndPath().Left(iSrcFile.DriveAndPath().Length()) == iSrcFile.DriveAndPath()) |
|
2286 |
// If source directory path contains destination directory path, including drive number, we consider |
|
2287 |
// this is "...\\ROOT\\" -> "...\\ROOT\\SUB\\" type of operation. Therefore skips all the items we |
|
2288 |
// found in "...\\ROOT\\SUB\\". We achieve this by checking current scanning directory path: |
|
2289 |
{ |
|
2290 |
if (iTrgFile.DriveAndPath() == iScanner->FullPath().Left(iTrgFile.DriveAndPath().Length())) |
|
2291 |
{ |
|
2292 |
return; |
|
2293 |
} |
|
2294 |
} |
|
2295 |
} |
|
2296 |
||
2297 |
TParse& srcName = iTmpParse; |
|
2298 |
TFileName& trgName = iTmpName1; |
|
2299 |
GetSrcAndTrg(srcName,trgName); |
|
2300 |
||
2301 |
// Handle case when source is directory |
|
2302 |
if (CurrentEntry().iAtt&KEntryAttDir) |
|
2303 |
{ |
|
2304 |
if(!(iSwitches&KRecurseFlag)) |
|
2305 |
{ |
|
2306 |
User::Leave(KErrNone); |
|
2307 |
} |
|
2308 |
trgName.Append(KPathDelimiter); |
|
2309 |
TInt r = iFs.MkDirAll(trgName); |
|
2310 |
if (r!=KErrNone && r!=KErrAlreadyExists) |
|
2311 |
User::Leave(r); |
|
2312 |
||
2313 |
if(iAction == EInternalCopyForMove) |
|
2314 |
{ |
|
2315 |
// Move operation - Attempt to delete the source directory. |
|
2316 |
if((iMatchEntry & KMovingFilesMask) != KMovingFilesMask) |
|
2317 |
{ |
|
2318 |
iTmpName2 = srcName.FullName(); |
|
2319 |
iTmpName2.Append(KPathDelimiter); |
|
2320 |
TInt rdErr = iFs.RmDir(iTmpName2); |
|
2321 |
if(rdErr != KErrNone && rdErr != KErrInUse) |
|
2322 |
{ |
|
2323 |
User::Leave(rdErr); |
|
2324 |
} |
|
2325 |
} |
|
2326 |
} |
|
2327 |
return; |
|
2328 |
} |
|
2329 |
||
2330 |
#ifndef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
2331 |
RFile srcFile,trgFile; |
|
2332 |
#else |
|
2333 |
RFile64 srcFile,trgFile; |
|
2334 |
#endif |
|
2335 |
TInt r=KErrNone; |
|
2336 |
if (FileNamesIdentical(srcName.FullName(),trgName)) |
|
2337 |
{ |
|
2338 |
if (iSwitches & KOverWriteFlag) |
|
2339 |
// Source and target are identical, KOverWriteFlag makes copying |
|
2340 |
// having no effect. |
|
2341 |
return; |
|
2342 |
else |
|
2343 |
User::Leave(KErrAlreadyExists); |
|
2344 |
} |
|
2345 |
||
2346 |
r=srcFile.Open(iFs, srcName.FullName(), |
|
2347 |
iAction==EInternalCopy ? EFileRead|EFileShareReadersOnly // Copy access |
|
2348 |
: EFileWrite|EFileWriteDirectIO|EFileShareExclusive); // Move access |
|
2349 |
TBool isRO = EFalse; |
|
2350 |
if(r==KErrAccessDenied && iAction==EInternalCopyForMove) |
|
2351 |
{ |
|
2352 |
TEntry& entry = iTmpEntry; |
|
2353 |
r = iFs.Entry(srcName.FullName(), entry); |
|
2354 |
if(r==KErrNone && (entry.iAtt&KEntryAttReadOnly)) |
|
2355 |
{ |
|
2356 |
isRO = ETrue; |
|
2357 |
r = iFs.SetAtt(srcName.FullName(), 0, KEntryAttReadOnly); |
|
2358 |
if(r==KErrNone) |
|
2359 |
{ |
|
2360 |
r = srcFile.Open(iFs, srcName.FullName(), EFileWrite|EFileWriteDirectIO|EFileShareExclusive); |
|
2361 |
} |
|
2362 |
} |
|
2363 |
} |
|
2364 |
if (r!=KErrNone) |
|
2365 |
{ |
|
2366 |
iErrorInfo=ESrcOpenFailed; |
|
2367 |
if(isRO) |
|
2368 |
{ |
|
2369 |
iFs.SetAtt(srcName.FullName(), KEntryAttReadOnly, 0); |
|
2370 |
} |
|
2371 |
User::Leave(r); |
|
2372 |
} |
|
2373 |
||
2374 |
if ((iSwitches&KOverWriteFlag)==0) |
|
2375 |
r=trgFile.Create(iFs,trgName,EFileWrite|EFileWriteDirectIO|EFileShareExclusive); |
|
2376 |
else |
|
2377 |
r=trgFile.Replace(iFs,trgName,EFileWrite|EFileWriteDirectIO|EFileShareExclusive); |
|
2378 |
||
2379 |
if (r==KErrPathNotFound && (iSwitches&KRecurseFlag)) |
|
2380 |
{ |
|
2381 |
r=iFs.MkDirAll(trgName); |
|
2382 |
if (r==KErrNone) |
|
2383 |
r=trgFile.Create(iFs,trgName,EFileWrite|EFileWriteDirectIO|EFileShareExclusive); |
|
2384 |
} |
|
2385 |
||
2386 |
if (r!=KErrNone) |
|
2387 |
iErrorInfo=ETrgOpenFailed; |
|
2388 |
||
2389 |
TInt ret=0; |
|
2390 |
if (r == KErrNone) |
|
2391 |
r = DoCopy(srcFile, trgFile, ret); |
|
2392 |
||
2393 |
srcFile.Close(); |
|
2394 |
trgFile.Close(); |
|
2395 |
if ((r!=KErrNone && (r!=KErrAlreadyExists && iErrorInfo!=ETrgOpenFailed)) || (ret==MFileManObserver::ECancel)) |
|
2396 |
iFs.Delete(trgName); |
|
2397 |
if(r==KErrNone && isRO) |
|
2398 |
{ |
|
2399 |
r = iFs.SetAtt(trgName, KEntryAttReadOnly, 0); |
|
2400 |
} |
|
2401 |
User::LeaveIfError(r); |
|
2402 |
||
2403 |
// |
|
2404 |
// Move operation |
|
2405 |
// |
|
2406 |
if (iAction == EInternalCopyForMove && ret != MFileManObserver::ECancel) |
|
2407 |
{ |
|
2408 |
r=iFs.Delete(srcName.FullName()); |
|
2409 |
if (r==KErrNone) |
|
2410 |
return; |
|
2411 |
iFs.Delete(trgName); |
|
2412 |
User::Leave(r); |
|
2413 |
} |
|
2414 |
} |
|
2415 |
||
2416 |
void CFileMan::DoDeleteL() |
|
2417 |
// |
|
2418 |
// Do delete operation step |
|
2419 |
// |
|
2420 |
{ |
|
2421 |
TFileName& pathname = iTmpName1; |
|
2422 |
TFileName& filename = iTmpName2; |
|
2423 |
pathname.Copy(FullPath()); |
|
2424 |
filename.Copy(CurrentEntry().iName); |
|
2425 |
if(CurrentEntry().iName.Length() + pathname.Length() > KMaxFileName) |
|
2426 |
{ |
|
2427 |
User::LeaveIfError(ShrinkNames(iFs, pathname, filename, EFalse)); |
|
2428 |
} |
|
2429 |
iTmpParse.Set(filename, &pathname, NULL); |
|
2430 |
User::LeaveIfError(iFs.Delete(iTmpParse.FullName())); |
|
2431 |
} |
|
2432 |
||
2433 |
void CFileMan::DoRenameL() |
|
2434 |
// |
|
2435 |
// Do rename operation step |
|
2436 |
// |
|
2437 |
{ |
|
2438 |
// Following 'if' statements are to prevent incorrect recursive Move() or Copy() from "destination" |
|
2439 |
// to "destination", this problem occurs when the initial source directory contains destination |
|
2440 |
// directory. |
|
2441 |
// (e.g. CFileMan::Move(_L("C:\\SRC\\*.TXT"), _L("C:\\SRC\\Sub\\"), CFileMan::ERecurse);) |
|
2442 |
// Note that CFileMan::Rename() does not suffer from this particular case, as CFileMan::Rename() API |
|
2443 |
// can only operate non-recursively. |
|
2444 |
if (iSrcFile.DriveAndPath().Length() < iTrgFile.DriveAndPath().Length()) |
|
2445 |
{ |
|
2446 |
if (iTrgFile.DriveAndPath().Left(iSrcFile.DriveAndPath().Length()) == iSrcFile.DriveAndPath()) |
|
2447 |
// If source directory path contains destination directory path, including drive number, we consider |
|
2448 |
// this is "...\\ROOT\\" -> "...\\ROOT\\SUB\\" type of operation. Therefore skips all the items we |
|
2449 |
// found in "...\\ROOT\\SUB\\". We achieve this by checking current scanning directory path: |
|
2450 |
{ |
|
2451 |
if (iTrgFile.DriveAndPath() == iScanner->FullPath().Left(iTrgFile.DriveAndPath().Length())) |
|
2452 |
{ |
|
2453 |
return; |
|
2454 |
} |
|
2455 |
} |
|
2456 |
} |
|
2457 |
||
2458 |
TParse& srcName = iTmpParse; |
|
2459 |
TFileName& trgName = iTmpName1; |
|
2460 |
GetSrcAndTrg(srcName, trgName); |
|
2461 |
||
2462 |
TInt r = iFs.Rename(srcName.FullName(),trgName); |
|
2463 |
if (r==KErrAlreadyExists && (iSwitches&KOverWriteFlag)!=0) |
|
2464 |
{ |
|
2465 |
// Target already exists, with the overwrite flag enabled |
|
2466 |
if((CurrentEntry().iAtt & KEntryAttDir) == 0) |
|
2467 |
{ |
|
2468 |
// Renaming a file |
|
2469 |
r=iFs.Replace(srcName.FullName(),trgName); |
|
2470 |
} |
|
2471 |
else if (iAction == EInternalRenameForMove) |
|
2472 |
{ |
|
2473 |
trgName = srcName.FullName(); |
|
2474 |
trgName.Append(KPathDelimiter); |
|
2475 |
r = iFs.RmDir(trgName); // remove empty directory after move |
|
2476 |
if(r == KErrInUse) |
|
2477 |
{ |
|
2478 |
r = KErrNone; |
|
2479 |
} |
|
2480 |
} |
|
2481 |
} |
|
2482 |
||
2483 |
if (r==KErrPathNotFound) |
|
2484 |
{ |
|
2485 |
if((iSwitches&KMoveRenameFlag) && !(iSwitches&KRecurseFlag)) |
|
2486 |
User::Leave(r); |
|
2487 |
r=iFs.MkDirAll(trgName); |
|
2488 |
if (r==KErrNone) |
|
2489 |
r=iFs.Rename(srcName.FullName(),trgName); |
|
2490 |
} |
|
2491 |
if (r==KErrBadName) |
|
2492 |
{ |
|
2493 |
TEntry& entry = iTmpEntry; |
|
2494 |
TInt retcode=iFs.Entry(srcName.FullName(), entry); |
|
2495 |
if (retcode!=KErrNone) |
|
2496 |
iErrorInfo=ESrcOpenFailed; |
|
2497 |
else |
|
2498 |
iErrorInfo=ETrgOpenFailed; |
|
2499 |
} |
|
2500 |
User::LeaveIfError(r); |
|
2501 |
} |
|
2502 |
||
2503 |
void CFileMan::DoRmDirL() |
|
2504 |
// |
|
2505 |
// Do rmdir operation step |
|
2506 |
// |
|
2507 |
{ |
|
2508 |
TFileName& srcName = iTmpName1; |
|
2509 |
srcName.Copy(FullPath()); |
|
2510 |
if (srcName.Length() + CurrentEntry().iName.Length() > KMaxFileName) |
|
2511 |
{ |
|
2512 |
TFileName& current = iTmpName2; |
|
2513 |
current.Copy(CurrentEntry().iName); |
|
2514 |
User::LeaveIfError(ShrinkNames(iFs, srcName, current, ETrue)); |
|
2515 |
} |
|
2516 |
else |
|
2517 |
{ |
|
2518 |
srcName.Append(CurrentEntry().iName); |
|
2519 |
} |
|
2520 |
||
2521 |
if ((CurrentEntry().iAtt&KEntryAttDir)==0) |
|
2522 |
User::LeaveIfError(iFs.Delete(srcName)); |
|
2523 |
else |
|
2524 |
{ |
|
2525 |
srcName.Append(KPathDelimiter); |
|
2526 |
User::LeaveIfError(iFs.RmDir(srcName)); |
|
2527 |
} |
|
2528 |
} |
|
2529 |
||
2530 |
||
2531 |
void CFileMan::CompleteOperationL() |
|
2532 |
// |
|
2533 |
// Tidy up after an operation |
|
2534 |
// The last step to remove directory or to a move directory operation |
|
2535 |
// is to remove the source directory... |
|
2536 |
// |
|
2537 |
{ |
|
2538 |
TInt r=KErrNotFound; |
|
2539 |
if (iAction == EInternalRmDir || |
|
2540 |
(iAction == EInternalCopyForMove && ((iMatchEntry & KMovingFilesMask) != KMovingFilesMask) && !iMovingContents && !iSrcFile.IsRoot()) || |
|
2541 |
iAction == EInternalRenameForMove && !iMovingContents && iNumberOfFilesProcessed) |
|
2542 |
{ |
|
2543 |
r=iFs.RmDir(iSrcFile.FullName()); |
|
2544 |
if ((r!=KErrNone && r!=KErrNotFound && iAction!=EInternalRenameForMove && r!=KErrInUse) || (iAction == EInternalRmDir && r == KErrInUse)) |
|
2545 |
{ |
|
2546 |
iLastError=r; |
|
2547 |
User::Leave(r); |
|
2548 |
} |
|
2549 |
} |
|
2550 |
||
2551 |
if (iLastError == KErrCancel && iNumberOfFilesProcessed==0 ) |
|
2552 |
{ |
|
2553 |
iLastError=KErrCancel; |
|
2554 |
iErrorInfo=ENoFilesProcessed; |
|
2555 |
User::Leave(KErrCancel); |
|
2556 |
} |
|
2557 |
||
2558 |
if (iLastError==KErrNone && r==KErrNotFound && iNumberOfFilesProcessed==0) |
|
2559 |
{ |
|
2560 |
iLastError=KErrNotFound; |
|
2561 |
iErrorInfo=ENoFilesProcessed; |
|
2562 |
User::Leave(KErrNotFound); |
|
2563 |
} |
|
2564 |
} |
|
2565 |
||
2566 |
void CFileMan::SetFlags(TBool anOverWrite,TBool aRecurse,TBool aScanDownTree,TBool aMoveRename) |
|
2567 |
// |
|
2568 |
// Set or clear flags |
|
2569 |
// |
|
2570 |
{ |
|
2571 |
||
2572 |
iSwitches=0; |
|
2573 |
if (aRecurse) |
|
2574 |
iSwitches|=KRecurseFlag; |
|
2575 |
if (anOverWrite) |
|
2576 |
iSwitches|=KOverWriteFlag; |
|
2577 |
if (aScanDownTree) |
|
2578 |
iSwitches|=KScanDownFlag; |
|
2579 |
if (aMoveRename) |
|
2580 |
iSwitches|=KMoveRenameFlag; |
|
2581 |
} |
|
2582 |
||
2583 |
||
2584 |
EXPORT_C TInt CFileMan::Copy(const RFile& anOld, const TDesC& aNew, TUint aSwitches) |
|
2585 |
/** |
|
2586 |
Copies from an open file handle to a destination file name. |
|
2587 |
||
2588 |
This is a synchronous function. |
|
2589 |
||
2590 |
Optionally, this function can be set to overwrite the target file. |
|
2591 |
If the flag is set for no overwriting and the target file already exists, |
|
2592 |
then the target file will not be overwritten, and an error (KErrAlreadyExists) |
|
2593 |
will be returned. |
|
2594 |
Error codes may be retrieved using CFileBase::GetLastError(). |
|
2595 |
||
2596 |
Notes: |
|
2597 |
||
2598 |
-# The file can be copied across drives. |
|
2599 |
-# Read-only, hidden and system files can be copied and |
|
2600 |
the source file's attributes are preserved in the target file. |
|
2601 |
||
2602 |
@param anOld Open file handle indicating the file to be copied. |
|
2603 |
@param aNew Path indicating the directory (and optionally the filename) |
|
2604 |
into which the file is to be copied. |
|
2605 |
Any path components which are not specified here will be |
|
2606 |
taken from the session path |
|
2607 |
@param aSwitches Specify zero for no overwriting; |
|
2608 |
CFileMan::EOverWrite to overwrite files with the same name; |
|
2609 |
Any other flags are illegal |
|
2610 |
By default, the synchronous variant of this function operates |
|
2611 |
with overwriting. |
|
2612 |
||
2613 |
@return KErrNone if successful, otherwise one of the other system-wide error codes. |
|
2614 |
||
2615 |
@see CFileBase::GetLastError() |
|
2616 |
@see CFileMan::Move() |
|
2617 |
||
2618 |
@capability Dependent If the path for aNew begins with /Sys then Tcb capability is required. |
|
2619 |
@capability Dependent If the path for aNew begins with /Private and does not match |
|
2620 |
this process' SID then AllFiles capability is required. |
|
2621 |
@capability Dependent If the path for aNew begins with /Resource then Tcb capability is required. |
|
2622 |
*/ |
|
2623 |
{ |
|
257 | 2624 |
TRACEMULT4(UTF::EBorder, UTraceModuleEfsrv::ECFileManCopy3, MODULEUID, |
2625 |
(TUint) this, anOld.SubSessionHandle(), aNew, aSwitches); |
|
0 | 2626 |
|
2627 |
TInt ret; |
|
2628 |
if (iSwitches&KFManBusyFlag) |
|
2629 |
{ |
|
2630 |
ret = KErrInUse; |
|
2631 |
} |
|
2632 |
// The only switch that is legal for single file copies is EOverWrite |
|
2633 |
else if ((aSwitches & ~EOverWrite) != 0) |
|
2634 |
{ |
|
2635 |
ret = KErrArgument; |
|
2636 |
} |
|
2637 |
else |
|
2638 |
{ |
|
2639 |
||
2640 |
SetFlags(aSwitches & EOverWrite, EFalse, EFalse, EFalse); |
|
2641 |
||
2642 |
// need to signal to CFileBase that we're copying from a handle |
|
2643 |
// and that iSrcFile is invalid |
|
2644 |
iSwitches|= KCopyFromHandle; |
|
2645 |
||
2646 |
TInt r; |
|
257 | 2647 |
RETURNIFERROR(r, iFs.Parse(aNew, iTrgFile),UTraceModuleEfsrv::ECFileManCopy3Return); |
0 | 2648 |
|
2649 |
// Need to duplicate the RFile handle so that any threads owned |
|
2650 |
// by this process can use it - i.e. the worker thread |
|
257 | 2651 |
RETURNIFERROR(r, iSrcFileHandle.Duplicate(anOld, EOwnerProcess),UTraceModuleEfsrv::ECFileManCopy3Return); |
0 | 2652 |
|
2653 |
iAction = EInternalCopyFromHandle; |
|
2654 |
iNumberOfFilesProcessed = 0; |
|
2655 |
TRAP(r,RunL()); |
|
2656 |
ret=(r==KErrNone) ? iLastError : r; |
|
2657 |
DoSynchronize(r); |
|
2658 |
} |
|
2659 |
||
257 | 2660 |
TRACERET1(UTF::EBorder, UTraceModuleEfsrv::ECFileManCopy3Return, MODULEUID, ret); |
0 | 2661 |
return(ret); |
2662 |
} |
|
2663 |
||
2664 |
EXPORT_C TInt CFileMan::Copy(const RFile& anOld,const TDesC& aNew,TUint aSwitches,TRequestStatus& aStatus) |
|
2665 |
/** |
|
2666 |
Copies from an open file handle to a destination file name. |
|
2667 |
||
2668 |
This is an asynchronous function. |
|
2669 |
Its behaviour is the same as the synchronous overload. |
|
2670 |
||
2671 |
@param anOld Open file handle indicating the file to be copied. |
|
2672 |
@param aNew Path indicating the directory (and optionally the filename) |
|
2673 |
into which the file is to be copied. |
|
2674 |
Any path components which are not specified here will be |
|
2675 |
taken from the session path |
|
2676 |
@param aSwitches Specify zero for no overwriting; |
|
2677 |
CFileMan::EOverWrite to overwrite files with the same name; |
|
2678 |
Any other flags are illegal. |
|
2679 |
||
2680 |
@param aStatus The request status object. On request completion, |
|
2681 |
indicates how the request completed: |
|
2682 |
KErrNone, if successful, otherwise one of the other system-wide error |
|
2683 |
codes. |
|
2684 |
||
2685 |
@return KErrNone if the asynchronous request is made successfully; KErrInUse if an asynchronous request |
|
2686 |
is still pending; otherwise one of the other system-wide error codes |
|
2687 |
||
2688 |
@see CFileBase::GetLastError() |
|
2689 |
||
2690 |
@capability Dependent If the path for aNew begins with /Sys then Tcb capability is required. |
|
2691 |
@capability Dependent If the path for aNew begins with /Private and does not match |
|
2692 |
this process' SID then AllFiles capability is required. |
|
2693 |
@capability Dependent If the path for aNew begins with /Resource then Tcb capability is required. |
|
2694 |
*/ |
|
2695 |
{ |
|
257 | 2696 |
TRACEMULT5(UTF::EBorder, UTraceModuleEfsrv::ECFileManCopy4, MODULEUID, |
2697 |
(TUint) this, anOld.SubSessionHandle(), aNew, aSwitches, (TUint) &aStatus); |
|
0 | 2698 |
|
2699 |
TInt r; |
|
2700 |
if (iSwitches&KFManBusyFlag) |
|
2701 |
{ |
|
2702 |
r = KErrInUse; |
|
2703 |
} |
|
2704 |
else |
|
2705 |
{ |
|
2706 |
iStatus=&aStatus; |
|
2707 |
r = Copy(anOld,aNew,aSwitches); |
|
2708 |
} |
|
2709 |
||
257 | 2710 |
TRACERET1(UTF::EBorder, UTraceModuleEfsrv::ECFileManCopy4Return, MODULEUID, r); |
0 | 2711 |
return(r); |
2712 |
} |
|
2713 |
||
2714 |
void CFileMan::DoCopyFromHandleL() |
|
2715 |
// |
|
2716 |
// Copy from open file handle |
|
2717 |
// |
|
2718 |
{ |
|
2719 |
TInt ret=0; |
|
2720 |
TFileName& trgName = iTmpName1; |
|
2721 |
||
2722 |
if (iTrgFile.NamePresent()) |
|
2723 |
{ |
|
2724 |
trgName = iTrgFile.FullName(); |
|
2725 |
} |
|
2726 |
else |
|
2727 |
{ |
|
2728 |
iSrcFileHandle.Name(trgName); |
|
2729 |
if ((trgName.Length() + iTrgFile.DriveAndPath().Length()) > KMaxFileName) |
|
2730 |
{ |
|
2731 |
iSrcFileHandle.Close(); |
|
2732 |
User::Leave(KErrBadName); |
|
2733 |
} |
|
2734 |
trgName.Insert(0, iTrgFile.DriveAndPath()); |
|
2735 |
} |
|
2736 |
||
2737 |
#ifndef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
2738 |
RFile trgFile; |
|
2739 |
#else |
|
2740 |
RFile64 trgFile; |
|
2741 |
#endif |
|
2742 |
TInt r=KErrNone; |
|
2743 |
||
2744 |
if ((iSwitches&KOverWriteFlag)==0) |
|
2745 |
r=trgFile.Create(iFs,trgName,EFileWrite|EFileWriteDirectIO|EFileShareExclusive); |
|
2746 |
else |
|
2747 |
r=trgFile.Replace(iFs,trgName,EFileWrite|EFileWriteDirectIO|EFileShareExclusive); |
|
2748 |
if (r!=KErrNone) |
|
2749 |
iErrorInfo = ETrgOpenFailed; |
|
2750 |
||
2751 |
if (r == KErrNone) |
|
2752 |
r = DoCopy(iSrcFileHandle, trgFile, ret); |
|
2753 |
||
2754 |
// close the (duplicated) source file handle |
|
2755 |
iSrcFileHandle.Close(); |
|
2756 |
||
2757 |
trgFile.Close(); |
|
2758 |
if (ret == MFileManObserver::ECancel || (r!=KErrNone && r!=KErrAlreadyExists && iErrorInfo!=ETrgOpenFailed)) |
|
2759 |
iFs.Delete(trgName); |
|
2760 |
User::LeaveIfError(r); |
|
2761 |
} |
|
2762 |
||
2763 |
#ifndef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
2764 |
TInt CFileMan::DoCopy(const RFile& aSrcFile, RFile& aDstFile, TInt& aRet) |
|
2765 |
{ |
|
2766 |
TInt rem; |
|
2767 |
#else |
|
2768 |
TInt CFileMan::DoCopy(const RFile64& aSrcFile, RFile64& aDstFile, TInt& aRet) |
|
2769 |
{ |
|
2770 |
TInt64 rem; |
|
2771 |
#endif |
|
257 | 2772 |
RETURNIFERRORD(r,aSrcFile.Size(rem),EFalse); |
2773 |
RETURNIFERROR(r, aDstFile.SetSize(rem),EFalse); |
|
0 | 2774 |
|
2775 |
HBufC8* bufPtr = NULL; |
|
2776 |
bufPtr = AllocateBuffer(rem); |
|
2777 |
if (bufPtr == NULL) |
|
2778 |
return KErrNoMemory; |
|
2779 |
TPtr8 copyBuf=bufPtr->Des(); |
|
2780 |
||
2781 |
#ifndef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
2782 |
TInt pos=0; |
|
2783 |
#else |
|
2784 |
TInt64 pos=0; |
|
2785 |
#endif |
|
2786 |
aRet = MFileManObserver::EContinue; |
|
2787 |
while(rem && aRet == MFileManObserver::EContinue) |
|
2788 |
{ |
|
2789 |
#ifndef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
2790 |
TInt s=Min(rem,copyBuf.MaxSize()); |
|
2791 |
#else |
|
2792 |
// Min result shall be of TInt size |
|
2793 |
TInt s=(TInt)(Min(rem,(TInt64)copyBuf.MaxSize())); |
|
2794 |
#endif |
|
2795 |
r=aSrcFile.Read(pos,copyBuf,s); |
|
2796 |
if (r==KErrNone && copyBuf.Length()!=s) |
|
2797 |
r = KErrCorrupt; |
|
2798 |
if (r==KErrNone) |
|
2799 |
r=aDstFile.Write(pos,copyBuf,s); |
|
2800 |
if (r!=KErrNone) |
|
2801 |
break; |
|
2802 |
pos+= s; |
|
2803 |
rem-= s; |
|
2804 |
iBytesTransferred = s; |
|
2805 |
aRet = (iObserver) ? iObserver->NotifyFileManOperation() : MFileManObserver::EContinue; |
|
2806 |
if (aRet != MFileManObserver::EContinue && aRet != MFileManObserver::ECancel) |
|
2807 |
Panic(EFManBadValueFromObserver); |
|
2808 |
} |
|
2809 |
||
2810 |
// need to flush the target file - otherwise if there is any dirty data this will be flushed |
|
2811 |
// when the file is closed and this will set the archive attribute, resulting in the file |
|
2812 |
// having potentially a different attribute from the source file |
|
2813 |
if (r == KErrNone) |
|
2814 |
r = aDstFile.Flush(); |
|
2815 |
||
2816 |
if (aRet != MFileManObserver::ECancel) |
|
2817 |
{ |
|
2818 |
TTime lastMod; |
|
2819 |
if (r == KErrNone) |
|
2820 |
r = aSrcFile.Modified(lastMod); |
|
2821 |
if (r == KErrNone) |
|
2822 |
r = aDstFile.SetModified(lastMod); |
|
2823 |
||
2824 |
TUint fileAttributes=0; |
|
2825 |
if (r == KErrNone) |
|
2826 |
r = aSrcFile.Att(fileAttributes); |
|
2827 |
if (r == KErrNone) |
|
2828 |
r = aDstFile.SetAtt(fileAttributes,(~fileAttributes)&KEntryAttMaskSupported); |
|
2829 |
||
2830 |
if(r == KErrNone) |
|
2831 |
r = aDstFile.Flush(); |
|
2832 |
} |
|
2833 |
||
2834 |
delete bufPtr; |
|
2835 |
||
2836 |
return r; |
|
2837 |
} |