34 #include "cmtpsendobjectinfo.h" |
34 #include "cmtpsendobjectinfo.h" |
35 #include "mtpdppanic.h" |
35 #include "mtpdppanic.h" |
36 #include "cmtpfsexclusionmgr.h" |
36 #include "cmtpfsexclusionmgr.h" |
37 #include "cmtpdataprovidercontroller.h" |
37 #include "cmtpdataprovidercontroller.h" |
38 #include "cmtpdataprovider.h" |
38 #include "cmtpdataprovider.h" |
|
39 #include "cmtpstoragemgr.h" |
39 |
40 |
40 |
41 |
41 // Class constants. |
42 // Class constants. |
42 __FLOG_STMT(_LIT8(KComponent,"SendObjectInfo");) |
43 __FLOG_STMT(_LIT8(KComponent,"SendObjectInfo");) |
43 |
44 |
70 Destructor |
71 Destructor |
71 */ |
72 */ |
72 EXPORT_C CMTPSendObjectInfo::~CMTPSendObjectInfo() |
73 EXPORT_C CMTPSendObjectInfo::~CMTPSendObjectInfo() |
73 { |
74 { |
74 __FLOG(_L8("~CMTPSendObjectInfo - Entry")); |
75 __FLOG(_L8("~CMTPSendObjectInfo - Entry")); |
75 |
76 __FLOG_2(_L8("iProgress:%d NoRollback:%d"),iProgress,iNoRollback); |
76 if ((iProgress == EObjectInfoSucceed || |
77 if ((iProgress == EObjectInfoSucceed || |
77 iProgress == EObjectInfoFail || |
78 iProgress == EObjectInfoFail || |
78 iProgress == EObjectInfoInProgress) && !iNoRollback) |
79 iProgress == EObjectInfoInProgress) && !iNoRollback) |
79 { |
80 { |
80 // Not finished SendObjectInfo/PropList SendObject pair detected. |
81 // Not finished SendObjectInfo/PropList SendObject pair detected. |
155 if (IsTooLarge(iObjectSize)) |
156 if (IsTooLarge(iObjectSize)) |
156 { |
157 { |
157 result = EMTPRespCodeObjectTooLarge; |
158 result = EMTPRespCodeObjectTooLarge; |
158 } |
159 } |
159 |
160 |
160 //File size is limited to KMaxTInt64 that is 8ExaBytes |
|
161 //if the object size is more,then report this error. |
|
162 if (!CanStoreFileL(iStorageId, iObjectSize)||(iObjectSize > (KMaxTInt64))) |
|
163 { |
|
164 result = EMTPRespCodeStoreFull; |
|
165 } |
|
166 } |
161 } |
167 } |
162 } |
168 |
163 |
169 // If the previous request is not SendObjectInfo or SendObjectPropList, SendObject fails |
164 // If the previous request is not SendObjectInfo or SendObjectPropList, SendObject fails |
170 if (result == EMTPRespCodeOK && iOperationCode == EMTPOpCodeSendObject) |
165 if (result == EMTPRespCodeOK && iOperationCode == EMTPOpCodeSendObject) |
718 iFramework.ObjectMgr().CommitReservedObjectHandleL(*iReceivedObject); |
712 iFramework.ObjectMgr().CommitReservedObjectHandleL(*iReceivedObject); |
719 |
713 |
720 TParsePtrC file( iFullPath ); |
714 TParsePtrC file( iFullPath ); |
721 _LIT( KTxtExtensionODF, ".odf" ); |
715 _LIT( KTxtExtensionODF, ".odf" ); |
722 if ( file.ExtPresent() && file.Ext().CompareF(KTxtExtensionODF)==0 ) |
716 if ( file.ExtPresent() && file.Ext().CompareF(KTxtExtensionODF)==0 ) |
723 {; |
717 { |
724 TUint32 DpId = iFramework.DataProviderId(); |
718 TUint32 DpId = iFramework.DataProviderId(); |
725 DpId = iDpSingletons.MTPUtility().GetDpId(file.Ext().Mid(1),KNullDesC); |
719 DpId = iDpSingletons.MTPUtility().GetDpId(file.Ext().Mid(1),KNullDesC); |
726 //The data provider which owns all mimetypes of a file extension is not found |
720 //The data provider which owns all mimetypes of a file extension is not found |
727 if ( 255 == DpId ) |
721 if ( 255 == DpId ) |
728 { |
722 { |
795 #endif |
789 #endif |
796 return result; |
790 return result; |
797 } |
791 } |
798 |
792 |
799 /** |
793 /** |
800 Check if we can store the file on the storage |
|
801 @return ETrue if yes, otherwise EFalse |
|
802 */ |
|
803 TBool CMTPSendObjectInfo::CanStoreFileL(TUint32 aStorageId, TInt64 aObjectSize) const |
|
804 { |
|
805 __FLOG(_L8("CanStoreFileL - Entry")); |
|
806 TBool result(ETrue); |
|
807 if (aStorageId == KMTPStorageDefault) |
|
808 { |
|
809 aStorageId = iFramework.StorageMgr().DefaultStorageId(); |
|
810 } |
|
811 TInt drive( iFramework.StorageMgr().DriveNumber(aStorageId) ); |
|
812 User::LeaveIfError(drive); |
|
813 TVolumeInfo volumeInfo; |
|
814 User::LeaveIfError(iFramework.Fs().Volume(volumeInfo, drive)); |
|
815 if (volumeInfo.iFree < aObjectSize) |
|
816 { |
|
817 result = EFalse; |
|
818 } |
|
819 __FLOG_VA((_L8("Result = %d"), result)); |
|
820 __FLOG(_L8("CanStoreFileL - Exit")); |
|
821 return result; |
|
822 } |
|
823 |
|
824 /** |
|
825 Check if the object is too large |
794 Check if the object is too large |
826 @return ETrue if yes, otherwise EFalse |
795 @return ETrue if yes, otherwise EFalse |
827 */ |
796 */ |
828 TBool CMTPSendObjectInfo::IsTooLarge(TUint64 aObjectSize) const |
797 TBool CMTPSendObjectInfo::IsTooLarge(TUint64 aObjectSize) const |
829 { |
798 { |
1078 { |
1047 { |
1079 TMTPResponseCode ret = EMTPRespCodeOK; |
1048 TMTPResponseCode ret = EMTPRespCodeOK; |
1080 const TUint32 storeId(Request().Uint32(TMTPTypeRequest::ERequestParameter1)); |
1049 const TUint32 storeId(Request().Uint32(TMTPTypeRequest::ERequestParameter1)); |
1081 const TUint32 parentHandle(Request().Uint32(TMTPTypeRequest::ERequestParameter2)); |
1050 const TUint32 parentHandle(Request().Uint32(TMTPTypeRequest::ERequestParameter2)); |
1082 |
1051 |
1083 // this checking is only valid when the second parameter is not a special value. |
1052 if( (EMTPOpCodeSendObjectPropList == iOperationCode) || (EMTPOpCodeSendObjectInfo == iOperationCode) ) |
1084 if (parentHandle != KMTPHandleAll && parentHandle != KMTPHandleNone) |
1053 { |
1085 { |
1054 if(storeId != KMTPStorageDefault) |
1086 //does not take owernship |
1055 { |
1087 CMTPObjectMetaData* parentObjInfo = iRequestChecker->GetObjectInfo(parentHandle); |
1056 if(!iSingletons.StorageMgr().IsReadWriteStorage(storeId)) |
1088 __ASSERT_DEBUG(parentObjInfo, Panic(EMTPDpObjectNull)); |
1057 { |
1089 |
1058 ret = EMTPRespCodeStoreReadOnly; |
1090 if (parentObjInfo->Uint(CMTPObjectMetaData::EStorageId) != storeId) |
1059 } |
1091 { |
1060 } |
1092 ret = EMTPRespCodeInvalidObjectHandle; |
1061 |
1093 } |
1062 // this checking is only valid when the second parameter is not a special value. |
1094 } |
1063 if ((EMTPRespCodeOK == ret) && (parentHandle != KMTPHandleAll && parentHandle != KMTPHandleNone)) |
1095 |
1064 { |
|
1065 //does not take owernship |
|
1066 CMTPObjectMetaData* parentObjInfo = iRequestChecker->GetObjectInfo(parentHandle); |
|
1067 __ASSERT_DEBUG(parentObjInfo, Panic(EMTPDpObjectNull)); |
|
1068 |
|
1069 if (parentObjInfo->Uint(CMTPObjectMetaData::EStorageId) != storeId) |
|
1070 { |
|
1071 ret = EMTPRespCodeInvalidObjectHandle; |
|
1072 } |
|
1073 } |
|
1074 } |
|
1075 |
1096 return ret; |
1076 return ret; |
1097 } |
1077 } |
1098 |
1078 |
1099 /** |
1079 /** |
1100 Reserves space for and assigns an object handle to the received object, then |
1080 Reserves space for and assigns an object handle to the received object, then |
1143 |
1123 |
1144 void CMTPSendObjectInfo::Rollback() |
1124 void CMTPSendObjectInfo::Rollback() |
1145 { |
1125 { |
1146 if(iIsFolder) |
1126 if(iIsFolder) |
1147 { |
1127 { |
1148 __FLOG(_L8("It is a folder cancel process.")); |
1128 __FLOG(_L8("Rollback the dir created.")); |
1149 iFramework.Fs().RmDir(iFullPath); |
1129 iFramework.Fs().RmDir(iFullPath); |
1150 // If it is folder, delete it from MTP database, i.e ObjectStore. |
1130 // If it is folder, delete it from MTP database, i.e ObjectStore. |
1151 TRAP_IGNORE(iFramework.ObjectMgr().RemoveObjectL(iFullPath)); |
1131 TRAP_IGNORE(iFramework.ObjectMgr().RemoveObjectL(iFullPath)); |
1152 } |
1132 } |
1153 else |
1133 else |
1154 { |
1134 { |
1155 __FLOG(_L8("It is a file cancel process.")); |
1135 __FLOG(_L8("Rollback the file created.")); |
|
1136 delete iFileReceived; |
|
1137 iFileReceived = NULL; |
1156 // Delete this object from file system. |
1138 // Delete this object from file system. |
1157 iFramework.Fs().Delete(iFullPath); |
1139 iFramework.Fs().Delete(iFullPath); |
1158 TRAP_IGNORE(iFramework.ObjectMgr().UnreserveObjectHandleL(*iReceivedObject)); |
1140 TRAP_IGNORE(iFramework.ObjectMgr().UnreserveObjectHandleL(*iReceivedObject)); |
1159 } |
1141 } |
1160 } |
1142 } |
1223 { |
1208 { |
1224 entry.iAtt |= KEntryAttReadOnly; |
1209 entry.iAtt |= KEntryAttReadOnly; |
1225 } |
1210 } |
1226 User::LeaveIfError(iFramework.Fs().SetAtt(iFullPath, entry.iAtt, ~entry.iAtt)); |
1211 User::LeaveIfError(iFramework.Fs().SetAtt(iFullPath, entry.iAtt, ~entry.iAtt)); |
1227 } |
1212 } |
|
1213 |
|
1214 if(iDateMod != NULL && iDateMod->Length()) |
|
1215 { |
|
1216 TTime modifiedTime; |
|
1217 iDpSingletons.MTPUtility().MTPTimeStr2TTime(*iDateMod, modifiedTime); |
|
1218 User::LeaveIfError(iFramework.Fs().SetModified(iFullPath, modifiedTime)); |
|
1219 } |
|
1220 |
1228 iReceivedObject->SetDesCL(CMTPObjectMetaData::EName, iName); |
1221 iReceivedObject->SetDesCL(CMTPObjectMetaData::EName, iName); |
1229 |
1222 |
1230 __FLOG(_L8("SetPropertiesL - Exit")); |
1223 __FLOG(_L8("SetPropertiesL - Exit")); |
1231 } |
1224 } |
1232 |
1225 |