19 #include "mdsfileserverplugin.h" |
19 #include "mdsfileserverplugin.h" |
20 #include "harvesterlog.h" |
20 #include "harvesterlog.h" |
21 #include "mdsutils.h" |
21 #include "mdsutils.h" |
22 |
22 |
23 _LIT( KMdsFileServerPlugin, "MdsFileServerPlugin" ); |
23 _LIT( KMdsFileServerPlugin, "MdsFileServerPlugin" ); |
|
24 _LIT( KExludedThumbPath, "\\_PAlbTN\\"); |
|
25 _LIT( KExludedMediaArtPath, "\\.mediaartlocal\\"); |
24 |
26 |
25 /* Server name */ |
27 /* Server name */ |
26 _LIT( KHarvesterServerName, "HarvesterServer" ); |
28 _LIT( KHarvesterServerName, "HarvesterServer" ); |
27 |
29 |
28 const TInt KCleanQueueTreshold( 1000 ); |
30 const TInt KCleanQueueTreshold( 1000 ); |
43 // |
45 // |
44 CMdsFileServerPlugin::~CMdsFileServerPlugin() |
46 CMdsFileServerPlugin::~CMdsFileServerPlugin() |
45 { |
47 { |
46 WRITELOG( "CMdsFileServerPlugin::~CMdsFileServerPlugin()" ); |
48 WRITELOG( "CMdsFileServerPlugin::~CMdsFileServerPlugin()" ); |
47 |
49 |
48 TRAP_IGNORE( DisableL() ); |
50 #ifdef _DEBUG |
49 iFsSession.Close(); |
51 TRAPD( error, DisableL() ); |
|
52 _LIT( KPanicCategory,"CMdsFileServerPlugin" ); |
|
53 __ASSERT_DEBUG( error == KErrNone, User::Panic( KPanicCategory, error ) ); |
|
54 #else |
|
55 TRAP_IGNORE( DisableL() ); |
|
56 #endif |
50 |
57 |
51 iCreatedFiles.ResetAndDestroy(); |
58 iCreatedFiles.ResetAndDestroy(); |
52 iCreatedFiles.Close(); |
59 iCreatedFiles.Close(); |
53 |
60 |
54 iModifiedFiles.ResetAndDestroy(); |
61 iModifiedFiles.ResetAndDestroy(); |
79 //----------------------------------------------------------------------------- |
86 //----------------------------------------------------------------------------- |
80 // |
87 // |
81 void CMdsFileServerPlugin::InitialiseL() |
88 void CMdsFileServerPlugin::InitialiseL() |
82 { |
89 { |
83 WRITELOG( "CMdsFileServerPlugin::InitializeL()" ); |
90 WRITELOG( "CMdsFileServerPlugin::InitializeL()" ); |
84 User::LeaveIfError( iFsSession.Connect() ); |
|
85 } |
91 } |
86 |
92 |
87 //----------------------------------------------------------------------------- |
93 //----------------------------------------------------------------------------- |
88 // |
94 // |
89 //----------------------------------------------------------------------------- |
95 //----------------------------------------------------------------------------- |
172 // |
178 // |
173 //----------------------------------------------------------------------------- |
179 //----------------------------------------------------------------------------- |
174 // |
180 // |
175 TInt CMdsFileServerPlugin::DoRequestL( TFsPluginRequest& aRequest ) |
181 TInt CMdsFileServerPlugin::DoRequestL( TFsPluginRequest& aRequest ) |
176 { |
182 { |
177 // ignore event if there is no any client listening |
183 // ignore event if there are not any clients listening |
178 if( iConnectionCount <= 0 ) |
184 if( iConnectionCount <= 0 ) |
179 { |
185 { |
180 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - no clients -> ignore event" ); |
186 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - no clients -> ignore event" ); |
181 return KErrNone; |
187 return KErrNone; |
182 } |
188 } |
183 |
189 |
184 TInt function = aRequest.Function(); |
190 TInt function = aRequest.Function(); |
185 |
191 |
186 iFileName.Zero(); |
|
187 iNewFileName.Zero(); |
|
188 |
|
189 #ifdef _DEBUG_EVENTS |
192 #ifdef _DEBUG_EVENTS |
190 PrintDebugEvents( function ); |
193 PrintDebugEvents( function ); |
191 #endif |
194 #endif |
192 |
195 |
193 if ( function == EFsFileSubClose && iCreatedFiles.Count() == 0 ) |
196 if ( function == EFsFileSubClose && iCreatedFiles.Count() == 0 ) |
216 WRITELOG1( "CMdsFileServerPlugin::DoRequestL() - fileName: %S", &iFileName ); |
219 WRITELOG1( "CMdsFileServerPlugin::DoRequestL() - fileName: %S", &iFileName ); |
217 } |
220 } |
218 } |
221 } |
219 |
222 |
220 // get process id |
223 // get process id |
221 TUid processId = { 0 }; |
224 TUid processId = aRequest.Message().SecureId(); |
222 |
|
223 processId = aRequest.Message().SecureId(); |
|
224 |
225 |
225 TBool isDirectory = EFalse; |
226 TBool isDirectory = EFalse; |
226 |
227 |
227 // if rename, check destination path |
228 // if rename, check destination path |
228 if ( function == EFsRename || function == EFsFileRename || |
229 if ( function == EFsRename || function == EFsFileRename || |
233 if ( iNewFileName.Length() > KMaxFileName ) |
234 if ( iNewFileName.Length() > KMaxFileName ) |
234 { |
235 { |
235 return KErrNone; |
236 return KErrNone; |
236 } |
237 } |
237 WRITELOG2( "CMdsFileServerPlugin::DoRequestL() - newFileName: '%S' %d", &iNewFileName, newNameErr ); |
238 WRITELOG2( "CMdsFileServerPlugin::DoRequestL() - newFileName: '%S' %d", &iNewFileName, newNameErr ); |
|
239 TBool setToBeDeleted( EFalse ); |
238 if ( newNameErr == KErrNone ) |
240 if ( newNameErr == KErrNone ) |
239 { |
241 { |
240 if ( !CheckPath(iNewFileName) ) |
242 if ( !CheckPath(iNewFileName) ) |
241 { |
243 { |
242 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - new path not supported" ); |
244 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - new path not supported" ); |
246 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - ignore file" ); |
248 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - ignore file" ); |
247 return KErrNone; |
249 return KErrNone; |
248 } |
250 } |
249 // file moved to ignored path, delete from db |
251 // file moved to ignored path, delete from db |
250 function = EFsDelete; |
252 function = EFsDelete; |
|
253 setToBeDeleted = ETrue; |
251 } |
254 } |
252 |
255 |
253 if ( !CheckAttribs( iNewFileName, isDirectory ) ) |
256 if( !setToBeDeleted ) |
254 { |
257 { |
255 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - new path attribute check failed" ); |
258 RFsPlugin fsPlugin( aRequest ); |
256 if( !CheckAttribs(iFileName, isDirectory) ) |
259 const TInt rfsPluginErr = fsPlugin.Connect(); |
|
260 |
|
261 if ( ( rfsPluginErr == KErrNone ) && !CheckAttribs( iNewFileName, isDirectory, fsPlugin, EFalse ) ) |
257 { |
262 { |
258 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - old path attribute check failed" ); |
263 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - new path attribute check failed" ); |
259 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - ignore file" ); |
264 if( !CheckAttribs(iFileName, isDirectory, fsPlugin, EFalse) ) |
260 return KErrNone; |
265 { |
|
266 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - old path attribute check failed" ); |
|
267 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - ignore file" ); |
|
268 fsPlugin.Close(); |
|
269 return KErrNone; |
|
270 } |
|
271 // file set to hidden, delete from db |
|
272 function = EFsDelete; |
261 } |
273 } |
262 // file set to hidden, delete from db |
274 fsPlugin.Close(); |
263 function = EFsDelete; |
|
264 } |
275 } |
265 } |
276 } |
266 else |
277 else |
267 { |
278 { |
268 if ( !CheckPath(iFileName) ) |
279 if( !CheckIfValidFile(iFileName, isDirectory, aRequest, EFalse) ) |
269 { |
280 { |
270 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - path not supported" ); |
|
271 return KErrNone; |
|
272 } |
|
273 |
|
274 if ( !CheckAttribs(iFileName, isDirectory) ) |
|
275 { |
|
276 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - attribute check failed" ); |
|
277 return KErrNone; |
281 return KErrNone; |
278 } |
282 } |
279 } |
283 } |
280 } |
284 } |
281 else if ( !formatFunction ) |
285 else if ( !formatFunction ) |
282 { |
286 { |
283 if ( !CheckPath(iFileName) ) |
287 const TBool deleteFunction( function == EFsDelete ); |
284 { |
288 if( !CheckIfValidFile(iFileName, isDirectory, aRequest, deleteFunction) ) |
285 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - path not supported" ); |
289 { |
286 return KErrNone; |
|
287 } |
|
288 |
|
289 if ( !CheckAttribs( iFileName, isDirectory ) ) |
|
290 { |
|
291 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - attribute check failed" ); |
|
292 return KErrNone; |
290 return KErrNone; |
293 } |
291 } |
294 } |
292 } |
295 |
293 |
296 TInt fileEventType = EMdsFileUnknown; |
294 TInt fileEventType = EMdsFileUnknown; |
304 switch( function ) |
302 switch( function ) |
305 { |
303 { |
306 case EFsFileCreate: |
304 case EFsFileCreate: |
307 { |
305 { |
308 #ifdef _DEBUG |
306 #ifdef _DEBUG |
309 if (function == EFsFileCreate) |
307 if (function == EFsFileCreate) |
|
308 { |
310 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - EFsFileCreate" ); |
309 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - EFsFileCreate" ); |
311 if (function == EFsFileReplace) |
310 } |
312 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - EFsFileReplace" ); |
|
313 #endif |
311 #endif |
314 |
312 |
315 iCreatedFiles.Append( iFileName.AllocL() ); |
313 HBufC* createdFileName = iFileName.Alloc(); |
316 User::LeaveIfError( UnregisterIntercept(EFsFileSetModified, EPostIntercept) ); |
314 if( createdFileName ) |
|
315 { |
|
316 // Ownership transferred if succeeded |
|
317 const TInt appendError( iCreatedFiles.Append( createdFileName ) ); |
|
318 if( appendError != KErrNone ) |
|
319 { |
|
320 delete createdFileName; |
|
321 createdFileName = NULL; |
|
322 } |
|
323 } |
317 return KErrNone; |
324 return KErrNone; |
318 } |
325 } |
319 |
326 |
320 case EFsFileSubClose: |
327 case EFsFileSubClose: |
321 { |
328 { |
329 { |
336 { |
330 fileEventType = EMdsFileCreated; |
337 fileEventType = EMdsFileCreated; |
331 delete iCreatedFiles[i]; |
338 delete iCreatedFiles[i]; |
332 iCreatedFiles.Remove( i ); |
339 iCreatedFiles.Remove( i ); |
333 |
340 |
334 //Have to check whether file has been hidden |
341 //Have to check whether file has been hidden |
335 if ( CheckAttribs( iFileName, isDirectory ) ) |
342 RFsPlugin fsPlugin( aRequest ); |
336 { |
343 const TInt rfsPluginError( fsPlugin.Connect() ); |
337 found = ETrue; |
344 if( (rfsPluginError == KErrNone) && CheckAttribs( iFileName, isDirectory, fsPlugin, EFalse ) ) |
338 } |
345 { |
339 |
346 found = ETrue; |
340 User::LeaveIfError( RegisterIntercept(EFsFileSetModified, EPostIntercept) ); |
347 } |
|
348 else if( rfsPluginError != KErrNone ) |
|
349 { |
|
350 found = ETrue; |
|
351 } |
|
352 fsPlugin.Close(); |
341 } |
353 } |
342 } |
354 } |
343 |
355 |
344 if( iCreatedFiles.Count() == 0 ) |
356 if( iCreatedFiles.Count() == 0 ) |
345 { |
357 { |
375 WRITELOG1( "CMdsFileServerPlugin::DoRequestL() - EFsFileRename, new file: %S", &iNewFileName ); |
387 WRITELOG1( "CMdsFileServerPlugin::DoRequestL() - EFsFileRename, new file: %S", &iNewFileName ); |
376 fileEventType = EMdsFileRenamed; |
388 fileEventType = EMdsFileRenamed; |
377 break; |
389 break; |
378 |
390 |
379 case EFsFileSetModified: |
391 case EFsFileSetModified: |
380 |
392 { |
381 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - EFsFileSetModified" ); |
393 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - EFsFileSetModified" ); |
382 iModifiedFiles.Append( iFileName.AllocL() ); |
394 |
|
395 for ( TInt i = iCreatedFiles.Count(); --i >= 0; ) |
|
396 { |
|
397 // If file has been created but not closed, do not handle modified events |
|
398 // for that file before the application that has created the file is done with writing |
|
399 // it to the disk. |
|
400 if ( MdsUtils::Compare( iFileName, *(iCreatedFiles[i]) ) == 0 ) |
|
401 { |
|
402 return KErrNone; |
|
403 } |
|
404 } |
|
405 |
|
406 HBufC* modifiedFileName = iFileName.Alloc(); |
|
407 if( modifiedFileName ) |
|
408 { |
|
409 // Ownership transferred if succeeded |
|
410 const TInt appendError( iModifiedFiles.Append( modifiedFileName ) ); |
|
411 if( appendError != KErrNone ) |
|
412 { |
|
413 delete modifiedFileName; |
|
414 modifiedFileName = NULL; |
|
415 } |
|
416 } |
|
417 |
383 fileEventType = EMdsFileModified; |
418 fileEventType = EMdsFileModified; |
|
419 } |
384 break; |
420 break; |
385 |
421 |
386 case EFsSetEntry: |
422 case EFsSetEntry: |
387 { |
423 { |
388 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - EFsSetEntry" ); |
424 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - EFsSetEntry" ); |
426 |
462 |
427 case EFsFormatOpen: |
463 case EFsFormatOpen: |
428 { |
464 { |
429 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - EFsFormatOpen" ); |
465 WRITELOG( "CMdsFileServerPlugin::DoRequestL() - EFsFormatOpen" ); |
430 // get the drive letter |
466 // get the drive letter |
431 RFsPlugin fsplugin( aRequest ); |
467 RFsPlugin fsPlugin( aRequest ); |
432 const TInt rfsPluginError( fsplugin.Connect() ); |
468 err = fsPlugin.Connect(); |
433 if( rfsPluginError == KErrNone ) |
469 if( err == KErrNone ) |
434 { |
470 { |
435 err = fsplugin.Volume( volInfo, drvNumber ); |
471 err = fsPlugin.Volume( volInfo, drvNumber ); |
436 } |
472 } |
437 else |
473 fsPlugin.Close(); |
438 { |
|
439 err = iFsSession.Volume( volInfo, drvNumber ); |
|
440 } |
|
441 fsplugin.Close(); |
|
442 |
474 |
443 if( KErrNone == err ) |
475 if( KErrNone == err ) |
444 { |
476 { |
445 iFormatOldMediaId = volInfo.iUniqueID; |
477 iFormatOldMediaId = volInfo.iUniqueID; |
446 iFormatDriveNumber = drvNumber; |
478 iFormatDriveNumber = drvNumber; |
945 TDesC* pathName = iIgnorePaths[i]; |
990 TDesC* pathName = iIgnorePaths[i]; |
946 if ( MdsUtils::Find( aFilename, *pathName ) != KErrNotFound ) |
991 if ( MdsUtils::Find( aFilename, *pathName ) != KErrNotFound ) |
947 { |
992 { |
948 return EFalse; |
993 return EFalse; |
949 } |
994 } |
|
995 else if( MdsUtils::Find( aFilename, KExludedThumbPath ) != KErrNotFound ) |
|
996 { |
|
997 return EFalse; |
|
998 } |
|
999 else if( MdsUtils::Find( aFilename, KExludedMediaArtPath ) != KErrNotFound ) |
|
1000 { |
|
1001 return EFalse; |
|
1002 } |
950 } |
1003 } |
951 |
1004 |
952 // check if notification path |
1005 // check if notification path |
953 if ( iPaths.Count() > 0 ) |
1006 if ( iPaths.Count() > 0 ) |
954 { |
1007 { |
979 //----------------------------------------------------------------------------- |
1032 //----------------------------------------------------------------------------- |
980 // CheckAttribs |
1033 // CheckAttribs |
981 //----------------------------------------------------------------------------- |
1034 //----------------------------------------------------------------------------- |
982 // |
1035 // |
983 TBool CMdsFileServerPlugin::CheckAttribs( const TDesC& aFilename, |
1036 TBool CMdsFileServerPlugin::CheckAttribs( const TDesC& aFilename, |
984 TBool& aIsDirectory ) const |
1037 TBool& aIsDirectory, RFsPlugin& aFsPlugin, TBool aDelete ) const |
985 { |
1038 { |
986 // find last backslash from filename and |
1039 // find last backslash from filename and |
987 // take drive and path from filename including last backslash |
1040 // take drive and path from filename including last backslash |
988 const TChar KBackslashChar( '\\' ); |
1041 const TChar KBackslashChar( '\\' ); |
989 TInt pos = aFilename.LocateReverse( KBackslashChar ); |
1042 TInt pos = aFilename.LocateReverse( KBackslashChar ); |
991 { |
1044 { |
992 return ETrue; |
1045 return ETrue; |
993 } |
1046 } |
994 TPtrC path( aFilename.Left( pos + 1 ) ); |
1047 TPtrC path( aFilename.Left( pos + 1 ) ); |
995 |
1048 |
996 TUint att = 0; |
1049 TEntry entry; |
997 |
1050 |
998 // check if path is hidden or system path |
1051 // check if path is hidden |
999 TInt err = iFsSession.Att( path, att ); |
1052 TInt err = aFsPlugin.Entry( path, entry ); |
1000 if ( err == KErrNone ) |
1053 if ( err == KErrNone ) |
1001 { |
1054 { |
1002 if ( att & KEntryAttHidden || att & KEntryAttSystem ) |
1055 if ( entry.iAtt & KEntryAttHidden ) |
1003 { |
1056 { |
1004 return EFalse; |
1057 return EFalse; |
1005 } |
1058 } |
1006 } |
1059 } |
1007 |
1060 |
1008 // or is the file hidden or system file |
1061 if( !aDelete ) |
1009 att = 0; |
1062 { |
1010 err = iFsSession.Att( aFilename, att ); |
1063 // check if the file hidden or system file |
1011 if ( err == KErrNone ) |
1064 err = aFsPlugin.Entry( aFilename, entry ); |
1012 { |
1065 if ( err == KErrNone ) |
1013 if ( att & KEntryAttHidden || att & KEntryAttSystem ) |
1066 { |
1014 { |
1067 if ( entry.iAtt & KEntryAttHidden || entry.iAtt & KEntryAttSystem ) |
1015 return EFalse; |
1068 { |
1016 } |
1069 return EFalse; |
|
1070 } |
1017 |
1071 |
1018 aIsDirectory = att & KEntryAttDir ? ETrue : EFalse; |
1072 aIsDirectory = entry.iAtt & KEntryAttDir ? ETrue : EFalse; |
|
1073 } |
1019 } |
1074 } |
1020 |
1075 |
1021 return ETrue; |
1076 return ETrue; |
1022 } |
1077 } |
1023 |
1078 |
1069 return ETrue; |
1124 return ETrue; |
1070 } |
1125 } |
1071 |
1126 |
1072 WRITELOG( "CMdsFileServerPlugin::CheckHarvesterStatus() - end" ); |
1127 WRITELOG( "CMdsFileServerPlugin::CheckHarvesterStatus() - end" ); |
1073 return EFalse; |
1128 return EFalse; |
|
1129 } |
|
1130 |
|
1131 //----------------------------------------------------------------------------- |
|
1132 // CheckIfValidFile |
|
1133 //----------------------------------------------------------------------------- |
|
1134 // |
|
1135 TBool CMdsFileServerPlugin::CheckIfValidFile( const TDesC& aFilename, |
|
1136 TBool& aIsDirectory, TFsPluginRequest& aRequest, TBool aDelete ) |
|
1137 { |
|
1138 if ( !CheckPath(aFilename) ) |
|
1139 { |
|
1140 WRITELOG( "CMdsFileServerPlugin::CheckIfValidFile() - path not supported" ); |
|
1141 return EFalse; |
|
1142 } |
|
1143 |
|
1144 RFsPlugin fsPlugin( aRequest ); |
|
1145 const TInt rfsPluginErr = fsPlugin.Connect(); |
|
1146 |
|
1147 if( rfsPluginErr == KErrNone ) |
|
1148 { |
|
1149 if ( !CheckAttribs(aFilename, aIsDirectory, fsPlugin, aDelete) ) |
|
1150 { |
|
1151 WRITELOG( "CMdsFileServerPlugin::CheckIfValidFile() - attribute check failed" ); |
|
1152 return EFalse; |
|
1153 } |
|
1154 } |
|
1155 fsPlugin.Close(); |
|
1156 |
|
1157 return ETrue; |
1074 } |
1158 } |
1075 |
1159 |
1076 //----------------------------------------------------------------------------- |
1160 //----------------------------------------------------------------------------- |
1077 // CMdsFileServerPluginFactory implementation |
1161 // CMdsFileServerPluginFactory implementation |
1078 //----------------------------------------------------------------------------- |
1162 //----------------------------------------------------------------------------- |