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