Re: NSDocument: File attributes for backup file?
Re: NSDocument: File attributes for backup file?
- Subject: Re: NSDocument: File attributes for backup file?
- From: Mark Piccirelli <email@hidden>
- Date: Tue, 5 Feb 2002 19:33:30 -0800
Mani --
It looks like there are indeed situations in which backup file
attributes aren't preserved, though I'd be surprised if you're seeing
the problem happen on HFS+. In any case, try overriding -[NSDocument
writeWithBackupToFile:ofType:saveOperation:], have it call the
superclass' method, and then set the attributes on whatever backup file
has been created/updated during document writing. -[NSFileManager
changeFileAttributes:atPath:] should be the handiest way to do this.
You might even be able to use the same dictionary returned by your
document's -fileAttributesToWriteToFile:ofType:saveOperation: method.
Your code will have to figure out the path to the backup document file
itself. Here's some code that will do it the exact same way that
NSDocument does it:
// Make up a name for the backup revision of the document.
NSString *documentFileNameExtension = [fullDocumentPath pathExtension];
NSString *backupDocumentPath = [[fullDocumentPath
stringByDeletingPathExtension] stringByAppendingString:@"~"];
if (documentFileNameExtension && ![documentFileNameExtension
isEqualToString:@""]) {
backupDocumentPath = [backupDocumentName
stringByAppendingPathExtension:documentFileNameExtension];
}
I've made a note to include backward compatibility code in NSDocument if
we ever change the way backup file names are figured, though I don't
anticipate that happening any time soon anyway.
I haven't seen any trouble with Finder biffing on files whose names have
a "~" right before the extension. To confirm whether or not the problem
you've seen is in the Finder, as opposed to being caused by type/creator
code problems, you can just rename one of your document files that do
have the correct attributes....
Hope this helps.
-- Mark
On Wednesday, January 30, 2002, at 04:37 AM, Manfred Lippert wrote:
>
Hi,
>
>
I have a subclass of NSDocument that sets some file attributes to the
>
saved
>
files by overriding fileAttributesToWriteToFile:ofType:saveOperation.
>
I also want to keep backups of the files, so I override keepBackupFile
>
to
>
return YES.
>
The problem: The backup files do *not* have the attributes I gave the
>
original files. :-( Especially these are HFS Type/Creator and Posix
>
Access
>
Permissions. But I really need those attributes also on the backup
>
files.
>
>
What is the best way to give the same attributes to my backup files?
>
I don't want to rewrite the entire saving code ...
>
If I have to: has someone sample code for me? That would be great.
>
>
Another problem:
>
NSDocument seems to make a backup by renaming "file.ext" to "file~.ext".
>
Could it be that the Finder doesn't recognize the extension of those
>
backups
>
as extension anymore?? If I hide extensions in the Finder, only the
>
extensions of the original files are hidden, and also a double click on
>
backup files does not launch the right application. (But maybe this has
>
to
>
do with missing HFS Type/Creator-Codes?)
>
>
Thanks,
>
Mani
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.