views:

40

answers:

1

I'm trying to create a "project"-like document, in that it contains subdocuments in a specified directory. I'd like a brand new save of a document to set up that directory with appropriate subdirectories. I'd like a "Save As" to copy all those subdirectories and any files within them to the new location. But I'd like a "Save" to only update certain data files and (of course) not overwrite all the subdocuments!

What's the "safe" way to do this? I tried keeping track of the file's location in my document, and checking to see if it was the same or different than the save location, but it feels messy, and I'm worried that Apple is doing something behind the scenes that will make this direct URL-to-URL comparison fail in some circumstances.

Is there a standard way to do something like this?

+1  A: 

NSFileWrapper has incremental writing support in Snow Leopard, which will use hard links instead of copying. This seems like exactly what you're looking for.

See this blog entry for more information.

Nicholas Riley
Unfortunately, using hard links to emulate copy-on-write is a dangerous and broken idea. Sooner or later someone will edit one of the “copied” files in the package with a tool that rewrites the original file rather than writing a new one, and break the other “copies”.NSFileWrapper without the hard link hack is the “proper” framework-provided approach.
Ahruman
Uh? The framework *is* doing the hard linking for you. It's not a hack, it's a substantial speed improvement for incremental saves. And this only happens with a "Save", not a "Save As", just as the poster suggests.
Nicholas Riley