karelia/iMedia — Issue #33: No Browser refresh on changes to AlbumData.xml
Author: jjac
Created: 2011-12-19 16:36:56+00:00
State: open

The iMedia browser does not refresh its iPhoto library when an image is added to iPhoto.

### Context

- Current head of master branch (commit 176965b)
- OS X 10.7.2
- iPhoto 9.2.1

### Steps to reproduce

1. Open iMedia Browser and click on your iPhoto library in the tree browser
1. Drag an image file from somewhere (but not from your iMedia Browser) onto iPhoto
1. Go back to iMedia Browser and find that nothing has changed here

### Expected behavior

The iMedia browser should have rebuilt the whole node tree and incorporated the new image into its iPhoto library

### Code analysis

The root cause to this false behavior is found in

-[IMBiPhotoParser nodeWithOldNode:options:error:]

which is subsequently called when the browser is notified for some change in the iPhoto library directory. You will find that it will not copy the `isTopLevelNode` property from the old node to the newly created node but will only make the new node a top level node when the old node is nil (lines 235-263). This logic seems rather odd to me. Why not straight copy `isTopLevelNode` from its old node?

Not being a top level node the path of the new (iPhoto root) node will not be watched which means that watching for changes in the iPhoto library directory ceases at this point.

I added a

node.isTopLevelNode = inOldNode.isTopLevelNode;

on line 263 and it then works.

But without the addition why didn't at least the first change cause a refresh? This is because iPhoto will first create a temporary file in its library's top level directory not yet changing AlbumData.xml. This will cause the browser to refresh without any changes. Then iPhoto will change AlbumData.xml but nobody will listen anymore.

In a http://groups.google.com/group/imedia-dev/browse_thread/thread/a51429a582ad1de6 I also suspected the implementation of

- (void) watchedPathDidChange:(NSString*)inWatchedPath
{
if ([inWatchedPath isEqual:self.mediaSource])
{
@synchronized(self)
{
self.plist = nil;
}
}
}

to be the cause. It still holds that `watchedPath` will never match `mediaSource` but this has no ill effects since

-[IMBAppleMediaParser plist]

will always check for an updated AlbumData.xml whenever it is called and recreate the plist dictionary when necessary .

### Now what?

I can go ahead and include the proposed change into the upcoming Photo Stream pull request if there is no adverse insight.

What worries me a bit is that I saw memory footprints of 500 MB and more for the iMedia browser once reestablishing (and triggering) refreshs.

Please comment.