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