Island FileExists

Hi,
I noticed that FileExists hasnt been implemented when your on Darwin.

I was also looking at the RTL2 implementation and it calls the Island when its not Toffee

In some cases like MacOS would it be ok to call the Toffee implementation ?

Cheers,
John

Thanks, logged as bugs://85520

Ouch. Sorry about that.

Thanks.

Im not sure if you missed my question at the end. With this piece of code

  {$ELSEIF TOFFEE}
  var isDirectory := false;
  result := NSFileManager.defaultManager.fileExistsAtPath(mapped) isDirectory(var isDirectory) and not isDirectory;
  {$ELSEIF ECHOES}

is it ok to do {$ELSEIF DARWIN} instead rather than going into the ISLAND section ?

if the Toffee implementation is is using pure Cocoa Apis, either would be fine, yes. In most cases (such as this one, if it were implemented ;), the Island FRTL version would probably use the same API that the TOFFEE define does.

so the above could be written with IF DARWIN instead of IF TOFFEE, and work. it comes down to (admittedly academic) consistency, I suppose. Would we rather have the same code path for all island platforms, or the same code path for all Cocoa platforms (even iff it then differs between Island/Darwin vs the other Island platforms.

If all the abstractions are implemented 100% perfect; it should make no difference to the end user; bt for cases where there are leaky abstractions, it might. Say, if Island RTL implemented Exists on its down and it differed subtly (a stretch for a function as simple as this one, but go with it). That’d be a bug, but would we rather have not broken between Island/Darwin vs Island/Windows (say), or consistent for Island, but broken between Island and Toffee?

THAT all said:

    class method FileExists(aFullName: not nullable String): Boolean;
    begin
      {$IFDEF WINDOWS}
      exit IsFile(rtl.GetFileAttributesW(aFullName.ToFileName()));
      {$ELSEIF POSIX}
      exit IsFile(FileUtils.Get__struct_stat(aFullName)^.st_mode);
      {$ELSE}{$ERROR}
      {$ENDIF}
    end;

Darwin is POSIX, so this should work fine… Also, it it wasn’t POSIX, then this would actually fail at compile time, due to there {$ERROR}.

If it’s not working for you (your post indicate whether it does), that’s be an issue to investigate separately…

bugs://85520 got closed with status nochangereq.

FileExistsConsoleApplication.zip (1.2 MB)

When the file doesn’t exist I get

An exception occurred in FileExistsConsoleApplication, thread 898B

Type: RemObjects.Elements.System.Exception

Message:

errno is 2

Call Stack:

000000010345B9C0 _ElementsRaiseException FileExistsConsoleApplication
000000010345F6A3 _ms_td__1s____Globalf_CheckForIOErrorni32 FileExistsConsoleApplication
0000000103468694 _mi_t7__1sFile6_Exists FileExistsConsoleApplication
00000001033ED054 FileExistsConsoleApplication.Program.Main FileExistsConsoleApplication (Program.pas, line 14)
00000001033ECE59 ___elements_entry_point FileExistsConsoleApplication
00007FFF6B207CC9 _start libdyld.dylib

It returns true when it does.

FileExistsConsoleApplication.zip (627.2 KB)

This is a better example just using the Island library

Thanks, logged as bugs://85524

bugs://85524 got closed with status fixed.

Thanks. This is fixed.

2 Likes