Re: sandboxd deny file-write-create
Re: sandboxd deny file-write-create
- Subject: Re: sandboxd deny file-write-create
- From: Quincey Morris <email@hidden>
- Date: Sun, 24 Nov 2013 11:31:36 -0800
On Nov 24, 2013, at 09:04 , Pax <email@hidden> wrote:
> Here's the problem. I'm writing out (potentially) very large files. It might be that the user doesn't want one huge xml file - instead they might want a bunch of smaller xml files. Therefore I prompt the user for a filename (which I use as a base) and then I append a number. So, for example, if the user specifies that they'd like the file to be called file.xml, I modify this to:
> file 1.xml
> file 2.xml
> file 3.xml and so forth.
> […] This code works file until I turn sandboxing on - and then it fails. The following code works fine in the sandbox, but without the benefit of appended numerals - making it impossible for me to split the file into chunks. […]
> Does anyone have any cunning plan for how I might achieve the functionality that I need without breaking the sandbox?
No cunning plan, but a couple of pedestrian alternatives.
Alternative 1. Instead of asking for a base *file* name, ask for a new *folder* name via NSSavePanel. That is, if the user enter “XYZ”, create a new folder of that name and put the files inside it, with a pre-determined name or even with XYZ as the base name.
This has the advantage that you don’t sprinkle the new files throughout an existing folder that might have lots of other files in it. The disadvantage is that you need to be careful if the folder already exists. The save panel mechanism will have already asked the user if the folder should be replaced, but it’s an easy way to wreak a lot of havoc if the user isn’t paying careful attention. (What I normally do, when replacing an existing item as a result of a save panel choice, is to delete it if it’s a file, but move it to the trash if it’s a folder. Then at least I can’t be blamed for mass deletions.)
Alternative 2. Instead of displaying a NSSavePanel, display a NSOpenPanel instead, asking the user to choose (or create) a destination folder for the files. Then, display a second, custom panel asking for the base file name.
Before you object that it is annoying to the user to see two panels in succession, consider the following defects in your original approach:
— If there happened to be an existing file called “file.xml” in the folder the user chose in the save panel, there’ll have been an “Are you sure you want to replace ‘file.xml’” alert displayed before your code know anything about it. In fact, that file wouldn’t be replaced or deleted.
— The save panel gives the user no indication that multiple files will be created, or how their names will be constructed.
If you use an open panel instead, you won’t have the first problem (though you should still check that you’re not going to override actual existing files without asking the user about it). You also won’t have the second problem, because your second panel is custom, and you can explain what you’re about to do, and how the new files will be named.
_______________________________________________
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