Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2026-09

TDirectory.Delete(SomePath, True) possibly silenty deletes the contents of symlinks/junctions

3 messages · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bart

Hi,

On Lazarus there has been a bugreport that DeleteDirectory follows symlinks and unexpectedly removes their contents instead of just deleting the symlink (or junction).
See: https://gitlab.com/freepascal.org/lazarus/lazarus/-/work_items/42561

I noticed that the DeleteDirectory() function in System.IOUtils follows the same codepath, so this will probably happen as well. (I did not specifically test this though).

It also may very well be that this is exactly what Delphi does, but IMO that would be just horrible then..
(I cannot test this, since the latest Delphi I own is D7 PE, and I'm unwilling to install their community edition, I'ld rathe keep my laptop sort of clean)

Secondly I also noticed that Delphi says it raises an exception if the directory does not exist, but I think fpc does not :
- the result of RemoveDir or DeleteDirectory is not checked
- the result of DeleteDirecory is True if call it on a non-existing path with OnlyChildren=True (since in that case FindFirst will not return 0, and there will be no consecutive call to RemoveDir(NonExistingPath)

Should I file a bugreport for those issues?

Bart

Reply by email

Bart
to Bart
Secondly I also noticed that Delphi says it raises an exception if the directory does not exist, but I think fpc does not : - the result of RemoveDir or DeleteDirectory is not checked
Well, the result  of RemoveDir() is not check in case of
TDeleteDirectory.Delete(Path);
Bart

Reply by email