Recent

Author Topic: FileExists /Applications/Safari.app returns false  (Read 292 times)

MISV

  • Hero Member
  • *****
  • Posts: 701
FileExists /Applications/Safari.app returns false
« on: September 28, 2020, 11:48:36 am »
Are you having this problem as well?

FileExists('/Applications/Safari.app') returns false

apparently even for a notarized (no entitlements) and signed app...?


Hansaplast

  • Hero Member
  • *****
  • Posts: 599
  • Tweaking4All.com
    • Tweaking4All
Re: FileExists /Applications/Safari.app returns false
« Reply #1 on: September 28, 2020, 11:53:46 am »
A .app "file" is actually a directory under macOS.
You'll need to use:


Code: Pascal  [Select][+][-]
  1. DirectoryExists('/Applications/Safari.app')

Thaddy

  • Hero Member
  • *****
  • Posts: 10526
Re: FileExists /Applications/Safari.app returns false
« Reply #2 on: September 28, 2020, 12:01:04 pm »
@Hansaplast

Actually it is the other way around: A directory is always a file under Unix and derivatives. "Everything is a file" adagium.
What happens here is that recently, to avoid platform confusion, directories are filtered out from FileExists calls and DirectoryExists should be used instead for directories, it filters the other way around  ;D.
Technically, the new behavior is not Unix compliant in any way, but it helps the cross-platform nature of FPC and Lazarus.
I believe that 3.0.4 still has the old behavior and that the new behavior is back-ported to 3.2.0 (or maybe 3.2.1)

Note that I actually quite like this new behavior since I have lots of code that should compile on both Windows and Linux with the same consistent behavior.

(note to self: I have to check if devices are also filtered, because these are also files and maybe should not be shown.)
« Last Edit: September 28, 2020, 12:31:16 pm by Thaddy »

Hansaplast

  • Hero Member
  • *****
  • Posts: 599
  • Tweaking4All.com
    • Tweaking4All
Re: FileExists /Applications/Safari.app returns false
« Reply #3 on: September 28, 2020, 12:49:21 pm »
Thanks Thaddy  :)
Excellent explanation - I wasn't even thinking about the details in that much depth, and you're absolutely right.


I just use DirectoryExists to check if the .app file/dir exists, since it lists as a directory in Terminal as well.


Code: Pascal  [Select][+][-]
  1. drwxr-xr-x@  3 root  wheel      96 Sep 17 15:24 Safari.app


Note:
I just tested FileExists and DirectoryExists in Lazarus 2.1.0 r63882 FPC 3.3.1 x86_64-darwin-cocoa
FileExists fails on checking "/Applications/Safari.app", but DirectoryExists works correct (as expected).
Not sure if this is helpful for you when checking.

MISV

  • Hero Member
  • *****
  • Posts: 701
Re: FileExists /Applications/Safari.app returns false
« Reply #4 on: September 29, 2020, 08:52:52 am »
Thank you everyone! Appears to work now :)

 

TinyPortal © 2005-2018