Explorar o código

* fmShareDenyNone should also take a shared lock (+ test)

git-svn-id: trunk@30877 -
Jonas Maebe %!s(int64=10) %!d(string=hai) anos
pai
achega
9b987fde93
Modificáronse 3 ficheiros con 26 adicións e 3 borrados
  1. 1 0
      .gitattributes
  2. 2 3
      rtl/unix/sysutils.pp
  3. 23 0
      tests/webtbs/tw27998a.pp

+ 1 - 0
.gitattributes

@@ -14487,6 +14487,7 @@ tests/webtbs/tw27880.pp svneol=native#text/plain
 tests/webtbs/tw2789.pp svneol=native#text/plain
 tests/webtbs/tw2794.pp svneol=native#text/plain
 tests/webtbs/tw27998.pp svneol=native#text/plain
+tests/webtbs/tw27998a.pp svneol=native#text/plain
 tests/webtbs/tw28007.pp svneol=native#text/pascal
 tests/webtbs/tw2803.pp svneol=native#text/plain
 tests/webtbs/tw2806.pp svneol=native#text/plain

+ 2 - 3
rtl/unix/sysutils.pp

@@ -396,10 +396,9 @@ begin
         fmShareCompat,
         fmShareExclusive:
           lockop:=LOCK_EX or LOCK_NB;
-        fmShareDenyWrite:
-          lockop:=LOCK_SH or LOCK_NB;
+        fmShareDenyWrite,
         fmShareDenyNone:
-          exit;
+          lockop:=LOCK_SH or LOCK_NB;
         else
           begin
             { fmShareDenyRead does not exit under *nix, only shared access

+ 23 - 0
tests/webtbs/tw27998a.pp

@@ -0,0 +1,23 @@
+program a;
+{$mode delphi}
+uses
+  SysUtils, Classes;
+const
+  LockFile = 'lock.txt';
+var
+  H, H2 : TStream;
+begin
+  try
+    H := TFileStream.Create(lockFile, fmCreate);
+    { should raise exception because of exclusive lock above }
+    H2 := TFileStream.create(LockFile, fmOpenRead or fmShareDenyNone);
+    H2.free;
+    H.free;
+    DeleteFile(LockFile);
+    halt(1);
+  except
+    H.free;
+    DeleteFile(LockFile);
+  end
+end.
+