Re: Automatically mirroring folders
Re: Automatically mirroring folders
- Subject: Re: Automatically mirroring folders
- From: Tony Romano <email@hidden>
- Date: Mon, 20 Jun 2011 01:41:13 -0700
- Thread-topic: Automatically mirroring folders
You coded your application to tell you when the directory has changed and
it's doing exactly that. I'm not sure what changes you are interested in
knowing or ignoring(I.e. File added, file modified, file deleted). In all
cases, you will need to track something so you have a reference, get a
notification that something has changed, decide what action you need to
take and then act on it.
Depending on what changes you are interested in, you may only need to
track the last time something changed, when you get a notification,
anything past this time needs an update. Or maybe you need to track all
the files in the directory, get a notification, and decide the difference
and act accordingly. You can scale up or down as needed.
For example, the project I'm working on, I have a difference engine to
determine files added, deleted, or modified based on a reference I am
looking at in memory. I am able to surgically modify my internal
structure and UI to match the changes happening on some external storage.
I think if you start playing around with turning notifications on or off,
or ignoring them at certain times, it may lead to errors. This is just a
hunch on my part and it could totally work just fine. I'd prefer to
process the notification and decide what to do. From a performance
perspective, since you are using FSEvents, you have to do a read on the
directory no matter what and that is probably the biggest cost, setting up
a diff engine on a 10, 100, 1000, 10000 files is fast. Also remember that
FSEvent will coalesce multiple event on a directory, so block changes will
come across as one event and the diff engine will find all the changes on
one pass through the engine.
This is one aspect on OS X I find to be weak, notifications on files.
Sure, the are Kqueues, but they have limits. Not as robust as I've seen
elsewhere.
HTH,
Tony Romano
On 6/20/11 12:53 AM, "Matt Gough" <email@hidden> wrote:
>Can you not make use of:
>
>kFSEventStreamCreateFlagIgnoreSelf
>"Ignore events generated by this client. For example, an application
>might want to watch for changes to a file so that it can reread it, but
>should not needlessly reread it if the change to the file was caused by
>the application itself writing out changes."
>
>Matt
>
>On 19 Jun 2011, at 17:48:32, Leonardo wrote:
>
>> Problem: I have to automatically mirror 2 folders, /A and /B, such a way
>> they contains the same files and folders.
>>
>> - So I FSEventStreamCreate with kFSEventStreamEventIdSinceNow,
>> kFSEventStreamCreateFlagWatchRoot and a 2 seconds latency time.
>>
>> - I get a notification: there is a new file to copy from /A to /B. I
>>copy
>> the file, but I quickly get a new notification that there is a new file
>>in
>> B. Well, this notification is useless to me. I copied that file.
>>Therefore I
>> don't need to copy it again.
>>
>> - So, before I copy the file, I thought, I stop and invalidate the
>>stream,
>> then I copy the file, then I turn the stream on again. But here I get 2
>> problems:
>>
>> 1) At the end of the copyFile, I turn the stream on again, and the
>>Finder, a
>> couple of seconds later (but it could even be shorter or longer)
>>updates the
>> /B/.DS_Store file so I get a new notification. How to force the Finder
>>to
>> update the .DS_Store file immediately after the copy? Or should I use a
>> longer latency time? How long?
>>
>> 2) During the period of time the stream is off, if some new files arrive
>> within the folder /A, I lose the notification to copy it.
>>
>> How to workaround that?
>>
>>
>> Regards
>> -- Leonardo
>>
>>
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>>
>>.com
>>
>> This email sent to email@hidden
>
>_______________________________________________
>
>Cocoa-dev mailing list (email@hidden)
>
>Please do not post admin requests or moderator comments to the list.
>Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
>Help/Unsubscribe/Update your Subscription:
>
>This email sent to email@hidden
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden