Can't copy data files into sandboxed app's container

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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

Can't copy data files into sandboxed app's container

Post by stephenmcnutt » Thu Aug 31, 2017 11:02 pm

I have an app called Classroom Quizshow. I have three data files (Settings Saver.rev, Questions.rev, and Teams.rev) inside a folder called "CQdata" within my standalone app's package. In my openCard handler, I copy them from my app's package to the appropriate location inside the user's Library. The following works for my standalone app BEFORE I sandbox it...

put specialFolderPath("support") & "/Classroom Quizshow" into gMacLibraryDefaultFolder
create folder gMacLibraryDefaultFolder
revCopyFile specialFolderPath("resources") & "/CQdata" & "/Settings Saver.rev", specialFolderPath("support") & "/Classroom Quizshow"
revCopyFile specialFolderPath("resources") & "/CQdata" & "/Questions.rev", specialFolderPath("support") & "/Classroom Quizshow"
revCopyFile specialFolderPath("resources") & "/CQdata" & "/Teams.rev", specialFolderPath("support") & "/Classroom Quizshow"

In the non-sandboxed standalone, the three files are copied to this directory: ~Library/Application Support/Classroom Quizshow/

I then sandbox my standalone using App Wrapper 3.

Now, in my sandboxed standalone, the first two lines of code above function properly. That is, the "Classroom Quizshow" folder is created in the proper location for a sandboxed app:
~Library/Containers/com.classroomquizshow.classroomquizshow/Data/Library/Application Support/Classroom Quizshow

However, the three data files are NOT copied into that folder.

I've been trying to figure this out for well over a year now, so... Help! :-)

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

Re: Can't copy data files into sandboxed app's container

Post by jacque » Fri Sep 01, 2017 4:32 pm

I wonder if those 3 files have to be codesigned too. I know extensions/plug-ins have to be. As a test, will they copy into the documents folder?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

tomBTG
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 73
Joined: Fri Nov 25, 2011 6:42 pm
Location: Kansas City

Re: Can't copy data files into sandboxed app's container

Post by tomBTG » Sat Sep 02, 2017 5:48 pm

Hi,

Here's an untested workaround for the problem:

Instead of copying existing stacks from your standalone package to the library, you could let the standalone do the work: Test if the files exist and, if not, create a new stack for each of them, add any cprops or fields you need, then save those stacks to the library location. This approach bypasses MacOS packaging issues.

Does this help?

Tom Bodine

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

Re: Can't copy data files into sandboxed app's container

Post by stephenmcnutt » Sat Sep 02, 2017 6:31 pm

Thanks, Tom, but I don't see how that would help because I'd still be copying or in this case saving stacks to the same location. Seems like I'd run into the same problem.

tomBTG
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 73
Joined: Fri Nov 25, 2011 6:42 pm
Location: Kansas City

Re: Can't copy data files into sandboxed app's container

Post by tomBTG » Sat Sep 02, 2017 7:05 pm

Maybe the issue is not the destination you are writing to. Maybe the MacOS doesn't like the source of your files (the application package). If that's the issue, the workaround would solve it.

My understanding is that revCopyFile uses the Mac OS to do the file copying. Whereas doing the save just lets Livecode write a file to a target location. I've been creating preference files for years using the direct save method. But I've also encountered many hitches using revCopyFile. So that's why I was thinking this workaround has potential.

By the way, when you are copying the files with revCopyFile, does it give you an error code in the result? That could be a useful clue.

Tom

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

Re: Can't copy data files into sandboxed app's container

Post by stephenmcnutt » Sat Sep 02, 2017 8:32 pm

I've heard of problems with revCopyFile, too. I notice my sandboxed standalone takes longer to open than the un-sandboxed standalone. There's a note in the LiveCode documentation about revCopyFile not being available when the app first launches. Maybe revCopyFile isn't yet available when it's called in the sandboxed standalone. I used to use shell commands to copy the file, and I may have to revert to that method.

Someone suggested I use the "put URL" method of copying the files, but so far I can't get it to work. This doesn't work at all, sandboxed or not...

put specialFolderPath("support") & "/Classroom Quizshow" into gMacLibraryDefaultFolder
put specialFolderPath("resources") & "/CQdata" & "/Settings Saver.rev" into gMacPackageFilePath_Settings_Saver
put specialFolderPath("resources") & "/CQdata" & "/Questions.rev" into gMacPackageFilePath_Questions
put specialFolderPath("resources") & "/CQdata" & "/Teams.rev" into gMacPackageFilePath_Teams
put URL ("binfile:" & gMacPackageFilePath_Settings_Saver) into URL ("binfile:" & gMacLibraryDefaultFolder)
put URL ("binfile:" & gMacPackageFilePath_Questions) into URL ("binfile:" & gMacLibraryDefaultFolder)
put URL ("binfile:" & gMacPackageFilePath_Teams) into URL ("binfile:" & gMacLibraryDefaultFolder)

I can't find documentation on how this "put URL" thing is supposed to work. Can you spot a syntax problem there?

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

Re: Can't copy data files into sandboxed app's container

Post by jacque » Sat Sep 02, 2017 9:47 pm

I can't find documentation on how this "put URL" thing is supposed to work. Can you spot a syntax problem there?
Yes, since you're moving a file into a file, you need to specify the new file name:

Code: Select all

put URL ("binfile:" & gMacPackageFilePath_Teams) into URL ("binfile:" & gMacLibraryDefaultFolder & "/Teams.rev")
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: Can't copy data files into sandboxed app's container

Post by stephenmcnutt » Sun Sep 03, 2017 4:55 pm

Yes!!!! When I use the "put URL" method properly, including the file names in the second part as you suggested, it works in both the unsandboxed and sandboxed versions of my standalone. I'm back in business and moving forward after more than a year of stagnation! Thank you!

So, lesson learned here is that revCopyFile indeed cannot be relied on to work in all situations. As I said, I read about problems with revCopyFile years ago and had been using shell commands instead. Then, I can't remember exactly, I believe I heard something about how shell commands were going to be outlawed in some situations (sandboxed apps maybe), and I also heard that revCopyFile was fixed and working fine. Apparently that latter part at least is not entirely true.

This program, Classroom Quizshow, has been a hobby of mine for over 23 years now. I originally wrote it in HyperCard during spring break of my first year as a 4th grade teacher then rewrote it in LiveCode some years later. I was really worried that I might be seeing the end of my little 23-years-plus project, but now I can continue, and I'm very happy about that. I've spent the last three years unable to update my Mac App Store version due to rejections and the past year dealing with this specific problem of not being able to copy my data files into the sandboxed standalone. Now at least I can get back to tackling the rejections, get my Mac App Store app updated (the version on classroomquizshow.com is three years more advanced) and actually start IMPROVING and ADDING FEATURES again. Sorry, all of this probably isn't very interesting, but I'm just so happy to be unstuck! Thank you, all those who helped me.

tomBTG
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 73
Joined: Fri Nov 25, 2011 6:42 pm
Location: Kansas City

Re: Can't copy data files into sandboxed app's container

Post by tomBTG » Sun Sep 03, 2017 5:07 pm

Congratulations on the breakthrough!
-- Tom Bodine

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

Re: Can't copy data files into sandboxed app's container

Post by jacque » Sun Sep 03, 2017 5:29 pm

Glad you're back on track. I believe revCopyFile uses shell too for some things, so that may be the reason it failed.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Mac OS”