TFileStream can't open a file from network drive in second app lazarus / 33-macOS - Mac OS X ---------------------------------------------------------------------- Igor · 2020-12-15 10:52 TFileStream can't open a file from a network drive (SMB or AFP), if I already opened this file in another instance of the same app (or another Lazarus app) using TFileStream: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Result:=TFileStream.Create(UTF8Encode(FN), fmOpenRead or fmShareDenyWrite); Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i /Volumes/igor/test.mov However I can open this file in another app on Mac (VLC player). I correctly set access parameters, but it seems that TFileStream locks a file after openning and another app can't open it with TFileStream. This problem doesn't occur with a local file. I attach a simple test app. UPDATE. I tried to replace TFileStream with functions from FpOpen and these new functions work fine to read the same file from SMB or AFP network from two apps. Lazarus 2.0.10 / FPC 3.2.0. macOS Big Sur / Catalina ---------------------------------------------------------------------- rvk · 2020-12-15 12:47 What happens if you use fmShareDenyNone? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Result:=TFileStream.Create(UTF8Encode(FN), fmOpenRead or fmShareDenyNone); (Of course in both Apps !!) ---------------------------------------------------------------------- Igor · 2020-12-15 13:12 Yes, we tried with fmShareDenyNone - the same result. P.S. The app is the same (I run it twice in two Terminal app). Also I tried with two different apps - as soon I open a file with TFileStream from network drive, I cannot open it in a new TFileStream in another app. I observe this problem on 3 Macs (Catalina, Big Sur) with differente networks (WD Live with AFP protocol) and Windows 10 Pro network (Samba). ---------------------------------------------------------------------- rvk · 2020-12-15 13:39 For me, your example works fine on Windows/Lazarus trunk. On a Linux variant you could use smbstatus to see how the files are opened. On Windows you could look in the computer management in Open Files to see how it's opened. (I don't have an Apple so can't test it on that) ---------------------------------------------------------------------- Igor · 2020-12-15 14:03 This problem doesn't occur on Windows. I checked in macOS. The problem can be reproduced with a very simple Lazarus code on any type of network - SMB or AFP. But this problem doesn't occur with other apps (file managers, VLC, etc). I don't understand why it happens. ---------------------------------------------------------------------- Igor · 2020-12-15 17:51 I tried to replace TFileStream with functions from FpOpen and these new functions work fine to read the same file from SMB or AFP network from two apps. ---------------------------------------------------------------------- PascalDragon · 2020-12-16 08:25 TFileStream.Create uses SysUtils.FileOpen which in turn uses FpOpen (see $fpcdir/rtl/unix/sysutils.pp at around line 419). What it also does is to lock the file (Unix based systems use advisory locking instead of mandatory locking as Windows does). Maybe you can play around with that code a bit to find out what goes wrong. For that you could copy the code of FileOpen, FileOpenNoLocking and DoFileLocking (as well as any private constants, etc.) to your own program and try to use them (TFileStream.Create simply passes its arguments to FileOpen). ---------------------------------------------------------------------- Igor · 2020-12-16 11:01 We didn't use fpflock() Probably fpflock() doesn't work correctly for a file from a network drive in macOS? We'll try to modify our code to check if use of fpflock() cause the same problem as TFileStream