Jump to content
Sign in to follow this  
ToddFrankson

MacOS and Locking a File

Recommended Posts

So I use the following code on windows:

...

FileMk:THandle

...

If ((FileMk=INVALID_HANDLE_VALUE ) and System.SysUtils.FileExists(tempName)) then
                  FileMk:=FileOpen(tempName,fmExclusive or fmShareExclusive);

...

 

Works Fine on windows.  For the average person they can't copy the file, open the file, rename the file, etc....

 

It doesn't work on MACOS.  I have been looking all over the interwebs and really haven't found much.  Does anyone know how to accomplish the same feat on MacOS?  

Share this post


Link to post

I cannot contribute how to solve this, but having dealt mostly with Windows I also was surprised recently to find out about how differently this is handled on other platforms like macOS or Linux.

 

Delphi's standard library was initially built for Windows and suggests you could easily enforce this on other platforms as well. For other languages like C++ or Rust, the standard library's file access mechanism don't even support any way "sharing" or "locking". Their default implementation is even "Don't lock anything, allow everything" which I found surprising. Maybe that was just my old Windows habits.

Share this post


Link to post
1 hour ago, Der schöne Günther said:

I cannot contribute how to solve this, but having dealt mostly with Windows I also was surprised recently to find out about how differently this is handled on other platforms like macOS or Linux.

 

 

Me too.  Some of the other platforms make no sense to me.  Especially the API's

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×