Mac Sandbox Container Creation Problem

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
stephenmcnutt
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 107
Joined: Fri Nov 10, 2006 8:58 pm
Contact:

Mac Sandbox Container Creation Problem

Post by stephenmcnutt » Wed Sep 07, 2016 11:07 pm

My sandboxed standalone is no longer creating the final folder in this chain...

~/Library/Containers/<bundle_id>/Data/Library/Application Support/<app_name>/
(https://developer.apple.com/library/mac ... ndbox.html)

Or, to be specific to my app, it's not creating the Classroom Quizshow folder in...
~/Library/Containers/com.classroomquizshow.classroomquizshow/Data/Library/Application Support/Classroom Quizshow/

That folder is where I place my data files, and It always used to be created automatically. At least I think it was. If I was doing anything to cause the Classroom Quizshow folder to be created, I don't know what it was. I thought the entire container, including the <app_name> folder was created automatically for sandboxed apps, but I've heard some say it's not. The container and everything BUT the <app_name> folder IS being created as expected.

It seems like this is a question I should be able to answer by reading Apple's developer documentation, but I've been all trough the pages around the one I linked above and haven't found an answer. By the way, even though the link above is to a page on migration, I included it only because that page is the only place I could find that gives at least that much of the container's structure. I'm not trying to do a migration of my data files from the pre-sandbox library location.

stephenmcnutt
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 107
Joined: Fri Nov 10, 2006 8:58 pm
Contact:

Re: Mac Sandbox Container Creation Problem

Post by stephenmcnutt » Sun Sep 11, 2016 5:20 pm

More info. More clues... This problem... let me restate it here for clarity...

PROBLEM: The final directory (<app_name>) in this sequence of Mac OS X Sandbox Container directories is not being created:

~/Library/Containers/<bundle_id>/Data/Library/Application Support/<app_name>/ (in my case <app_name> = Classroom Quizshow)

I thought it was being created automatically before, but now I think it's not--that I have to create that final directory myself.

Why, after years of working with the same application, am I just now discovering that I need to create this directory? I have a theory. The problem started when I stopped using "shell" commands to create the data files I place inside <app_name> (in my case the directory is called Classroom Quizshow, and the data file being created in the example below is Questions.rev) and started using the equivalent(?) LiveCode command "create".

OLD METHOD:
local tSource
local tDestination
local tCommand
put gLibraryDefaultFolder into tDestination
put gPackageFilePath_Questions into tSource
put ("cp -n "&quote&tSource&quote&&quote&tDestination&quote) into tCommand
get shell(tCommand)

That sort of code must have been creating the <app_name> directory for me. In the above example, tDestination was a file path ending with /Application Support/Classroom Quizshow/Questions.rev. It must've been not only copying the Questions.rev file into the destination but also creating the "Classroom Quizshow" directory when it found it didn't yet exist.

NEW METHOD:
put specialFolderPath("Home") & "/Library/Containers/com.classroomquizshow.classroomquizshow/Data/Library/Application Support/Classroom Quizshow" into gMacLibraryDefaultFolder
create folder gMacLibraryDefaultFolder

Those two lines don't actually show the copying of the Questions.rev file, but that's not the important part. The creation of the Classroom Quizshow directory is.

Here's what I've found using the NEW METHOD above:

When I create a standalone, it works perfectly. If I delete the Classroom Quizshow directory from the app's Sandbox Container, the standalone recreates the directory and the three data files that are supposed to be in there. However, this standalone is not yet Sandboxed. If I check the Mac OS X utility app "Activity Monitor", it says "No" in the Sandbox column.

If I sign the standalone using the latest version of AppWrapper, the signing/wrapping is successful, and the resulting standalone shows "Yes" in Activity Monitor's Sandbox column. However this standalone does not successfully run the "create folder gMacLibraryDefaultFolder" line of code. Execution gets past this point, but the Classroom Quizshow directory that code is supposed to create is not created, resulting in a dead app.

So it seems this "create" method is not allowed in Apple's sandboxing rules--at least it's not allowed for creating the special <app_name> folder at ~/Library/Containers/<bundle_id>/Data/Library/Application Support/<app_name>/.

Can anyone confirm this and tell me how to properly create this special directory within Sandboxing rules?

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5344
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Mac Sandbox Container Creation Problem

Post by jacque » Mon Sep 12, 2016 8:23 pm

That's an unusual file path. My library folder has no "Containers" folder, and none of the subfolders in your path either. Apple is very specific about the locations where a sandboxed app can store its data. They prefer Application Support but will accept the Preferences folder at least for now. In the Application Support folder, developers are supposed to create a folder named for their app and place all data files inside that.

LC uses specialFolderPath("asup") to reference the correct folder. Your app shoud use something like this:

put specialFolderPath("asup") & "/Classroom Quizshow" into tFolder
if there is no folder tFolder then create folder tFolder

Then use that folder path to store your data files. LC correctly creates folders and files by calling on the OS to do the work, so there's nothing wrong with how LC works. But it's a good idea to let LC figure out the correct path for a sandboxed app by referencing its specialFolderPath function.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

stephenmcnutt
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 107
Joined: Fri Nov 10, 2006 8:58 pm
Contact:

Re: Mac Sandbox Container Creation Problem

Post by stephenmcnutt » Mon Sep 12, 2016 11:58 pm

Thank you for your help, Jacque. However, unless I am very much mistaken, you are describing the Library directory structure for a non-sandboxed Mac OS X app, while I am describing the Library directory structure for a sandboxed Mac OS X app.

Am I wrong? I could easily be because I'm no expert.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5344
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Mac Sandbox Container Creation Problem

Post by jacque » Tue Sep 13, 2016 12:49 am

It was my understanding that LC would do the right thing and the OS handles the implementation, but I confess that the sandboxed app I am working on doesn't need to save files to the desktop so I haven't tried it. You might want to, just to see.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

stephenmcnutt
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 107
Joined: Fri Nov 10, 2006 8:58 pm
Contact:

Re: Mac Sandbox Container Creation Problem

Post by stephenmcnutt » Sun Sep 25, 2016 4:40 pm

I'm going to restart this issue with a new post because I understand it much better now. I can ask my question much more clearly.

Post Reply

Return to “Mac OS”