sal/osl/unx/file_stat.cxx |   65 +++++++---------------------------------------
 1 file changed, 11 insertions(+), 54 deletions(-)

New commits:
commit fb2078addcbd96662283b2481206eee7ce3d50b6
Author: Stephan Bergmann <sberg...@redhat.com>
Date:   Mon Dec 19 16:47:13 2011 +0100

    Clean up previous commit.

diff --git a/sal/osl/unx/file_stat.cxx b/sal/osl/unx/file_stat.cxx
index 6b2407a..949121f 100644
--- a/sal/osl/unx/file_stat.cxx
+++ b/sal/osl/unx/file_stat.cxx
@@ -101,73 +101,14 @@ namespace /* private */
         pStat->uValidFields |= osl_FileStatus_Mask_Attributes;
     }
 
-    inline void set_file_access_rights(const struct stat& file_stat, int S_IR, 
int S_IW, int S_IX, oslFileStatus* pStat)
-    {
-        /* we cannot really map osl_File_Attribute_ReadOnly to
-           the Unix access rights, it's a Windows only flag
-           that's why the following hack. We set osl_FileStatus_Mask_Attributes
-           but if there is no read access for a file we clear the flag
-           again to signal to the caller that there are no file attributes
-           to read because that's better than to give them incorrect one.
-        */
-        pStat->uValidFields |= osl_FileStatus_Mask_Attributes;
-
-        if ((0 == (S_IW & file_stat.st_mode)) && (S_IR & file_stat.st_mode))
-            pStat->uAttributes |= osl_File_Attribute_ReadOnly;
-
-        if (S_IX & file_stat.st_mode)
-            pStat->uAttributes |= osl_File_Attribute_Executable;
-    }
-
-    /* a process may belong to up to NGROUPS_MAX groups, so when
-       checking group access rights, we have to check all belonging
-       groups */
-    inline bool is_in_process_grouplist(const gid_t file_group)
-    {
-        // check primary process group
-
-        if (getgid() == file_group)
-            return true;
-
-        // check supplementary process groups
-
-        gid_t grplist[NGROUPS_MAX];
-        int   grp_number = getgroups(NGROUPS_MAX, grplist);
-
-        for (int i = 0; i < grp_number; i++)
-        {
-            if (grplist[i] == file_group)
-                return true;
-        }
-        return false;
-    }
-
-    /* Currently we are determining the file access right based
-       on the real user ID not the effective user ID!
-       We don't use access(...) because access follows links which
-       may cause performance problems see #97133.
+    /* This code used not to use access(...) because access follows links which
+       may cause performance problems see #97133.  (That apparently references 
a
+       no-longer accessible Hamburg-internal bug-tracking system.)
+       However, contrary to what is stated above the use of access calls is
+       required on network file systems not using unix semantics (AFS, see
+       fdo#43095).
     */
-    inline void set_file_access_rights(const struct stat& file_stat, 
oslFileStatus* pStat)
-    {
-        if (getuid() == file_stat.st_uid)
-        {
-            set_file_access_rights(file_stat, S_IRUSR, S_IWUSR, S_IXUSR, 
pStat);
-        }
-        else if (is_in_process_grouplist(file_stat.st_gid))
-        {
-            set_file_access_rights(file_stat, S_IRGRP, S_IWGRP, S_IXGRP, 
pStat);
-        }
-        else
-        {
-            set_file_access_rights(file_stat, S_IROTH, S_IWOTH, S_IXOTH, 
pStat);
-        }
-    }
-
-    /* contrary to what is stated above the use of access calls
-       is required on network file systems not using unix semantics
-      (AFS)
-    */
-    inline void set_file_access_real_rights(const rtl::OUString& file_path, 
oslFileStatus* pStat)
+    inline void set_file_access_rights(const rtl::OUString& file_path, 
oslFileStatus* pStat)
     {
         pStat->uValidFields |= osl_FileStatus_Mask_Attributes;
 
@@ -193,15 +134,10 @@ namespace /* private */
         set_file_hidden_status(file_path, pStat);
         set_file_access_mask(file_stat, pStat);
 
-#ifdef FAKE_ACCESS_RIGHTS
         // we set the file access rights only on demand
         // because it's potentially expensive
         if (uFieldMask & osl_FileStatus_Mask_Attributes)
-               set_file_access_rights(file_stat, pStat);
-#else
-        if (uFieldMask & osl_FileStatus_Mask_Attributes)
-            set_file_access_real_rights(file_path, pStat);
-#endif
+            set_file_access_rights(file_path, pStat);
     }
 
     inline void set_file_access_time(const struct stat& file_stat, 
oslFileStatus* pStat)
commit 32a6a0891fb5f2d893cca656cd44afd0bcbe3272
Author: Moritz Bechler <mbech...@eenterphace.org>
Date:   Mon Dec 19 16:36:31 2011 +0100

    fdo#43095: allow the use of real access() calls

diff --git a/sal/osl/unx/file_stat.cxx b/sal/osl/unx/file_stat.cxx
index 674e603..6b2407a 100644
--- a/sal/osl/unx/file_stat.cxx
+++ b/sal/osl/unx/file_stat.cxx
@@ -163,6 +163,22 @@ namespace /* private */
         }
     }
 
+    /* contrary to what is stated above the use of access calls
+       is required on network file systems not using unix semantics
+      (AFS)
+    */
+    inline void set_file_access_real_rights(const rtl::OUString& file_path, 
oslFileStatus* pStat)
+    {
+        pStat->uValidFields |= osl_FileStatus_Mask_Attributes;
+
+        if (access_u(file_path.pData, W_OK) < 0)
+            pStat->uAttributes |= osl_File_Attribute_ReadOnly;
+
+        if (access_u(file_path.pData, X_OK) == 0)
+            pStat->uAttributes |= osl_File_Attribute_Executable;
+    }
+
+
     inline void set_file_hidden_status(const rtl::OUString& file_path, 
oslFileStatus* pStat)
     {
         pStat->uAttributes   = 
osl::systemPathIsHiddenFileOrDirectoryEntry(file_path) ? 
osl_File_Attribute_Hidden : 0;
@@ -177,10 +193,15 @@ namespace /* private */
         set_file_hidden_status(file_path, pStat);
         set_file_access_mask(file_stat, pStat);
 
+#ifdef FAKE_ACCESS_RIGHTS
         // we set the file access rights only on demand
         // because it's potentially expensive
         if (uFieldMask & osl_FileStatus_Mask_Attributes)
                set_file_access_rights(file_stat, pStat);
+#else
+        if (uFieldMask & osl_FileStatus_Mask_Attributes)
+            set_file_access_real_rights(file_path, pStat);
+#endif
     }
 
     inline void set_file_access_time(const struct stat& file_stat, 
oslFileStatus* pStat)
_______________________________________________
Libreoffice-commits mailing list
Libreoffice-commits@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to