Monitor file changes

Login to reply to this topic.
Mon, 2006-05-15 10:26
Joined: 2006-04-05
Forum posts: 104
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

Mon, 2006-05-15 23:14
Forum Nokia Champion
Joined: 2003-10-01
Forum posts: 723
Re: Monitor file changes
Hi,

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.  Tongue

Tote

Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/

Tue, 2006-05-16 00:16
Guest (not verified)
Forum posts: 2043
Re: Monitor file changes
This sort of functionality is constantly being asked for, does anybody know why Symbian has never implemented it?
Tue, 2006-05-16 05:59
Joined: 2005-11-20
Forum posts: 1246
Re: Monitor file changes
I would really like to know what all the people that ask (and they do ask, alright!) need this functionality for. One should always be cautious when taking oneself as a measure, but I myself program now for over 20 years and never ever had the need to watch changes in a file system this way in one of my many programs...

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

Tue, 2006-05-16 10:45
Joined: 2005-02-12
Forum posts: 98
Re: Monitor file changes
No we may have need for important reason....
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?HuhHuhHuh
Tue, 2006-05-16 10:49
Forum Nokia Champion
Joined: 2003-10-01
Forum posts: 723
Re: Monitor file changes
And do you HAVE TO monitor file changes constantly on phone? Could you not simply check for the changes upon initiating the next session?

Tote

Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/

Tue, 2006-05-16 12:57
Joined: 2006-04-05
Forum posts: 104
Re: Monitor file changes
Hi,

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



Tue, 2006-05-16 13:21
Forum Nokia Champion
Joined: 2004-05-26
Forum posts: 732
Re: Monitor file changes
I found a quite interesting post from FN, hope it may helpful for you.

Developer Discussion Boards - File operations monitoring

One person was refering TNotifyType there. Did you use that enum?

Quote

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.

Tue, 2006-05-16 13:59
Forum Nokia Champion
Joined: 2003-10-01
Forum posts: 723
Re: Monitor file changes
Hi,

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.  Cry

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/

Tue, 2006-05-16 17:09
Joined: 2006-04-05
Forum posts: 104
Re: Monitor file changes
Hi,

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.   Wink

PL
Tue, 2006-05-16 17:23
Joined: 2005-11-20
Forum posts: 1246
Re: Monitor file changes
I am not that person, and I lost already karma points for less controversal posts than right this one, but let me say: I am not sure that it is a "misery".

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

Wed, 2006-05-17 05:54
Joined: 2004-10-31
Forum posts: 92
Re: Monitor file changes
Perhaps the answer is to write a generic active object class which takes a directory path on construction.  Do a full directory scan (store the results) and use it to create a separate active object to monitor, for example, each of the directories in the root of the drive(s) of interest - using as narrow file notification options as you can (eg just ENotifyFile).  You could, optionally, create even more active objects for those areas of the filesystem more liable to change.

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...
Sun, 2007-09-02 08:04
Joined: 2007-06-05
Forum posts: 7
Re: Monitor file changes

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

Tue, 2007-09-04 11:41
Joined: 2004-11-29
Forum posts: 1246
Re: Monitor file changes

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.

  • Login to reply to this topic.