"Close Stack" Doesn't Close Stack
Posted: Thu Jun 13, 2013 9:00 pm
At least it doesn't seem to do so predictably. I have three data stacks in my Mac OS X application: Questions.rev, Settings Saver.rev, and Teams.rev. There's a copy of these three located in the application package, and they are copied to the Classroom Quizshow (the name of my app) folder within the user's /Library/Application Support folder at application launch if they're not already there. That works fine. Then I also have some other trickiness because I'm updating the copy of Settings Saver.rev that's possibly already in a user's Library folder. The root of the problem is no doubt that I have two copies of each data stack in two locations, and these pairs of stacks, of course, have the same names.
Through the debugger, I've determined that what doesn't work is closing the stacks. The problem is that, although I have the three (six, actually) data stacks' destroyStack set to true, they don't actually close (at least not immediately) when I issue a close stack command. Then, when I try to access them again, I get the error message saying:
A stack with the same name as the one you are trying to load is already open.
Before loading /Users/Steve/Dropbox/CQ 8.6.6/CQdata/Settings Saver.rev, what do you want to do with the stack: /Users/Steve/Library/Application Support/Classroom Quizshow/Settings Saver.rev, Settings Saver?
I'd already told that stack to "close stack". I've read the caveats in the "close stack" documentation describing situations in which stacks might not immediately close, but they don't seem to apply to my case. Also, the script doesn't work in stand-alone form, either. In the IDE it throws up the error message then freezes LiveCode, requiring a forced quit. Here's the example script in which "close stack" isn't working. I should note that, in an unsuccessful attempt to solve this problem--or at least to make the script easier to follow for me, I now refer to the six stacks by their absolute file paths instead of relying on changing the defaultFolder as I previously had. The variables such as gLibraryFilePath_Questions contain these absolute file paths, and I've verified that they're hitting their targets.
...
end if
save stack tFilePath_Settings_Saver
close stack tFilePath_Settings_Saver
if AppStore = "yes" then
if gUpdateSettingsSaver = "yes" then
local tSource
local tDestination
local tCommand
put gLibraryDefaultFolder into tDestination
put gPackageFilePath_Settings_Saver into tSource
put ("cp ""e&tSource"e&"e&tDestination"e) into tCommand -- There's no -n in the command, so it WILL overwrite the existing file. http://ss64.com/osx/cp.html
get shell(tCommand)
end if
save stack gLibraryFilePath_Questions
close stack gLibraryFilePath_Questions
save stack gLibraryFilePath_Teams
close stack gLibraryFilePath_Teams
else -- AppStore <> "yes"
save stack gPackageFilePath_Questions
close stack gPackageFilePath_Questions
save stack gPackageFilePath_Teams
close stack gPackageFilePath_Teams
end if
end saveDataStacks
The first "close stack" (close stack tFilePath_Settings_Saver), is intended to close the copy of Settings Saver.rev within the Library/Application Support/Classroom Quizshow/ folder, and, indeed, the "save" command on the previous line does save that stack as verified in the Finder.
When stepping through the code, I can see that stack is NOT closed after executing that step. I determine this by looking at the Application Browser after closing and reopening it to refresh its view. However, by the time I reach the final line of code pasted above, Settings Saver.rev IS closed. The other two "close stack" calls in the script above do NOT close their stacks, at least not by the time we reach the end of the pasted script.
So let me try to boil the problem down: Because of some tricky stack copying I have to do to get the data stacks from their initial home in the application package to their permanent home in the Library folder, I have pairs of stacks with the same name in two different places. I would think I could get by with this perhaps unadvisable situation by diligently closing the stacks after each use, but "close stack" isn't following orders. Help?
One more thing: I'm using LiveCode 5.5.4, build 1502.
Through the debugger, I've determined that what doesn't work is closing the stacks. The problem is that, although I have the three (six, actually) data stacks' destroyStack set to true, they don't actually close (at least not immediately) when I issue a close stack command. Then, when I try to access them again, I get the error message saying:
A stack with the same name as the one you are trying to load is already open.
Before loading /Users/Steve/Dropbox/CQ 8.6.6/CQdata/Settings Saver.rev, what do you want to do with the stack: /Users/Steve/Library/Application Support/Classroom Quizshow/Settings Saver.rev, Settings Saver?
I'd already told that stack to "close stack". I've read the caveats in the "close stack" documentation describing situations in which stacks might not immediately close, but they don't seem to apply to my case. Also, the script doesn't work in stand-alone form, either. In the IDE it throws up the error message then freezes LiveCode, requiring a forced quit. Here's the example script in which "close stack" isn't working. I should note that, in an unsuccessful attempt to solve this problem--or at least to make the script easier to follow for me, I now refer to the six stacks by their absolute file paths instead of relying on changing the defaultFolder as I previously had. The variables such as gLibraryFilePath_Questions contain these absolute file paths, and I've verified that they're hitting their targets.
...
end if
save stack tFilePath_Settings_Saver
close stack tFilePath_Settings_Saver
if AppStore = "yes" then
if gUpdateSettingsSaver = "yes" then
local tSource
local tDestination
local tCommand
put gLibraryDefaultFolder into tDestination
put gPackageFilePath_Settings_Saver into tSource
put ("cp ""e&tSource"e&"e&tDestination"e) into tCommand -- There's no -n in the command, so it WILL overwrite the existing file. http://ss64.com/osx/cp.html
get shell(tCommand)
end if
save stack gLibraryFilePath_Questions
close stack gLibraryFilePath_Questions
save stack gLibraryFilePath_Teams
close stack gLibraryFilePath_Teams
else -- AppStore <> "yes"
save stack gPackageFilePath_Questions
close stack gPackageFilePath_Questions
save stack gPackageFilePath_Teams
close stack gPackageFilePath_Teams
end if
end saveDataStacks
The first "close stack" (close stack tFilePath_Settings_Saver), is intended to close the copy of Settings Saver.rev within the Library/Application Support/Classroom Quizshow/ folder, and, indeed, the "save" command on the previous line does save that stack as verified in the Finder.
When stepping through the code, I can see that stack is NOT closed after executing that step. I determine this by looking at the Application Browser after closing and reopening it to refresh its view. However, by the time I reach the final line of code pasted above, Settings Saver.rev IS closed. The other two "close stack" calls in the script above do NOT close their stacks, at least not by the time we reach the end of the pasted script.
So let me try to boil the problem down: Because of some tricky stack copying I have to do to get the data stacks from their initial home in the application package to their permanent home in the Library folder, I have pairs of stacks with the same name in two different places. I would think I could get by with this perhaps unadvisable situation by diligently closing the stacks after each use, but "close stack" isn't following orders. Help?
One more thing: I'm using LiveCode 5.5.4, build 1502.