Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make AtExit a stack and make DirectoryTemporary more robust #2856

Merged
merged 2 commits into from
Sep 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/files.gd
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,11 @@ DeclareGlobalFunction( "RemoveDirectoryRecursively" );
InstallAtExit( function()
local path;
for path in GAPInfo.DirectoriesTemporary do
RemoveDirectoryRecursively(path);
if IsDir(path) = 'D' then
RemoveDirectoryRecursively(path);
else
PRINT_TO("*errout*", "Temporary directory already removed: ", path, "\n");
fi;
od;
end );

Expand Down
5 changes: 3 additions & 2 deletions lib/session.g
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ end);
BIND_GLOBAL("PROGRAM_CLEAN_UP", function()
local f;
if IsBound( GAPInfo.AtExitFuncs ) and IsList( GAPInfo.AtExitFuncs ) then
for f in GAPInfo.AtExitFuncs do
while not IsEmpty(GAPInfo.AtExitFuncs) do
f := Remove(GAPInfo.AtExitFuncs);
if IsFunction(f) then
CALL_WITH_CATCH(f,[]); # really should be CALL_WITH_CATCH here
CALL_WITH_CATCH(f,[]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe, nice comment :)

fi;
od;
fi;
Expand Down
6 changes: 6 additions & 0 deletions tst/testspecial/at-exit.g
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Check InstallAtExit is run in reverse order
InstallAtExit(function() Print("First Call\n"); end);

# Check InstallAtExit recovers from Errors
InstallAtExit(function() Print("Step 1\n"); Error("ERROR!"); Print("Step 2\n"); end);
InstallAtExit(function() Print("Last Call\n"); end);
11 changes: 11 additions & 0 deletions tst/testspecial/at-exit.g.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
gap> # Check InstallAtExit is run in reverse order
gap> InstallAtExit(function() Print("First Call\n"); end);
gap>
gap> # Check InstallAtExit recovers from Errors
gap> InstallAtExit(function() Print("Step 1\n"); Error("ERROR!"); Print("Step 2\n"); end);
gap> InstallAtExit(function() Print("Last Call\n"); end);
gap> QUIT;
Last Call
Step 1
Error, ERROR!
First Call