Do not follow symbolic links for G_FILE_TEST_SYMLINK. Also fixed the
authorSebastian Wilhelmi <wilhelmi@ira.uka.de>
Thu, 7 Feb 2002 20:14:00 +0000 (20:14 +0000)
committerSebastian Wilhelmi <wilhelmi@src.gnome.org>
Thu, 7 Feb 2002 20:14:00 +0000 (20:14 +0000)
2002-02-07  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>

* glib/gfileutils.c (g_file_test): Do not follow symbolic links
for G_FILE_TEST_SYMLINK. Also fixed the correct "OR"-behaviour for
G_FILE_TEST_IS_EXECUTABLE and G_FILE_TEST_EXISTS. (#60048)

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
glib/gfileutils.c

index e3cee67..46e3b26 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2002-02-07  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * glib/gfileutils.c (g_file_test): Do not follow symbolic links
+       for G_FILE_TEST_SYMLINK. Also fixed the correct "OR"-behaviour for
+       G_FILE_TEST_IS_EXECUTABLE and G_FILE_TEST_EXISTS. (#60048)
+
 2002-02-07  Changwoo Ryu  <cwryu@debian.org>
 
        * configure.in (ALL_LINGUAS): Added "ko".
index e3cee67..46e3b26 100644 (file)
@@ -1,3 +1,9 @@
+2002-02-07  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * glib/gfileutils.c (g_file_test): Do not follow symbolic links
+       for G_FILE_TEST_SYMLINK. Also fixed the correct "OR"-behaviour for
+       G_FILE_TEST_IS_EXECUTABLE and G_FILE_TEST_EXISTS. (#60048)
+
 2002-02-07  Changwoo Ryu  <cwryu@debian.org>
 
        * configure.in (ALL_LINGUAS): Added "ko".
index e3cee67..46e3b26 100644 (file)
@@ -1,3 +1,9 @@
+2002-02-07  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * glib/gfileutils.c (g_file_test): Do not follow symbolic links
+       for G_FILE_TEST_SYMLINK. Also fixed the correct "OR"-behaviour for
+       G_FILE_TEST_IS_EXECUTABLE and G_FILE_TEST_EXISTS. (#60048)
+
 2002-02-07  Changwoo Ryu  <cwryu@debian.org>
 
        * configure.in (ALL_LINGUAS): Added "ko".
index e3cee67..46e3b26 100644 (file)
@@ -1,3 +1,9 @@
+2002-02-07  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * glib/gfileutils.c (g_file_test): Do not follow symbolic links
+       for G_FILE_TEST_SYMLINK. Also fixed the correct "OR"-behaviour for
+       G_FILE_TEST_IS_EXECUTABLE and G_FILE_TEST_EXISTS. (#60048)
+
 2002-02-07  Changwoo Ryu  <cwryu@debian.org>
 
        * configure.in (ALL_LINGUAS): Added "ko".
index e3cee67..46e3b26 100644 (file)
@@ -1,3 +1,9 @@
+2002-02-07  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * glib/gfileutils.c (g_file_test): Do not follow symbolic links
+       for G_FILE_TEST_SYMLINK. Also fixed the correct "OR"-behaviour for
+       G_FILE_TEST_IS_EXECUTABLE and G_FILE_TEST_EXISTS. (#60048)
+
 2002-02-07  Changwoo Ryu  <cwryu@debian.org>
 
        * configure.in (ALL_LINGUAS): Added "ko".
index e3cee67..46e3b26 100644 (file)
@@ -1,3 +1,9 @@
+2002-02-07  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * glib/gfileutils.c (g_file_test): Do not follow symbolic links
+       for G_FILE_TEST_SYMLINK. Also fixed the correct "OR"-behaviour for
+       G_FILE_TEST_IS_EXECUTABLE and G_FILE_TEST_EXISTS. (#60048)
+
 2002-02-07  Changwoo Ryu  <cwryu@debian.org>
 
        * configure.in (ALL_LINGUAS): Added "ko".
index e3cee67..46e3b26 100644 (file)
@@ -1,3 +1,9 @@
+2002-02-07  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * glib/gfileutils.c (g_file_test): Do not follow symbolic links
+       for G_FILE_TEST_SYMLINK. Also fixed the correct "OR"-behaviour for
+       G_FILE_TEST_IS_EXECUTABLE and G_FILE_TEST_EXISTS. (#60048)
+
 2002-02-07  Changwoo Ryu  <cwryu@debian.org>
 
        * configure.in (ALL_LINGUAS): Added "ko".
index e3cee67..46e3b26 100644 (file)
@@ -1,3 +1,9 @@
+2002-02-07  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * glib/gfileutils.c (g_file_test): Do not follow symbolic links
+       for G_FILE_TEST_SYMLINK. Also fixed the correct "OR"-behaviour for
+       G_FILE_TEST_IS_EXECUTABLE and G_FILE_TEST_EXISTS. (#60048)
+
 2002-02-07  Changwoo Ryu  <cwryu@debian.org>
 
        * configure.in (ALL_LINGUAS): Added "ko".
index c14cea1..aa4d104 100644 (file)
  * the check whether it's a directory doesn't matter since the existence 
  * test is %TRUE. With the current set of available tests, there's no point
  * passing in more than one test at a time.
+ * 
+ * Apart from #G_FILE_TEST_IS_SYMLINK all tests follow symbolic links,
+ * so for a symbolic link to a regular file g_file_test() will return
+ * %TRUE for both #G_FILE_TEST_IS_SYMLINK and #G_FILE_TEST_IS_REGULAR.
  *
  * Return value: whether a test was %TRUE
  **/
@@ -83,29 +87,35 @@ gboolean
 g_file_test (const gchar *filename,
              GFileTest    test)
 {
-  if (test & G_FILE_TEST_EXISTS)
-    return (access (filename, F_OK) == 0);
-  else if (test & G_FILE_TEST_IS_EXECUTABLE)
-    return (access (filename, X_OK) == 0);
-  else
+  if ((test & G_FILE_TEST_EXISTS) && (access (filename, F_OK) == 0))
+    return TRUE;
+  
+  if ((test & G_FILE_TEST_IS_EXECUTABLE) && (access (filename, X_OK) == 0))
+    return TRUE;
+
+  if (test & G_FILE_TEST_IS_SYMLINK)
     {
       struct stat s;
-      
-      if (stat (filename, &s) < 0)
-        return FALSE;
 
-      if ((test & G_FILE_TEST_IS_REGULAR) &&
-          S_ISREG (s.st_mode))
-        return TRUE;
-      else if ((test & G_FILE_TEST_IS_DIR) &&
-               S_ISDIR (s.st_mode))
+      if ((lstat (filename, &s) == 0) && S_ISLNK (s.st_mode))
         return TRUE;
-      else if ((test & G_FILE_TEST_IS_SYMLINK) &&
-               S_ISLNK (s.st_mode))
-        return TRUE;
-      else
-        return FALSE;
     }
+  
+  if (test & (G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_DIR))
+    {
+      struct stat s;
+      
+      if (stat (filename, &s) == 0)
+       {
+         if ((test & G_FILE_TEST_IS_REGULAR) && S_ISREG (s.st_mode))
+           return TRUE;
+         
+         if ((test & G_FILE_TEST_IS_DIR) && S_ISDIR (s.st_mode))
+           return TRUE;
+       }
+    }
+
+  return FALSE;
 }
 
 GQuark