TFileSystem.DelDirTree recurses into every entry with faDirectory. A directory junction or symbolic link to a directory has that attribute too, so DelDirTree goes through the link, deletes every file of the target, and then removes the link. The target directory stays, empty.
Measured with Delphi 12 Win32: sb\tree contains file.txt and a junction link to sb\target (mklink /J), and sb\target contains keep.txt. After TFileSystem.DelDirTree('sb\tree', True, False), which returned True, sb\tree and the junction are gone, sb\target still exists, and sb\target\keep.txt is deleted.
So deleting a tree that holds a link to real data destroys that data. DelTree, the destructor of TUniqueTempDir (unless DeleteOnlyIfEmpty) and TDirectorySync go through DelDirTree too.
A junction or directory symlink should be removed as a link (RemoveDirectory on the link removes only the link), without descending into it. Only the reparse tags IO_REPARSE_TAG_MOUNT_POINT and IO_REPARSE_TAG_SYMLINK (in FindData.dwReserved0) mark such links. Other reparse points, such as OneDrive folders with files on demand, are ordinary directories.
Found while measuring [bugs:#99].
Fixed in revision [r2529]. Correction to the description:
TDirectorySyncdoes not callDelDirTree; its own recursion follows links too, see [bugs:#102].Related
Bug Reports:
#102Commit: [r2529]