tags:

views:

113

answers:

2

I'm building a utility application that synchronizes files across two systems for Mac OSX. I need to detect when a file has been renamed but is otherwise the same file. How do I do this in Cocoa?

A: 

You can look at the inode number (NSFileSystemFileNumber in the attributes returned by NSFileManager), which would cover simple rename cases.

smorgan
A: 

There's no simple answer; you need to figure out the best strategy for your app.

At a simple level there is working with the file system number. You can grab this using NSFileSystemFileNumber. Probably better for the job though is to use FSRef. It's a C API but relatively straightforward, and has a method for comparing to FSRefs for equality.

But, there are plenty of applications which perform a save operation by replacing the file on disk, changing its file number. This could well upset your code. So consider using aliases. This is the same system as the Finder uses to keep track of the target of an alias file. Use either the Alias Manager (C API), or one of the open source Objective-C wrappers (e.g. NDAlias or BDAlias). An alias will do its best to maintain a reference to a file by both path and file number.

Mike Abdullah