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

Fix RemoveDirectoryRecursively for immutable argument #5584

Merged
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
3 changes: 2 additions & 1 deletion lib/files.gi
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ InstallGlobalFunction(RemoveDirectoryRecursively,
Error("dirname must be a directory");
return fail;
fi;
while Length(dirname) > 0 and dirname[Length(dirname)] = '/' do
dirname := ShallowCopy(dirname);
while Length(dirname) > 0 and Last(dirname) = '/' do
Remove(dirname);
od;
if Length(dirname) = 0 then
Expand Down
24 changes: 24 additions & 0 deletions tst/testinstall/kernel/streams.tst
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,30 @@ Error, RemoveDir: <filename> must be a string (not the value 'fail')
gap> IsDir(fail);
Error, IsDir: <filename> must be a string (not the value 'fail')

#
gap> tmpdir := MakeImmutable(TmpDirectory());;
gap> subdir := MakeImmutable(Concatenation(tmpdir, "/subdir"));;
gap> CreateDir(subdir);
true
gap> IsDir(subdir);
'D'
gap> RemoveDir(subdir);
true
gap> IsDir(subdir);
fail
gap> CreateDir(subdir);
true
gap> FileString(Concatenation(subdir, "/file"), "data");
4
gap> IsDir(subdir);
'D'
gap> RemoveDirectoryRecursively(tmpdir);
true
gap> IsDir(subdir);
fail
gap> IsDir(tmpdir);
fail

#
gap> IsExistingFile(fail);
Error, IsExistingFile: <filename> must be a string (not the value 'fail')
Expand Down