Monitor file changes
| Mon, 2006-05-15 10:26 | |
|
Hi,
I need to monitor various possible changes in the file system. I have had a look in this and other forums and it looks like the way forward is: RFs::NotifyChange() So, the idea is that i have a TRequestStatus (I have contructed an active object for this purpose) which i pass as a parameter in the NotifyChange call. Then, when something happens on the file system, my TRequestStatus gets completed. In my case this will run my RunL. So now lets imagine that I have also passed ENotifyAll to the NotifyChange method so that i recieve notification for almost anything that occurs on the file system. Lets also imagine that the user renames a file. In this case my RunL gets run. Perfect. How can i find out: - that the RunL has been run due to a renaming of a file? - what the old name (full path details) of the file was since that is the information that i had before, so that i know which file we are talking about? - what the new name is? So far as i can see the NotifyChange method will let you know that something has happened but not what. Does anyone have any tips on how to extract this information or any suggestion on a better aproach for monitoring the file system? Many thanks PL |
|






Forum posts: 723
First note that I haven't implemented such a feature at all.
BUT, having checked out the SDK docs I would say that the only optionyou have is to take a snapshot of the directory (hierarchy) first prior to asking for notification from the File Server. Then, upon notification, take another snapshot and compare the two - that will let you find out what has changed and how.
I know, I know: it's a PITA. But, I'm also interested in better alternatives.
Tote
Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/
Forum posts: 1246
But of course, if you want to surprise the world with one more "antivirus program", only this time on the oh-so-endangered Symbian phones, or if you want to become the Google of phone search, then you have a need to watch the phone filesystem.
What else for, however? I mean, what for watch the whole file system?
René Brunner
Forum posts: 98
If you are making an application that syncs the user data(contact,images...) on Some server using GPRS.So Every time Syncsession will start on phone first thing ,application need to know is what is new data added before last Successful SyncSession?
Forum posts: 723
Tote
Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/
Forum posts: 104
I can´t speak for others however i can confirm that a fundemental requirement of my program is that it is aware of changes on the file system (like the one i described above) as they happen.
I regret that for reasons of corporate confidentiality that i cannot be more specific about the requirement so as to demonstrate that this is the case.
What i find confusing about the whole RFs::NotifyChange() thing is that it seems to be designed to tell you that "something" has happened in the file system, but not "what" has happened.
I realise that you can narrow it down if you restrict the types of file system event that will complete the TRequestStatus that you pass it. eg. so that the RunL is run only in the case of an RFile::Write.
However this is still of limited use if you don´t know which file was written to.
I end up asking myself the question: What use is a method that tells you that something has happened but not what? or even to what?
The obvious conclusion is that i have not understood correctly what this method is for. However on the other hand i have seen numerous other threads on forums indicating that the use of NotifyChange is the way forward for a requirement like mine.
What i have not been able to find in the SDK nor after a morning of frenetic Googleing is a single example of the RFs::NotifyChange method being implemented.
Is there anyone out there that can:
- explain the use of RFs::NotifyChange?
- provide and example or a link to one?
- put me straight if this is really not what RFs::NotifyChange is really designed for?
Cheers
PL
Forum posts: 732
Developer Discussion Boards - File operations monitoring
One person was refering TNotifyType there. Did you use that enum?
Enum TNotifyType
Change notification flags.
These indicate what kind of change should result in notification.
This is useful for programs that maintain displays of file lists which must be dynamically updated.
ENotifyEntry
Addition or deletion of a directory entry, or changing or formatting a disk.
ENotifyAll
Any change, including mounting and unmounting drives.
ENotifyFile
Change resulting from file requests: RFile::Create(), RFile::Replace(), RFile::Rename(), and RFs::Delete(), RFs::Replace(), and RFs::Rename().
ENotifyDir
Change resulting from directory requests: RFs::MkDir(), RFs::RmDir(), and RFs::Rename().
ENotifyAttributes
Change resulting from RFs::SetEntry() and RFile::Set(), RFile::SetAtt(), RFile::SetModified() and RFile::SetSize() requests.
ENotifyWrite
Change resulting from the RFile::Write() request.
ENotifyDisk
Change resulting from the RRawDisk::Write() request.
Forum posts: 723
I have a bad feeling that MFileManObserver suits your purposes only if you're doing things using CFileMan. Otherwise (i.e. if you or anybody else uses RFs and RFile), it's not useful.
I would still say that RFs::NotifyChange still holds one piece of information that might be important in some case: the fact that something has changed. Although it does NOT reveal what has changed nor does it say how, but that you can check yourself. Even if it's very painful and error-prone, it's still something that you can do.
Tote
Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/
Forum posts: 104
The TNotifyType is the mechanism that i refered to earlier for filtering the type of event that would prompt the TRequestStatus to get completed.
So far as the MFileManObserver goes, i have the same bad feeling as "tote". This only works with CFileMan.
Whilst i agree that the idea of diff'ing snapshots of the file system should work in theory i foresee unforeseen difficulties (paddling up and down list of file names, sizes, timestamps, trying to get it all done before the next re-nameing or whatever other events are being listened for etc). As you say it would be a PITA and i´m not convinced that i could get it efficient enough for my purposes.
Given the number of posts that i´ve seen that relate to this issue, and the fact that some of them are not that recent, my hope is that someone out there has implemented somthing along these lines.
If you are that person hit reply and put us all out of our misery. Think of the karma points. Â
PL
Forum posts: 1246
I for my part am not very sad that it seems to be hard to watch other applications doing their file reads and writes. I am a shareware author, and not that thrilled at the prospect of programs watching in real time exactly where my program notes the number of remaining trial days. And I am not waiting either for programs in the way "wife spies on possibly cheating husband via his mobile" where a secretely installed program protocols every file access.
But anyway, just my humble opinion, your mileage may vary.
René Brunner
Forum posts: 92
Stick 'em all on the active scheduler and have a generic event handler which each calls when it receives an event. The handler scans the appropriate sub-tree and compares the new contents with the previously stored set.
You may end up with rather a lot of active objects though - maybe this would necessitate a separate thread so as not to swamp the active scheduler for your application. Probably a fair amount of storage for the directory listings too.
I suspect however that this is mostly academic since in v9 the amount of filesystem snooping is reduced to the more public areas of the filesystem...
Forum posts: 7
Hi,
I am following your logic for getting notification before the changes occured in the file. I got all the directories from an active objects and pass it to another active object RunL(). Here, i am implemented my notification with ENotifyfile(). I didn't get the notificaiton while touching the files from file manager. But, i got some error information in console as follows,
"C:\Symbian\8.1a\S60_2nd_FP3\Epoc32\release\winscw\udeb\z\system\apps\Notification\Notification.lib" -addcommand "out:C:\Symbian\8.1a\S60_2nd_FP3\\Epoc32\release\winscw\udeb\z\\system\apps\Notification\Notification.app" -warnings off -l .\Deb_S60_23_WINSCW -search notification.
uid.o NotificationAO.o NotificationAO2.o NotificationApp.o NotificationAppUi.o NotificationContainer.o NotificationDocument.o
mwldsym2.exe: Error creating file: Notification.app
mwldsym2.exe: The requested operation cannot be performed on a file with a user-mapped section open.
Errors caused tool to abort.
Can u tell me the solution for this?
Thanks and Regards,
Jobin
Forum posts: 1246
Jobin: That looks like an error during compilation and linking, and not when you run it?
The error looks like the app file is kept open. This could be because the emulator is still running, or that your IDE has messed up.
This resulting in your app _not_ being rebuilt.
Close emulator, and/or restart your IDE, and try again.
Maybe that is why you don't get any notification, you still run your old version before you added the new code.