mtpfws/mtpfw/dataproviders/dputility/src/cmtpcopyobject.cpp
changeset 47 63cf70d3ecd8
parent 33 883e91c086aa
child 60 841f70763fbe
equal deleted inserted replaced
44:a5deb6b96675 47:63cf70d3ecd8
    25 
    25 
    26 #include "cmtpfsentrycache.h"
    26 #include "cmtpfsentrycache.h"
    27 #include "cmtpstoragemgr.h"
    27 #include "cmtpstoragemgr.h"
    28 #include "cmtpcopyobject.h"
    28 #include "cmtpcopyobject.h"
    29 #include "mtpdppanic.h"
    29 #include "mtpdppanic.h"
    30 
    30 #include "mtpdebug.h"
    31 __FLOG_STMT(_LIT8(KComponent,"CopyObject");)
    31 #include "OstTraceDefinitions.h"
       
    32 #ifdef OST_TRACE_COMPILER_IN_USE
       
    33 #include "cmtpcopyobjectTraces.h"
       
    34 #endif
       
    35 
    32 
    36 
    33 /**
    37 /**
    34 Verification data for the CopyObject request
    38 Verification data for the CopyObject request
    35 */
    39 */
    36 const TMTPRequestElementInfo KMTPCopyObjectPolicy[] = 
    40 const TMTPRequestElementInfo KMTPCopyObjectPolicy[] = 
    60 /**
    64 /**
    61 Destructor
    65 Destructor
    62 */	
    66 */	
    63 EXPORT_C CMTPCopyObject::~CMTPCopyObject()
    67 EXPORT_C CMTPCopyObject::~CMTPCopyObject()
    64 	{	
    68 	{	
    65 	__FLOG(_L8("~CMTPCopyObject - Entry"));
    69 	OstTraceFunctionEntry0( CMTPCOPYOBJECT_CMTPCOPYOBJECT_DES_ENTRY );
    66 	Cancel();
    70 	Cancel();
    67 	iDpSingletons.Close();
    71 	iDpSingletons.Close();
    68 	iSingletons.Close();
    72 	iSingletons.Close();
    69 	
    73 	
    70 	delete iTimer;
    74 	delete iTimer;
    71 	delete iDest;
    75 	delete iDest;
    72 	delete iNewFileName;
    76 	delete iNewFileName;
    73 	delete iFileMan;
    77 	delete iFileMan;
    74 	
    78 
    75 	__FLOG(_L8("~CMTPCopyObject - Exit"));
    79 	OstTraceFunctionExit0( CMTPCOPYOBJECT_CMTPCOPYOBJECT_DES_EXIT );
    76 	__FLOG_CLOSE;
       
    77 	}
    80 	}
    78 
    81 
    79 /**
    82 /**
    80 Standard c++ constructor
    83 Standard c++ constructor
    81 */	
    84 */	
    82 CMTPCopyObject::CMTPCopyObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) :
    85 CMTPCopyObject::CMTPCopyObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) :
    83 	CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPCopyObjectPolicy)/sizeof(TMTPRequestElementInfo), KMTPCopyObjectPolicy),
    86 	CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPCopyObjectPolicy)/sizeof(TMTPRequestElementInfo), KMTPCopyObjectPolicy),
    84 	iTimer(NULL)
    87 	iTimer(NULL)
    85 	{
    88 	{
    86 	__FLOG_OPEN(KMTPSubsystem, KComponent);
       
    87 	}
    89 	}
    88 
    90 
    89 
    91 
    90 
    92 
    91 TMTPResponseCode CMTPCopyObject::CheckRequestL()
    93 TMTPResponseCode CMTPCopyObject::CheckRequestL()
    92 	{
    94 	{
    93 	__FLOG(_L8("CheckRequestL - Entry"));
    95 	OstTraceFunctionEntry0( CMTPCOPYOBJECT_CHECKREQUESTL_ENTRY );
    94 	TMTPResponseCode result = CMTPRequestProcessor::CheckRequestL();
    96 	TMTPResponseCode result = CMTPRequestProcessor::CheckRequestL();
    95 	if ( (EMTPRespCodeOK == result) && (!iSingletons.StorageMgr().IsReadWriteStorage(Request().Uint32(TMTPTypeRequest::ERequestParameter2))) )
    97 	if ( (EMTPRespCodeOK == result) && (!iSingletons.StorageMgr().IsReadWriteStorage(Request().Uint32(TMTPTypeRequest::ERequestParameter2))) )
    96 		{
    98 		{
    97 		result = EMTPRespCodeStoreReadOnly;
    99 		result = EMTPRespCodeStoreReadOnly;
    98 		}
   100 		}
   102 		CMTPObjectMetaData* object(CMTPObjectMetaData::NewLC());
   104 		CMTPObjectMetaData* object(CMTPObjectMetaData::NewLC());
   103 		if(iFramework.ObjectMgr().ObjectL(KHandle, *object))
   105 		if(iFramework.ObjectMgr().ObjectL(KHandle, *object))
   104 			{
   106 			{
   105 			const TDesC& suid(object->DesC(CMTPObjectMetaData::ESuid));
   107 			const TDesC& suid(object->DesC(CMTPObjectMetaData::ESuid));
   106 			iIsFolder = EFalse;
   108 			iIsFolder = EFalse;
   107 			User::LeaveIfError(BaflUtils::IsFolder(iFramework.Fs(), suid, iIsFolder));
   109 			LEAVEIFERROR(BaflUtils::IsFolder(iFramework.Fs(), suid, iIsFolder),
       
   110 			        OstTraceExt1( TRACE_ERROR, DUP1_CMTPCOPYOBJECT_CHECKREQUESTL, "can't judge whether %S is a folder", suid ));
   108 			if(!iIsFolder)
   111 			if(!iIsFolder)
   109 				{
   112 				{
   110 				if(iDpSingletons.CopyingBigFileCache().IsOnGoing())
   113 				if(iDpSingletons.CopyingBigFileCache().IsOnGoing())
   111 					{
   114 					{
   112 					__FLOG(_L8("CheckRequestL - A big file copying is ongoing, respond with access denied"));
   115 					OstTrace0( TRACE_NORMAL, CMTPCOPYOBJECT_CHECKREQUESTL, 
       
   116 					        "CheckRequestL - A big file copying is ongoing, respond with access denied" );				
   113 					result = EMTPRespCodeAccessDenied;
   117 					result = EMTPRespCodeAccessDenied;
   114 					}
   118 					}
   115 				}
   119 				}
   116 			}
   120 			}
   117 		CleanupStack::PopAndDestroy(object); 
   121 		CleanupStack::PopAndDestroy(object); 
   118 		}
   122 		}
   119 	__FLOG(_L8("CheckRequestL - Exit"));
   123 	OstTraceFunctionExit0( CMTPCOPYOBJECT_CHECKREQUESTL_EXIT );
   120 	return result;	
   124 	return result;	
   121 	} 
   125 	} 
   122 
   126 
   123 /**
   127 /**
   124 CopyObject request handler
   128 CopyObject request handler
   125 */		
   129 */		
   126 void CMTPCopyObject::ServiceL()
   130 void CMTPCopyObject::ServiceL()
   127 	{	
   131 	{	
   128 	__FLOG(_L8("ServiceL - Entry"));
   132 	OstTraceFunctionEntry0( CMTPCOPYOBJECT_SERVICEL_ENTRY );
   129 	TUint32 handle = KMTPHandleNone;
   133 	TUint32 handle = KMTPHandleNone;
   130 	TMTPResponseCode responseCode = EMTPRespCodeOK;
   134 	TMTPResponseCode responseCode = EMTPRespCodeOK;
   131 	TRAPD(err, responseCode = CopyObjectL(handle));
   135 	TRAPD(err, responseCode = CopyObjectL(handle));
   132 	if(err != KErrNone)
   136 	if(err != KErrNone)
   133 		{
   137 		{
   134 		SendResponseL(EMTPRespCodeAccessDenied);
   138 		SendResponseL(EMTPRespCodeAccessDenied);
   135 		}
   139 		}
   136 	else if(responseCode != EMTPRespCodeOK)
   140 	else if(responseCode != EMTPRespCodeOK)
   137 		{
   141 		{
   138 		__FLOG_VA((_L8("ServiceL, sending response with respond code %d"), responseCode));
   142 		OstTrace1( TRACE_NORMAL, CMTPCOPYOBJECT_SERVICEL, "ServiceL, sending response with respond code %d", responseCode );
   139 		SendResponseL(responseCode);
   143 		SendResponseL(responseCode);
   140 		}
   144 		}
   141 	else if (iIsFolder)
   145 	else if (iIsFolder)
   142 		{
   146 		{
   143 		__FLOG_VA((_L8("ServiceL, sending response with handle=%d, respond code OK"), handle));
   147 		OstTrace1( TRACE_NORMAL, DUP1_CMTPCOPYOBJECT_SERVICEL, "ServiceL, sending response with handle=%d, respond code OK", handle );
   144 		SendResponseL(EMTPRespCodeOK, 1, &handle);
   148 		SendResponseL(EMTPRespCodeOK, 1, &handle);
   145 		}
   149 		}
   146 	__FLOG(_L8("ServiceL - Exit"));
   150 	OstTraceFunctionExit0( CMTPCOPYOBJECT_SERVICEL_EXIT );
   147 	}
   151 	}
   148 
   152 
   149 
   153 
   150 /**
   154 /**
   151  Second phase constructor
   155  Second phase constructor
   152 */
   156 */
   153 void CMTPCopyObject::ConstructL()
   157 void CMTPCopyObject::ConstructL()
   154 	{
   158 	{
       
   159 	OstTraceFunctionEntry0( CMTPCOPYOBJECT_CONSTRUCTL_ENTRY );
   155 	iSingletons.OpenL();
   160 	iSingletons.OpenL();
   156 	iDpSingletons.OpenL(iFramework);
   161 	iDpSingletons.OpenL(iFramework);
       
   162 	OstTraceFunctionExit0( CMTPCOPYOBJECT_CONSTRUCTL_EXIT );
   157 	}
   163 	}
   158 
   164 
   159 	
   165 	
   160 /**
   166 /**
   161 A helper function of CopyObjectL.
   167 A helper function of CopyObjectL.
   162 @param aNewFileName the new full filename after copy.
   168 @param aNewFileName the new full filename after copy.
   163 @return objectHandle of new copy of object.
   169 @return objectHandle of new copy of object.
   164 */
   170 */
   165 void CMTPCopyObject::CopyFileL(const TDesC& aNewFileName)
   171 void CMTPCopyObject::CopyFileL(const TDesC& aNewFileName)
   166 	{
   172 	{
   167 	__FLOG(_L8("CopyFileL - Entry"));
   173 	OstTraceFunctionEntry0( CMTPCOPYOBJECT_COPYFILEL_ENTRY );
   168 	delete iNewFileName;
   174 	delete iNewFileName;
   169 	iNewFileName = NULL;
   175 	iNewFileName = NULL;
   170 	iNewFileName = aNewFileName.AllocL(); // Store the new file name	
   176 	iNewFileName = aNewFileName.AllocL(); // Store the new file name	
   171 	const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid));
   177 	const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid));
   172 	GetPreviousPropertiesL(suid);
   178 	GetPreviousPropertiesL(suid);
   173 	
   179 	
   174 	User::LeaveIfError(iFileMan->Copy(suid, *iDest, CFileMan::EOverWrite, iStatus));
   180 	LEAVEIFERROR(iFileMan->Copy(suid, *iDest, CFileMan::EOverWrite, iStatus),
       
   181 	        OstTraceExt2( TRACE_ERROR, CMTPCOPYOBJECT_COPYFILEL, "copy %S to %S failed!", suid, *iDest));
   175 	if ( !IsActive() )
   182 	if ( !IsActive() )
   176 	{  
   183 	{  
   177 	SetActive();
   184 	SetActive();
   178 	}
   185 	}
   179 	
   186 	
   180 	delete iTimer;
   187 	delete iTimer;
   181 	iTimer = NULL;
   188 	iTimer = NULL;
   182 	iTimer = CPeriodic::NewL(EPriorityStandard);
   189 	iTimer = CPeriodic::NewL(EPriorityStandard);
   183 	TTimeIntervalMicroSeconds32 KCopyObjectIntervalNone = 0;	
   190 	TTimeIntervalMicroSeconds32 KCopyObjectIntervalNone = 0;	
   184 	iTimer->Start(TTimeIntervalMicroSeconds32(KCopyObjectTimeOut), KCopyObjectIntervalNone, TCallBack(CMTPCopyObject::OnTimeoutL, this));
   191 	iTimer->Start(TTimeIntervalMicroSeconds32(KCopyObjectTimeOut), KCopyObjectIntervalNone, TCallBack(CMTPCopyObject::OnTimeoutL, this));
   185 	
   192 
   186 	__FLOG(_L8("CopyFileL - Exit"));
   193 	OstTraceFunctionExit0( CMTPCOPYOBJECT_COPYFILEL_EXIT );
   187 	}
   194 	}
   188 
   195 
   189 /**
   196 /**
   190 A helper function of CopyObjectL.
   197 A helper function of CopyObjectL.
   191 @param aNewFolderName the new full file folder name after copy.
   198 @param aNewFolderName the new full file folder name after copy.
   192 @return objecthandle of new copy of the folder.
   199 @return objecthandle of new copy of the folder.
   193 */
   200 */
   194 TUint32 CMTPCopyObject::CopyFolderL(const TDesC& aNewFolderName)
   201 TUint32 CMTPCopyObject::CopyFolderL(const TDesC& aNewFolderName)
   195 	{
   202 	{
   196 	__FLOG(_L8("CopyFolderL - Entry"));
   203 	OstTraceFunctionEntry0( CMTPCOPYOBJECT_COPYFOLDERL_ENTRY );
   197 	const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid));
   204 	const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid));
   198 	TUint32 handle;
   205 	TUint32 handle;
   199 	if (iObjectInfo->Uint(CMTPObjectMetaData::EDataProviderId) == iFramework.DataProviderId())
   206 	if (iObjectInfo->Uint(CMTPObjectMetaData::EDataProviderId) == iFramework.DataProviderId())
   200 		{
   207 		{
   201 		GetPreviousPropertiesL(suid);
   208 		GetPreviousPropertiesL(suid);
   202 		User::LeaveIfError(iFramework.Fs().MkDir(aNewFolderName));
   209 		LEAVEIFERROR(iFramework.Fs().MkDir(aNewFolderName),
       
   210 		        OstTraceExt1( TRACE_ERROR, CMTPCOPYOBJECT_COPYFOLDERL, "create directory %S failed!", aNewFolderName));
   203 		SetPreviousPropertiesL(aNewFolderName);	
   211 		SetPreviousPropertiesL(aNewFolderName);	
   204 		handle = UpdateObjectInfoL(aNewFolderName);
   212 		handle = UpdateObjectInfoL(aNewFolderName);
   205 		}
   213 		}
   206 	else
   214 	else
   207 		{
   215 		{
   208 		handle = iFramework.ObjectMgr().HandleL(aNewFolderName);
   216 		handle = iFramework.ObjectMgr().HandleL(aNewFolderName);
   209 		}
   217 		}
   210 	__FLOG(_L8("CopyFolderL - Exit"));
   218 	OstTraceFunctionExit0( CMTPCOPYOBJECT_COPYFOLDERL_EXIT );
   211 	return handle;
   219 	return handle;
   212 	}
   220 	}
   213 		
   221 		
   214 /**
   222 /**
   215 Copy object operation
   223 Copy object operation
   216 @return the object handle of the resulting object.
   224 @return the object handle of the resulting object.
   217 */
   225 */
   218 TMTPResponseCode CMTPCopyObject::CopyObjectL(TUint32& aNewHandle)
   226 TMTPResponseCode CMTPCopyObject::CopyObjectL(TUint32& aNewHandle)
   219 	{
   227 	{
   220 	__FLOG(_L8("CopyObjectL - Entry"));
   228 	OstTraceFunctionEntry0( CMTPCOPYOBJECT_COPYOBJECTL_ENTRY );
   221 	TMTPResponseCode responseCode = EMTPRespCodeOK;
   229 	TMTPResponseCode responseCode = EMTPRespCodeOK;
   222 	aNewHandle = KMTPHandleNone;
   230 	aNewHandle = KMTPHandleNone;
   223 	
   231 	
   224 	GetParametersL();
   232 	GetParametersL();
   225 			
   233 			
   239 			}
   247 			}
   240 		}
   248 		}
   241 	else // It is a folder.
   249 	else // It is a folder.
   242 		{
   250 		{
   243 		TFileName rightMostFolderName;
   251 		TFileName rightMostFolderName;
   244 		User::LeaveIfError(BaflUtils::MostSignificantPartOfFullName(suid, rightMostFolderName));
   252 		LEAVEIFERROR(BaflUtils::MostSignificantPartOfFullName(suid, rightMostFolderName),
       
   253 		        OstTraceExt1( TRACE_ERROR, CMTPCOPYOBJECT_COPYOBJECTL, "can't extract most significant part from %S", suid));    
   245 		if((newObjectName.Length() + rightMostFolderName.Length() + 1) <= newObjectName.MaxLength())
   254 		if((newObjectName.Length() + rightMostFolderName.Length() + 1) <= newObjectName.MaxLength())
   246 			{
   255 			{
   247 			newObjectName.Append(rightMostFolderName);
   256 			newObjectName.Append(rightMostFolderName);
   248 			// Add backslash.
   257 			// Add backslash.
   249 			_LIT(KBackSlash, "\\");
   258 			_LIT(KBackSlash, "\\");
   266 			aNewHandle = CopyFolderL(newObjectName);
   275 			aNewHandle = CopyFolderL(newObjectName);
   267 			}
   276 			}
   268 		}
   277 		}
   269 	
   278 	
   270 	CleanupStack::PopAndDestroy(); // newObjectName.
   279 	CleanupStack::PopAndDestroy(); // newObjectName.
   271 	__FLOG(_L8("CopyObjectL - Exit"));
   280 	OstTraceFunctionExit0( CMTPCOPYOBJECT_COPYOBJECTL_EXIT );
   272 	return responseCode;
   281 	return responseCode;
   273 	}
   282 	}
   274 
   283 
   275 /**
   284 /**
   276 Retrieve the parameters of the request
   285 Retrieve the parameters of the request
   277 */	
   286 */	
   278 void CMTPCopyObject::GetParametersL()
   287 void CMTPCopyObject::GetParametersL()
   279 	{
   288 	{
   280 	__FLOG(_L8("GetParametersL - Entry"));
   289 	OstTraceFunctionEntry0( CMTPCOPYOBJECT_GETPARAMETERSL_ENTRY );
   281 	__ASSERT_DEBUG(iRequestChecker, Panic(EMTPDpRequestCheckNull));
   290 	__ASSERT_DEBUG(iRequestChecker, Panic(EMTPDpRequestCheckNull));
   282 	
   291 	
   283 	TUint32 objectHandle  = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
   292 	TUint32 objectHandle  = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
   284 	iStorageId = Request().Uint32(TMTPTypeRequest::ERequestParameter2);
   293 	iStorageId = Request().Uint32(TMTPTypeRequest::ERequestParameter2);
   285 	TUint32 parentObjectHandle  = Request().Uint32(TMTPTypeRequest::ERequestParameter3);
   294 	TUint32 parentObjectHandle  = Request().Uint32(TMTPTypeRequest::ERequestParameter3);
   299 		delete iDest;
   308 		delete iDest;
   300 		iDest = NULL;
   309 		iDest = NULL;
   301 		iDest = parentObjectInfo->DesC(CMTPObjectMetaData::ESuid).AllocL();
   310 		iDest = parentObjectInfo->DesC(CMTPObjectMetaData::ESuid).AllocL();
   302 		iNewParentHandle = parentObjectHandle;
   311 		iNewParentHandle = parentObjectHandle;
   303 		}
   312 		}
   304 	__FLOG(_L8("GetParametersL - Exit"));	
   313 	OstTraceFunctionExit0( CMTPCOPYOBJECT_GETPARAMETERSL_EXIT );
   305 	}
   314 	}
   306 	
   315 	
   307 /**
   316 /**
   308 Get a default parent object, ff the request does not specify a parent object, 
   317 Get a default parent object, ff the request does not specify a parent object, 
   309 */
   318 */
   310 void CMTPCopyObject::SetDefaultParentObjectL()
   319 void CMTPCopyObject::SetDefaultParentObjectL()
   311 	{
   320 	{
   312 	__FLOG(_L8("SetDefaultParentObjectL - Entry"));
   321 	OstTraceFunctionEntry0( CMTPCOPYOBJECT_SETDEFAULTPARENTOBJECTL_ENTRY );
   313 
   322 
   314 	const CMTPStorageMetaData& storageMetaData( iFramework.StorageMgr().StorageL(iStorageId) );
   323 	const CMTPStorageMetaData& storageMetaData( iFramework.StorageMgr().StorageL(iStorageId) );
   315 	const TDesC& driveBuf( storageMetaData.DesC(CMTPStorageMetaData::EStorageSuid) );
   324 	const TDesC& driveBuf( storageMetaData.DesC(CMTPStorageMetaData::EStorageSuid) );
   316 	delete iDest;
   325 	delete iDest;
   317 	iDest = NULL;
   326 	iDest = NULL;
   318 	iDest = driveBuf.AllocL();
   327 	iDest = driveBuf.AllocL();
   319 	iNewParentHandle = KMTPHandleNoParent;
   328 	iNewParentHandle = KMTPHandleNoParent;
   320 	    
   329 	    
   321 	__FLOG(_L8("SetDefaultParentObjectL - Exit"));
   330 	OstTraceFunctionExit0( CMTPCOPYOBJECT_SETDEFAULTPARENTOBJECTL_EXIT );
   322 	}
   331 	}
   323 
   332 
   324 /**
   333 /**
   325 Check if we can copy the file to the new location
   334 Check if we can copy the file to the new location
   326 */
   335 */
   327 TMTPResponseCode CMTPCopyObject::CanCopyObjectL(const TDesC& aOldName, const TDesC& aNewName) const
   336 TMTPResponseCode CMTPCopyObject::CanCopyObjectL(const TDesC& aOldName, const TDesC& aNewName) const
   328 	{
   337 	{
   329 	__FLOG(_L8("CanCopyObjectL - Entry"));
   338 	OstTraceFunctionEntry0( CMTPCOPYOBJECT_CANCOPYOBJECTL_ENTRY );
   330 	TMTPResponseCode result = EMTPRespCodeOK;
   339 	TMTPResponseCode result = EMTPRespCodeOK;
   331 
   340 
   332 	TEntry fileEntry;
   341 	TEntry fileEntry;
   333 	User::LeaveIfError(iFramework.Fs().Entry(aOldName, fileEntry));
   342 	LEAVEIFERROR(iFramework.Fs().Entry(aOldName, fileEntry),
       
   343 	        OstTraceExt1( TRACE_ERROR, DUP1_CMTPCOPYOBJECT_CANCOPYOBJECTL, "Can't get entry details for %S", aOldName ));     
   334 	TInt drive(iFramework.StorageMgr().DriveNumber(iStorageId));
   344 	TInt drive(iFramework.StorageMgr().DriveNumber(iStorageId));
   335 	User::LeaveIfError(drive);
   345 	LEAVEIFERROR(drive,
       
   346 	        OstTraceExt2( TRACE_ERROR, DUP2_CMTPCOPYOBJECT_CANCOPYOBJECTL, 
       
   347 	                "Get driver number for storage %d failed! error code %d", iStorageId, drive));
       
   348 	        
   336 	TVolumeInfo volumeInfo;
   349 	TVolumeInfo volumeInfo;
   337 	User::LeaveIfError(iFramework.Fs().Volume(volumeInfo, drive));
   350 	LEAVEIFERROR(iFramework.Fs().Volume(volumeInfo, drive),
   338 	
   351 	        OstTrace1( TRACE_ERROR, DUP3_CMTPCOPYOBJECT_CANCOPYOBJECTL, "can't get volume information for driver %d", drive));
       
   352 
   339 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   353 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   340     if(volumeInfo.iFree < fileEntry.FileSize())
   354     if(volumeInfo.iFree < fileEntry.FileSize())
   341 #else
   355 #else
   342     if(volumeInfo.iFree < fileEntry.iSize)
   356     if(volumeInfo.iFree < fileEntry.iSize)
   343 #endif
   357 #endif
   346 		}
   360 		}
   347 	else if (BaflUtils::FileExists(iFramework.Fs(), aNewName))			
   361 	else if (BaflUtils::FileExists(iFramework.Fs(), aNewName))			
   348 		{
   362 		{
   349 		result = EMTPRespCodeInvalidParentObject;
   363 		result = EMTPRespCodeInvalidParentObject;
   350 		}
   364 		}
   351 	__FLOG_VA((_L8("CanCopyObjectL - Exit with response code 0x%04X"), result));
   365 	OstTrace1( TRACE_NORMAL, CMTPCOPYOBJECT_CANCOPYOBJECTL, "response code 0x%04X", result );	
       
   366 	OstTraceFunctionExit0( CMTPCOPYOBJECT_CANCOPYOBJECTL_EXIT );
   352 	return result;	
   367 	return result;	
   353 	}
   368 	}
   354 
   369 
   355 /**
   370 /**
   356 Save the object properties before doing the copy
   371 Save the object properties before doing the copy
   357 */
   372 */
   358 void CMTPCopyObject::GetPreviousPropertiesL(const TDesC& aFileName)
   373 void CMTPCopyObject::GetPreviousPropertiesL(const TDesC& aFileName)
   359 	{
   374 	{
   360 	__FLOG(_L8("GetPreviousPropertiesL - Entry"));
   375 	OstTraceFunctionEntry0( CMTPCOPYOBJECT_GETPREVIOUSPROPERTIESL_ENTRY );
   361 	User::LeaveIfError(iFramework.Fs().Modified(aFileName, iPreviousModifiedTime));
   376 	LEAVEIFERROR(iFramework.Fs().Modified(aFileName, iPreviousModifiedTime),
   362 	__FLOG(_L8("GetPreviousPropertiesL - Exit"));
   377 	        OstTraceExt1( TRACE_ERROR, CMTPCOPYOBJECT_GETPREVIOUSPROPERTIESL, "Can't get the last modification date and time for %S", aFileName));
       
   378 	if ( iIsFolder )
       
   379 	    {
       
   380         TEntry fileEntry;
       
   381         User::LeaveIfError(iFramework.Fs().Entry( aFileName, fileEntry ));
       
   382         iIsHidden = fileEntry.IsHidden();
       
   383 	    }
       
   384 	        
       
   385 	OstTraceFunctionExit0( CMTPCOPYOBJECT_GETPREVIOUSPROPERTIESL_EXIT );
   363 	}
   386 	}
   364 
   387 
   365 /**
   388 /**
   366 Set the object properties after doing the copy
   389 Set the object properties after doing the copy
   367 */
   390 */
   368 void CMTPCopyObject::SetPreviousPropertiesL(const TDesC& aFileName)
   391 void CMTPCopyObject::SetPreviousPropertiesL(const TDesC& aFileName)
   369 	{
   392 	{
   370 	__FLOG(_L8("SetPreviousPropertiesL - Entry"));
   393 	OstTraceFunctionEntry0( CMTPCOPYOBJECT_SETPREVIOUSPROPERTIESL_ENTRY );
   371 	User::LeaveIfError(iFramework.Fs().SetModified(aFileName, iPreviousModifiedTime));
   394 	LEAVEIFERROR(iFramework.Fs().SetModified(aFileName, iPreviousModifiedTime),
   372 	__FLOG(_L8("SetPreviousPropertiesL - Exit"));
   395 	        OstTraceExt1( TRACE_ERROR, CMTPCOPYOBJECT_SETPREVIOUSPROPERTIESL, "Sets the date and time for %S failed", aFileName));
       
   396 	if ( iIsFolder && iIsHidden )
       
   397 	    {
       
   398         TEntry fileEntry;
       
   399         User::LeaveIfError(iFramework.Fs().Entry( aFileName, fileEntry ));
       
   400         fileEntry.iAtt &= ~KEntryAttHidden;
       
   401         fileEntry.iAtt |= KEntryAttHidden;
       
   402         User::LeaveIfError(iFramework.Fs().SetAtt( aFileName, fileEntry.iAtt, ~fileEntry.iAtt));
       
   403 	    }
       
   404 	OstTraceFunctionExit0( CMTPCOPYOBJECT_SETPREVIOUSPROPERTIESL_EXIT );
   373 	}
   405 	}
   374 
   406 
   375 /**
   407 /**
   376  Update object info in the database.
   408  Update object info in the database.
   377 */
   409 */
   378 TUint32 CMTPCopyObject::UpdateObjectInfoL(const TDesC& aNewObjectName)
   410 TUint32 CMTPCopyObject::UpdateObjectInfoL(const TDesC& aNewObjectName)
   379 	{
   411 	{
   380 	__FLOG(_L8("UpdateObjectInfoL - Entry"));	
   412 	OstTraceFunctionEntry0( CMTPCOPYOBJECT_UPDATEOBJECTINFOL_ENTRY );
   381 	
   413 	
   382 	// We should not modify this object's handle, so just get a "copy".
   414 	// We should not modify this object's handle, so just get a "copy".
   383 	CMTPObjectMetaData* objectInfo(CMTPObjectMetaData::NewLC());
   415 	CMTPObjectMetaData* objectInfo(CMTPObjectMetaData::NewLC());
   384 	const TMTPTypeUint32 objectHandle(iObjectInfo->Uint(CMTPObjectMetaData::EHandle));
   416 	const TMTPTypeUint32 objectHandle(iObjectInfo->Uint(CMTPObjectMetaData::EHandle));
   385 	if(iFramework.ObjectMgr().ObjectL(objectHandle, *objectInfo))
   417 	if(iFramework.ObjectMgr().ObjectL(objectHandle, *objectInfo))
   390 		objectInfo->SetUint(CMTPObjectMetaData::EStorageId, iStorageId);
   422 		objectInfo->SetUint(CMTPObjectMetaData::EStorageId, iStorageId);
   391 		iFramework.ObjectMgr().InsertObjectL(*objectInfo);
   423 		iFramework.ObjectMgr().InsertObjectL(*objectInfo);
   392 		}
   424 		}
   393 	else
   425 	else
   394 		{
   426 		{
       
   427         OstTrace0( TRACE_ERROR, CMTPCOPYOBJECT_UPDATEOBJECTINFOL, "the specified object handle doesn't exist");
   395 		User::Leave(KErrCorrupt);
   428 		User::Leave(KErrCorrupt);
   396 		}
   429 		}
   397 	TUint32 handle = objectInfo->Uint(CMTPObjectMetaData::EHandle);	
   430 	TUint32 handle = objectInfo->Uint(CMTPObjectMetaData::EHandle);	
   398 	CleanupStack::PopAndDestroy(objectInfo);
   431 	CleanupStack::PopAndDestroy(objectInfo);
   399 	
   432 	
   400 	__FLOG(_L8("UpdateObjectInfoL - Exit"));
   433 	OstTraceFunctionExit0( CMTPCOPYOBJECT_UPDATEOBJECTINFOL_EXIT );
   401 	
       
   402 	return handle;	
   434 	return handle;	
   403 	}
   435 	}
   404 
   436 
   405 /**
   437 /**
   406  Call back function, called when the timer expired for big file copying.
   438  Call back function, called when the timer expired for big file copying.
   414 	return KErrNone;
   446 	return KErrNone;
   415 	}
   447 	}
   416 
   448 
   417 void CMTPCopyObject::DoOnTimeoutL()
   449 void CMTPCopyObject::DoOnTimeoutL()
   418 	{
   450 	{
   419 	__FLOG(_L8("DoOnTimeoutL - Entry"));
   451 	OstTraceFunctionEntry0( CMTPCOPYOBJECT_DOONTIMEOUTL_ENTRY );
   420 	
   452 	
   421 	if (iTimer)
   453 	if (iTimer)
   422 		{
   454 		{
   423 		if (iTimer->IsActive())
   455 		if (iTimer->IsActive())
   424 			{
   456 			{
   428 		iTimer = NULL;
   460 		iTimer = NULL;
   429 		}
   461 		}
   430 	
   462 	
   431 	const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid));
   463 	const TDesC& suid(iObjectInfo->DesC(CMTPObjectMetaData::ESuid));
   432 	TEntry fileEntry;
   464 	TEntry fileEntry;
   433 	User::LeaveIfError(iFramework.Fs().Entry(suid, fileEntry));
   465 	LEAVEIFERROR(iFramework.Fs().Entry(suid, fileEntry),
       
   466 	        OstTraceExt1( TRACE_ERROR, DUP1_CMTPCOPYOBJECT_DOONTIMEOUTL, "Gets the entry details for %S failed!", suid));
       
   467 
   434 	TUint32 handle = KMTPHandleNone;
   468 	TUint32 handle = KMTPHandleNone;
   435 	handle = UpdateObjectInfoL(*iNewFileName);
   469 	handle = UpdateObjectInfoL(*iNewFileName);
   436 	CMTPFSEntryCache& aCache = iDpSingletons.CopyingBigFileCache();
   470 	CMTPFSEntryCache& aCache = iDpSingletons.CopyingBigFileCache();
   437 	
   471 	
   438 	// Cache the target file entry info, which is used to send response to getobjectproplist and getobjectinfo
   472 	// Cache the target file entry info, which is used to send response to getobjectproplist and getobjectinfo
   439 	aCache.SetOnGoing(ETrue);
   473 	aCache.SetOnGoing(ETrue);
   440 	aCache.SetTargetHandle(handle);
   474 	aCache.SetTargetHandle(handle);
   441 	aCache.SetFileEntry(fileEntry);
   475 	aCache.SetFileEntry(fileEntry);
   442 	
   476 
   443 	__FLOG_VA((_L8("UpdateFSEntryCache, sending response with handle=%d, respond code OK for a big file copy"), handle));
   477 	OstTrace1( TRACE_NORMAL, CMTPCOPYOBJECT_DOONTIMEOUTL, 
       
   478 	        "UpdateFSEntryCache, sending response with handle=%d, respond code OK for a big file copy", handle );	
   444 	SendResponseL(EMTPRespCodeOK, 1, &handle);
   479 	SendResponseL(EMTPRespCodeOK, 1, &handle);
   445 	
   480 	
   446 	__FLOG(_L8("DoOnTimeoutL - Exit"));
   481 	OstTraceFunctionExit0( CMTPCOPYOBJECT_DOONTIMEOUTL_EXIT );
   447 	}
   482 	}
   448 
   483 
   449 /**
   484 /**
   450  CMTPCopyObject::RunL
   485  CMTPCopyObject::RunL
   451 */
   486 */
   452 void CMTPCopyObject::RunL()
   487 void CMTPCopyObject::RunL()
   453 	{
   488 	{
   454 	__FLOG(_L8("RunL - Entry"));
   489 	OstTraceFunctionEntry0( CMTPCOPYOBJECT_RUNL_ENTRY );
   455 	
   490 	
   456 	User::LeaveIfError(iStatus.Int());
   491 	LEAVEIFERROR(iStatus.Int(),
       
   492 	        OstTrace1( TRACE_ERROR, DUP2_CMTPCOPYOBJECT_RUNL, "wrong istatus %d", iStatus.Int()));
   457 	SetPreviousPropertiesL(*iNewFileName);
   493 	SetPreviousPropertiesL(*iNewFileName);
   458 	CMTPFSEntryCache& aCache = iDpSingletons.CopyingBigFileCache();
   494 	CMTPFSEntryCache& aCache = iDpSingletons.CopyingBigFileCache();
   459 	// Check to see if we are copying a big file
   495 	// Check to see if we are copying a big file
   460 	if(aCache.IsOnGoing())
   496 	if(aCache.IsOnGoing())
   461 		{
   497 		{
   462 		__FLOG(_L8("RunL - Big file copy complete"));
   498 		OstTrace0( TRACE_NORMAL, CMTPCOPYOBJECT_RUNL, "RunL - Big file copy complete" );
   463 		aCache.SetOnGoing(EFalse);
   499 		aCache.SetOnGoing(EFalse);
   464 		aCache.SetTargetHandle(KMTPHandleNone);
   500 		aCache.SetTargetHandle(KMTPHandleNone);
   465 		}	
   501 		}	
   466 	else
   502 	else
   467 		{
   503 		{
   475 			delete iTimer;
   511 			delete iTimer;
   476 			iTimer = NULL;
   512 			iTimer = NULL;
   477 			}
   513 			}
   478 		
   514 		
   479 		TUint32 handle = UpdateObjectInfoL(*iNewFileName);
   515 		TUint32 handle = UpdateObjectInfoL(*iNewFileName);
   480 		__FLOG_VA((_L8("RunL, sending response with handle=%d, respond code OK for a normal file copy"), handle));
   516 		OstTrace1( TRACE_NORMAL, DUP1_CMTPCOPYOBJECT_RUNL, 
       
   517 		        "RunL, sending response with handle=%d, respond code OK for a normal file copy", handle );		
   481 		SendResponseL(EMTPRespCodeOK, 1, &handle);
   518 		SendResponseL(EMTPRespCodeOK, 1, &handle);
   482 		}
   519 		}
   483 	__FLOG(_L8("RunL - Exit"));
   520 	OstTraceFunctionExit0( CMTPCOPYOBJECT_RUNL_EXIT );
   484 	}
   521 	}
   485 
   522 
   486 /**
   523 /**
   487 Override to handle the complete phase of copy object
   524 Override to handle the complete phase of copy object
   488 @return EFalse
   525 @return EFalse
   489 */
   526 */
   490 TBool CMTPCopyObject::DoHandleCompletingPhaseL()
   527 TBool CMTPCopyObject::DoHandleCompletingPhaseL()
   491 	{
   528 	{
       
   529 	OstTraceFunctionEntry0( CMTPCOPYOBJECT_DOHANDLECOMPLETINGPHASEL_ENTRY );
   492 	CMTPRequestProcessor::DoHandleCompletingPhaseL();
   530 	CMTPRequestProcessor::DoHandleCompletingPhaseL();
   493 	
   531 	
   494 	CMTPFSEntryCache& aCache = iDpSingletons.CopyingBigFileCache();
   532 	CMTPFSEntryCache& aCache = iDpSingletons.CopyingBigFileCache();
   495 	if(aCache.IsOnGoing())
   533 	if(aCache.IsOnGoing())
   496 		{
   534 		{
       
   535 		OstTraceFunctionExit0( CMTPCOPYOBJECT_DOHANDLECOMPLETINGPHASEL_EXIT );
   497 		return EFalse;
   536 		return EFalse;
   498 		}
   537 		}
   499 	else
   538 	else
   500 		{
   539 		{
       
   540 		OstTraceFunctionExit0( DUP1_CMTPCOPYOBJECT_DOHANDLECOMPLETINGPHASEL_EXIT );
   501 		return ETrue;
   541 		return ETrue;
   502 		}
   542 		}
   503 	}
   543 	}
   504 
   544 
   505 /**
   545 /**
   508 @param aConnection The connection from which the request comes
   548 @param aConnection The connection from which the request comes
   509 @return ETrue if the processor can handle the request, otherwise EFalse
   549 @return ETrue if the processor can handle the request, otherwise EFalse
   510 */        
   550 */        
   511 TBool CMTPCopyObject::Match(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection) const
   551 TBool CMTPCopyObject::Match(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection) const
   512 	{
   552 	{
   513 	__FLOG(_L8("Match - Entry"));
   553 	OstTraceFunctionEntry0( CMTPCOPYOBJECT_MATCH_ENTRY );
   514 	TBool result = EFalse;
   554 	TBool result = EFalse;
   515 	TUint16 operationCode = aRequest.Uint16(TMTPTypeRequest::ERequestOperationCode);
   555 	TUint16 operationCode = aRequest.Uint16(TMTPTypeRequest::ERequestOperationCode);
   516 	if ((operationCode == EMTPOpCodeCopyObject) && &iConnection == &aConnection)
   556 	if ((operationCode == EMTPOpCodeCopyObject) && &iConnection == &aConnection)
   517 	{
   557 	{
   518 	result = ETrue;
   558 	result = ETrue;
   519 	}    
   559 	}    
   520 	__FLOG_VA((_L8("Match -- Exit with result = %d"), result));
   560 	OstTraceFunctionExit0( CMTPCOPYOBJECT_MATCH_EXIT );
   521 	return result;    
   561 	return result;    
   522 	}
   562 	}