瀏覽代碼

* hopefully final fix to unix locking: specifying no locking mode again
means "exclusive lock" where supported (not on Solaris when opening
a file in read-only mode)

git-svn-id: trunk@12675 -

Jonas Maebe 16 年之前
父節點
當前提交
6581c8dec5
共有 1 個文件被更改,包括 16 次插入2 次删除
  1. 16 2
      rtl/unix/sysutils.pp

+ 16 - 2
rtl/unix/sysutils.pp

@@ -185,12 +185,26 @@ begin
 {$ifndef beos}
   if (Handle>=0) then
     begin
-      case (mode and (fmShareCompat or fmShareExclusive or fmShareDenyWrite or fmShareDenyRead)) of
+{$ifdef solaris}
+      { Solaris' flock is based on top of fcntl, which does not allow
+        exclusive locks for files only opened for reading nor shared
+        locks for files opened only for writing
+      }
+      if ((mode and (fmShareCompat or fmShareExclusive or fmShareDenyWrite or fmShareDenyRead)) = 0) then
+        begin
+          mode := mode and not(fmShareCompat);
+          if ((mode and (fmOpenRead or fmOpenWrite or fmOpenReadWrite)) = fmOpenWrite) then
+            mode := mode or fmShareExclusive
+          else
+            mode := mode or fmShareDenyWrite;
+        end;
+{$endif solaris}
+      case (mode and (fmShareCompat or fmShareExclusive or fmShareDenyWrite or fmShareDenyRead or fmShareDenyNone)) of
+        fmShareCompat,
         fmShareExclusive:
           lockop:=LOCK_EX or LOCK_NB;
         fmShareDenyWrite:
           lockop:=LOCK_SH or LOCK_NB;
-        fmShareCompat,
         fmShareDenyNone:
           exit;
         else