Author Topic: deletedirectory function and symlink dir  (Read 646 times)

n7800

  • Hero Member
  • *****
  • Posts: 779
  • Lazarus IDE contributor
    • GitLab profile
Re: deletedirectory function and symlink dir
« Reply #15 on: September 01, 2026, 02:40:45 pm »
Next time, please attach a link to the issue you created, and within that, a link to the original forum thread so anyone can find them (without having to copy and paste information between them).

https://gitlab.com/freepascal.org/lazarus/lazarus/-/work_items/42561

n7800

  • Hero Member
  • *****
  • Posts: 779
  • Lazarus IDE contributor
    • GitLab profile
Re: deletedirectory function and symlink dir
« Reply #16 on: September 01, 2026, 02:43:10 pm »
gitlab editor : what a pain

In the edit field, in the lower right corner, there's an icon representing Markdown. Clicking it opens the documentation for that markup: https://docs.gitlab.com/user/markdown/

laz_one_or2

  • New Member
  • *
  • Posts: 11
Re: deletedirectory function and symlink dir
« Reply #17 on: September 01, 2026, 08:27:34 pm »
ok will do
thanks  :)

ASerge

  • Hero Member
  • *****
  • Posts: 2518
Re: deletedirectory function and symlink dir
« Reply #18 on: September 02, 2026, 07:21:09 pm »
Note that there are "symbolic links" and "junctions". In the "mklink" command, these are the "/D" and "/J" parameters. The latter does not require elevated privileges.
In windows according Privilege Constants (Authorization): SE_CREATE_SYMBOLIC_LINK_NAME TEXT("SeCreateSymbolicLinkPrivilege"). Required to create a symbolic link. User Right: Create symbolic links.

Only granted to members of the Administrators group by default.

Bart

  • Hero Member
  • *****
  • Posts: 5776
    • Bart en Mariska's Webstek
Re: deletedirectory function and symlink dir
« Reply #19 on: September 02, 2026, 10:31:39 pm »
Yeah, the ones who were always right ("640 K should be enought for everybody") think that symlinks are so dangerour, a normal user cannot be trusted to use them.

Bart

Bart

  • Hero Member
  • *****
  • Posts: 5776
    • Bart en Mariska's Webstek
Re: deletedirectory function and symlink dir
« Reply #20 on: September 02, 2026, 10:33:17 pm »
Anyhow I posted a solution in the bugtracker, which currently I'm unable to push to the Lazarus repo for some reason.
Please test and repost back in the bugtracker.

Bart

laz_one_or2

  • New Member
  • *
  • Posts: 11
Re: deletedirectory function and symlink dir
« Reply #21 on: September 05, 2026, 01:20:31 pm »
i closed the issue on gitlab but i found another little bug.
must i reopen the issue ?

Thaddy

  • Hero Member
  • *****
  • Posts: 19805
  • Glad to be alive.
Re: deletedirectory function and symlink dir
« Reply #22 on: September 05, 2026, 01:47:29 pm »
If the bug is directly related, yes, if it is different open a separate issue.
Any "programmer" that knows only one programming language is not a programmer

laz_one_or2

  • New Member
  • *
  • Posts: 11
Re: deletedirectory function and symlink dir
« Reply #23 on: September 05, 2026, 01:59:36 pm »
ok thanks

Bart

  • Hero Member
  • *****
  • Posts: 5776
    • Bart en Mariska's Webstek
Re: deletedirectory function and symlink dir
« Reply #24 on: September 05, 2026, 07:55:14 pm »
Please continu the discussion in the bugtracker and not here.
Now it's double work for me.

Bart

Bart

  • Hero Member
  • *****
  • Posts: 5776
    • Bart en Mariska's Webstek
Re: deletedirectory function and symlink dir
« Reply #25 on: September 05, 2026, 11:35:33 pm »
I now added an overloaded version (in Lazarus main) with an out parameter indicating which file/dit it was unable to delete.

Bart

Bart

  • Hero Member
  • *****
  • Posts: 5776
    • Bart en Mariska's Webstek
Re: deletedirectory function and symlink dir
« Reply #26 on: September 05, 2026, 11:45:16 pm »
ok thanks

I closed the bugreport.
DeleteDirectory is NOT supposed to be able to delete protected directories like "System Volume Information"

Bart

laz_one_or2

  • New Member
  • *
  • Posts: 11
Re: deletedirectory function and symlink dir
« Reply #27 on: September 05, 2026, 11:59:05 pm »
bart you misunderstood me
please read my comment on gitlab

or not, seem you take me for an idiot, i don't care
« Last Edit: September 06, 2026, 12:00:57 am by laz_one_or2 »

Bart

  • Hero Member
  • *****
  • Posts: 5776
    • Bart en Mariska's Webstek
Re: deletedirectory function and symlink dir
« Reply #28 on: September 06, 2026, 02:01:17 pm »
bart you misunderstood me
Possibly.

please read my comment on gitlab
I did.

The problem is not the faSysFile attribute, which can easily be demostrated by having a file/dir with faSysFile (attrib +s somedir).
RemoveDirUtf8() and DeleteFileUTF8() handle that just fine.
Also files/dirs that have faHidden+faSysFile set will be deleted.
(I did test that).
What they will not delete are files/dirs which a faReadOnly attribute.
You will get an Access Denied error for those.

When I look at my "System Volume Information" folder, it has faHidden + faSysFile set.
When you cannot delete that (I'm NOT insane enough to test that) this means that the folder is somehow protected by the OS, or it may be "in use".

You can query the OS to see what caused the error.
Code: [Select]
  Res := DeleteDirectory('path/to/dir', True);
  writeln('DeleteDirectory(''path/todir'', False) -> ',Res);
  if not Res then writeln('Failure: ',SysErrorMessage(GetLastOSError)');

If I put a readonly file or directory in there, I get: "[Toegang geweigerd."  (Access Denied)
If some subdirectory is in use by another process (e.g. have it open in a console) I get "Het proces heeft geen toegang tot het bestand omdat het door een ander proces wordt gebruikt." (The file is in use by another process) (GetLastOSError = 32)

It would help if you could test this (querying GetLastOSError) in your scenario.


See below my test scenario where I put a file and a dir, both with faSysFile and faHidden attribute, in the "trash" folder.

The test program does:
Code: Pascal  [Select][+][-]
  1.   Res := DeleteDirectory('.\trash', True, Culprit);
  2.   writeln('DeleteDirectory(''.\trash'', False) -> ',Res);
  3.   if not Res then writeln('Culprit=',culprit,', [',GetLastOSError,': ',SysErrorMessage(GetLastOSError),']');

Code: [Select]
C:\Users\Bart\LazarusProjecten\bugs\deldir>cd trash

C:\Users\Bart\LazarusProjecten\bugs\deldir\trash>touch SysHiddenFile

C:\Users\Bart\LazarusProjecten\bugs\deldir\trash>attrib +s +h SysHiddenFile

C:\Users\Bart\LazarusProjecten\bugs\deldir\trash>md SysHiddenDir

C:\Users\Bart\LazarusProjecten\bugs\deldir\trash>attrib +s +h SysHiddenDir

C:\Users\Bart\LazarusProjecten\bugs\deldir\trash>attrib SysHiddenFile
A  SH                C:\Users\Bart\LazarusProjecten\bugs\deldir\trash\SysHiddenFile

C:\Users\Bart\LazarusProjecten\bugs\deldir\trash>attrib SysHiddenDir
   SH                C:\Users\Bart\LazarusProjecten\bugs\deldir\trash\SysHiddenDir

C:\Users\Bart\LazarusProjecten\bugs\deldir\trash>touch NormalFile

C:\Users\Bart\LazarusProjecten\bugs\deldir\trash>md NormalDir

C:\Users\Bart\LazarusProjecten\bugs\deldir\trash>cd..

C:\Users\Bart\LazarusProjecten\bugs\deldir>test
DeleteDirectory('.\trash', False) -> TRUE
Heap dump by heaptrc unit of C:\Users\Bart\LazarusProjecten\bugs\deldir\test.exe
1621 memory blocks allocated : 1021261/1023336
1621 memory blocks freed     : 1021261/1023336
0 unfreed memory blocks : 0
True heap size : 262144 (112 used in System startup)
True free heap : 262032

C:\Users\Bart\LazarusProjecten\bugs\deldir>dir trash
 Volume in drive C is Windows
 Volume Serial Number is 10B3-BFD1

 Directory of C:\Users\Bart\LazarusProjecten\bugs\deldir\trash

06-09-2026  13:46    <DIR>          .
06-09-2026  13:41    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  820.010.442.752 bytes free

C:\Users\Bart\LazarusProjecten\bugs\deldir>rd trash

C:\Users\Bart\LazarusProjecten\bugs\deldir>dir trash
 Volume in drive C is Windows
 Volume Serial Number is 10B3-BFD1

 Directory of C:\Users\Bart\LazarusProjecten\bugs\deldir

File Not Found

Notice the last "rd trash" this returns without error, so each and every file/dir inside trash must have been deleted by the test program.



Even so: it still may be possible that I misunderstand you.
If that is the case then please re-open the issue in the bugtracker and continue the discussion there.
(If you just add notes to the issue without opening, I won't notice.)

Note: your proposed fix in the bugtracker will only help if the file/dir in question is NOT in a subdir of the folder you are trying to delete (or OnlyChildren=False), because it will subsequently fail to delete that directory once all other files in it are deleted.

or not, seem you take me for an idiot, i don't care
There's no reason to insult me when I'm trying to help you out here.

Bart
« Last Edit: September 06, 2026, 10:02:11 pm by Bart »

 

TinyPortal © 2005-2018