Recent

Author Topic: FileExists not run correctly to symlink  (Read 433 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 1782
FileExists not run correctly to symlink
« on: February 08, 2019, 02:41:57 pm »
Hi guys, I have a little problem. I have a program that creates symbolic links on windows using the "mklink \ j destination source" command. If I do a FileExists on the destination after it has been created it does not return true to me. Why? How do I know if a symlink exists? Thank you
Ubuntu and Mac
Lazarus: 1.8.0
FPC: 3.0.4

ASerge

  • Hero Member
  • *****
  • Posts: 1066
Re: FileExists not run correctly to symlink
« Reply #1 on: February 08, 2019, 03:00:09 pm »
I have a program that creates symbolic links on windows using the "mklink \ j destination source" command. If I do a FileExists on the destination after it has been created it does not return true to me. Why? How do I know if a symlink exists?
Details, please. mklink / j make the junction for the DIRECTORY. Not file! Have you tested the existence of a file in this directory or are you using FileExists to check the existence of a directory?

xinyiman

  • Hero Member
  • *****
  • Posts: 1782
Re: FileExists not run correctly to symlink
« Reply #2 on: February 08, 2019, 03:03:55 pm »
I want to know if there is a junction. Are you coming?
Ubuntu and Mac
Lazarus: 1.8.0
FPC: 3.0.4

ASerge

  • Hero Member
  • *****
  • Posts: 1066
Re: FileExists not run correctly to symlink
« Reply #3 on: February 08, 2019, 04:38:29 pm »
I want to know if there is a junction. Are you coming?
So the question is quite different? How determine that a directory is a junction?

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6739
Re: FileExists not run correctly to symlink
« Reply #4 on: February 08, 2019, 07:09:49 pm »
Fixed in trunk afaik (revisions 39668,39669,39671,39672), fileexists has now a followlink parameter

Quote
r39668 svenbarth 2018-08-24 17:33:09 +0200 (Fri, 24 Aug 2018)
+ add Delphi compatible FollowLink parameter (default is True) to FileExists and DirectoryExists; support for it is up to each target
r39669 svenbarth 2018-08-24 17:33:45 +0200 (Fri, 24 Aug 2018)
+ add Delphi-compatible FileGetSymLinkTarget functions to all platforms (currently returns False on all platforms); this also includes TSymLinkRec variants for both RawByteString and UnicodeString
r39671 svenbarth 2018-08-24 17:34:04 +0200 (Fri, 24 Aug 2018)
+ implement FileGetSymLinkTarget() based on patch by Serge Anvarov in Mantis 0032370
r39672 svenbarth 2018-08-24 17:34:09 +0200 (Fri, 24 Aug 2018)
* improve DirectoryExists() and FileExists() based on patch by Serge Anvarov in Mantis 0032370 so that they also support files/directories that aren't accessible (e.g. the page file) as well as FollowLink = False

Afaik they are not merged because it is initial and the per target implementations still have to be done.

xinyiman

  • Hero Member
  • *****
  • Posts: 1782
Re: FileExists not run correctly to symlink
« Reply #5 on: February 12, 2019, 08:50:12 am »
Thank you very much
Ubuntu and Mac
Lazarus: 1.8.0
FPC: 3.0.4