Преглед изворни кода

* fixed file locking of files opened as read- or write-only on solaris
(locking is based on fcntl there, and that one cannot create an
exclusive lock for a read-only file or a shared lock for a write-only
file)

git-svn-id: trunk@12633 -

Jonas Maebe пре 16 година
родитељ
комит
9fabb0b127
1 измењених фајлова са 19 додато и 5 уклоњено
  1. 19 5
      rtl/unix/sysutils.pp

+ 19 - 5
rtl/unix/sysutils.pp

@@ -185,7 +185,21 @@ begin
 {$ifndef beos}
   if (Handle>=0) then
     begin
-      case (mode and (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)) = fmShareCompat) then
+        begin
+          mode := mode and not(fmShareCompat);
+          if ((mode and (fmOpenRead or fmOpenWrite or fmOpenReadWrite)) = fmOpenRead) then
+            mode := mode or fmShareDenyWrite
+          else
+            mode := mode or fmShareExclusive;
+        end;
+{$endif solaris}
+      case (mode and (fmShareCompat or fmShareExclusive or fmShareDenyWrite or fmShareDenyRead)) of
         fmShareCompat,
         fmShareExclusive:
           lockop:=LOCK_EX or LOCK_NB;
@@ -224,10 +238,10 @@ Var
   LinuxFlags : longint;
 begin
   LinuxFlags:=0;
-  Case (Mode and 3) of
-    0 : LinuxFlags:=LinuxFlags or O_RdOnly;
-    1 : LinuxFlags:=LinuxFlags or O_WrOnly;
-    2 : LinuxFlags:=LinuxFlags or O_RdWr;
+  case (Mode and (fmOpenRead or fmOpenWrite or fmOpenReadWrite)) of
+    fmOpenRead : LinuxFlags:=LinuxFlags or O_RdOnly;
+    fmOpenWrite : LinuxFlags:=LinuxFlags or O_WrOnly;
+    fmOpenReadWrite : LinuxFlags:=LinuxFlags or O_RdWr;
   end;
   FileOpen:=fpOpen (pointer(FileName),LinuxFlags);