923 |
923 |
924 // Move file to the actual drive and directory |
924 // Move file to the actual drive and directory |
925 // as well rename the file with the correct file name instead of temporary name |
925 // as well rename the file with the correct file name instead of temporary name |
926 // tempFullName will be updated in RenameFileL() |
926 // tempFullName will be updated in RenameFileL() |
927 TInt error = RenameFileL(tempFullName, filename, parse.DriveAndPath(), fsSess); |
927 TInt error = RenameFileL(tempFullName, filename, parse.DriveAndPath(), fsSess); |
928 |
|
929 |
|
930 |
928 |
931 if ( error != KErrNone ) |
929 if ( error != KErrNone ) |
932 { |
930 { |
933 fsSess.Delete(tempFullName); // If rename fails, we remove the temp RFile object. |
931 fsSess.Delete(tempFullName); // If rename fails, we remove the temp RFile object. |
934 } |
932 } |
1426 TFileName& aFileName, |
1424 TFileName& aFileName, |
1427 TFileName& aNewFileName, |
1425 TFileName& aNewFileName, |
1428 const TDesC& aNewPath, |
1426 const TDesC& aNewPath, |
1429 RFs& aFileSession) |
1427 RFs& aFileSession) |
1430 { |
1428 { |
|
1429 |
1431 // We move the file to the final location |
1430 // We move the file to the final location |
1432 // |
1431 // |
1433 CFileMan* fileMan= CFileMan::NewL(aFileSession); |
1432 CFileMan* fileMan= CFileMan::NewL(aFileSession); |
1434 CleanupStack::PushL(fileMan); |
1433 CleanupStack::PushL(fileMan); |
1435 |
1434 TPtrC tmpNewPath; |
1436 fileMan->Move(aFileName,aNewPath,CFileMan::ERecurse ); |
|
1437 CleanupStack::PopAndDestroy(fileMan); |
|
1438 |
|
1439 TParse fileParse; |
1435 TParse fileParse; |
1440 fileParse.Set(aFileName, NULL, NULL); |
1436 fileParse.Set(aFileName, NULL, NULL); |
1441 |
1437 |
|
1438 TInt error = fileMan->Move(aFileName,aNewPath,CFileMan::ERecurse ); |
|
1439 |
|
1440 // if error while moving to new location, keep file in old location and change file name |
|
1441 if (error != KErrNone) |
|
1442 { |
|
1443 tmpNewPath.Set (fileParse.DriveAndPath()); |
|
1444 } |
|
1445 else |
|
1446 { |
|
1447 tmpNewPath.Set (aNewPath); |
|
1448 } |
|
1449 |
|
1450 CleanupStack::PopAndDestroy(fileMan); |
|
1451 |
1442 TFileName tempFile; |
1452 TFileName tempFile; |
1443 tempFile.Append(aNewPath); |
1453 tempFile.Append(tmpNewPath); |
1444 tempFile.Append(fileParse.NameAndExt()); |
1454 tempFile.Append(fileParse.NameAndExt()); |
1445 aFileName = tempFile; |
1455 aFileName = tempFile; |
1446 |
1456 |
1447 // check the duplicated file name. if so, we renamed in a different way. |
1457 // check the duplicated file name. if so, we renamed in a different way. |
1448 TInt segmentNum = 0; |
1458 TInt segmentNum = 0; |
1449 TBuf<64> segmentString; |
1459 TBuf<64> segmentString; |
1450 |
1460 |
1451 TFileName newFullName; |
1461 TFileName newFullName; |
1452 newFullName.Zero(); |
1462 newFullName.Zero(); |
1453 newFullName.Append(aNewPath); |
1463 newFullName.Append(tmpNewPath); |
1454 newFullName.Append(aNewFileName); |
1464 newFullName.Append(aNewFileName); |
1455 |
1465 |
1456 aFileSession.SetSessionPath(aNewPath); |
1466 aFileSession.SetSessionPath(tmpNewPath); |
1457 |
1467 |
1458 while ( BaflUtils::FileExists(aFileSession, newFullName) ) |
1468 while ( BaflUtils::FileExists(aFileSession, newFullName) ) |
1459 { |
1469 { |
1460 segmentNum++; |
1470 segmentNum++; |
1461 User::LeaveIfError( RenameFileWithSegmentNumL(aNewFileName, segmentNum, segmentString) ); |
1471 User::LeaveIfError( RenameFileWithSegmentNumL(aNewFileName, segmentNum, segmentString) ); |
1462 newFullName.Zero(); |
1472 newFullName.Zero(); |
1463 newFullName.Append(aNewPath); |
1473 newFullName.Append(tmpNewPath); |
1464 newFullName.Append(aNewFileName); |
1474 newFullName.Append(aNewFileName); |
1465 } |
1475 } |
1466 // rename the file. |
1476 // rename the file. |
1467 // |
1477 // |
1468 TInt error = aFileSession.Rename(aFileName, newFullName); |
1478 error = aFileSession.Rename(aFileName, newFullName); |
|
1479 |
1469 aFileName = newFullName; |
1480 aFileName = newFullName; |
1470 |
1481 |
1471 return error; |
1482 return error; |
1472 } |
1483 } |
1473 |
1484 |