diff --git a/lib/files.gi b/lib/files.gi index 6ec708ff65..c4cd489017 100644 --- a/lib/files.gi +++ b/lib/files.gi @@ -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 diff --git a/tst/testinstall/kernel/streams.tst b/tst/testinstall/kernel/streams.tst index c83b6474d2..1f550dd6c0 100644 --- a/tst/testinstall/kernel/streams.tst +++ b/tst/testinstall/kernel/streams.tst @@ -172,6 +172,30 @@ Error, RemoveDir: must be a string (not the value 'fail') gap> IsDir(fail); Error, IsDir: 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: must be a string (not the value 'fail')