• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: FSDetermineIfRefIsEnclosedByFolder(): No const for Cocoa's Temp Dir?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FSDetermineIfRefIsEnclosedByFolder(): No const for Cocoa's Temp Dir?


  • Subject: Re: FSDetermineIfRefIsEnclosedByFolder(): No const for Cocoa's Temp Dir?
  • From: Bill Cheeseman <email@hidden>
  • Date: Wed, 12 Aug 2009 10:41:47 -0400


On Aug 12, 2009, at 10:10 AM, Jerry Krinock wrote:

Because my application deals with a small number of documents -- most users will have only one, and because these documents have "agents" associated with them and are often not edited, I want my app to warn the user immediately upon opening a document that is in the Trash, instead of the default Cocoa behavior which is to open it and complain later only if the user attempts to save changes.

Unfortunately, the correct way to determine if a file is in a special directory, using Folder Manager function FSDetermineIfRefIsEnclosedByFolder(), does not seem able to determine whether or not a path that I get from the url passed to - [NSDocument readFromURL:ofType:error:] is temporary. The first problem is that Cocoa apparently copies the file to a temporary directory, something like
/private/var/folders/PR/PRtZlutkFa82jPnfdYcUUk+++TI/-Tmp-/
before opening it, so this path is indeed "not in the trash".


OK, so then I try FSDetermineIfRefIsEnclosedByFolder() again, and again, passing kTemporaryFolderType, kChewableItemsFolderType, kTemporaryItemsInCacheDataFolderType, and kWhereToEmptyTrashFolderType in succession. But it in each case, it returns 'false' -- meaning that the file is not in the specified special directory.

So, finally I resorted to the obviously wrong kludge of getting the "Cocoa" temporary directory from NSTemporaryDirectory() and testing whether or not this is a prefix of the given path. Of course, this works.

What's the correct way to do this?

I faced a very similar issue recently, but on the save side, not the read side. I solved it by overriding one of the Cocoa methods that is called during an NSDocument save operation, in my NSDocument subclass, to get the URL of the final save location, when the document is being moved from the temporary save location to the final save location. I determined which method to override by studying the detailed roadmap of the NSDocument save operation in Apple's "Document-Based Application Overview" document.


Apple's document includes a similar roadmap to NSDocument's read operation. I would guess that you'll find in that roadmap an appropriate method to override in order to obtain the original URL of the document you are reading.


--

Bill Cheeseman
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


References: 
 >FSDetermineIfRefIsEnclosedByFolder(): No const for Cocoa's Temp Dir? (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: CATransition + NSView mask
  • Next by Date: Re: FSDetermineIfRefIsEnclosedByFolder(): No const for Cocoa's Temp Dir?
  • Previous by thread: FSDetermineIfRefIsEnclosedByFolder(): No const for Cocoa's Temp Dir?
  • Next by thread: Re: FSDetermineIfRefIsEnclosedByFolder(): No const for Cocoa's Temp Dir?
  • Index(es):
    • Date
    • Thread