[kdbus] More detailed description for ENOBUFS errno
[platform/upstream/glib.git] / gio / glocalfile.c
index ea59018..846eedb 100644 (file)
@@ -13,9 +13,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
  *
  * Author: Alexander Larsson <alexl@redhat.com>
  */
@@ -27,8 +25,8 @@
 #include <string.h>
 #include <errno.h>
 #include <fcntl.h>
+#if G_OS_UNIX
 #include <dirent.h>
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
@@ -68,6 +66,9 @@
 #ifdef G_OS_UNIX
 #include "glib-unix.h"
 #endif
+#include "glib-private.h"
+
+#include "glib-private.h"
 
 #ifdef G_OS_WIN32
 #include <windows.h>
@@ -138,7 +139,7 @@ g_local_file_class_init (GLocalFileClass *klass)
                                  G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE |
                                  G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED);
   
-#ifdef HAVE_CHOWN
+#ifdef G_OS_UNIX
   g_file_attribute_info_list_add (list,
                                  G_FILE_ATTRIBUTE_UNIX_UID,
                                  G_FILE_ATTRIBUTE_TYPE_UINT32,
@@ -2078,6 +2079,8 @@ g_local_file_trash (GFile         *file,
     {
       int errsv = errno;
 
+      g_unlink (infofile);
+
       g_free (topdir);
       g_free (trashname);
       g_free (infofile);
@@ -2502,7 +2505,7 @@ g_local_file_monitor_dir (GFile             *file,
                          GError           **error)
 {
   GLocalFile* local_file = G_LOCAL_FILE(file);
-  return _g_local_directory_monitor_new (local_file->filename, flags, is_remote (local_file->filename), error);
+  return _g_local_directory_monitor_new (local_file->filename, flags, NULL, is_remote (local_file->filename), TRUE, error);
 }
 
 static GFileMonitor*
@@ -2512,7 +2515,27 @@ g_local_file_monitor_file (GFile             *file,
                           GError           **error)
 {
   GLocalFile* local_file = G_LOCAL_FILE(file);
-  return _g_local_file_monitor_new (local_file->filename, flags, is_remote (local_file->filename), error);
+  return _g_local_file_monitor_new (local_file->filename, flags, NULL, is_remote (local_file->filename), TRUE, error);
+}
+
+GLocalDirectoryMonitor *
+g_local_directory_monitor_new_in_worker (const char         *pathname,
+                                         GFileMonitorFlags   flags,
+                                         GError            **error)
+{
+  return (gpointer) _g_local_directory_monitor_new (pathname, flags,
+                                                    GLIB_PRIVATE_CALL (g_get_worker_context) (),
+                                                    is_remote (pathname), FALSE, error);
+}
+
+GLocalFileMonitor *
+g_local_file_monitor_new_in_worker (const char         *pathname,
+                                    GFileMonitorFlags   flags,
+                                    GError            **error)
+{
+  return (gpointer) _g_local_file_monitor_new (pathname, flags,
+                                               GLIB_PRIVATE_CALL (g_get_worker_context) (),
+                                               is_remote (pathname), FALSE, error);
 }
 
 
@@ -2556,16 +2579,24 @@ g_local_file_measure_size_error (GFileMeasureFlags   flags,
       filename = g_string_new (name->data);
       for (node = name->next; node; node = node->next)
         {
+          gchar *utf8;
+
           g_string_prepend_c (filename, G_DIR_SEPARATOR);
-          g_string_prepend (filename, node->data);
+          utf8 = g_filename_display_name (node->data);
+          g_string_prepend (filename, utf8);
+          g_free (utf8);
         }
-
-      g_string_prepend (filename, "file://");
 #else
-      /* Otherwise, we already have it, so just use it. */
-      node = name;
-      filename = g_string_new ("file://");
-      g_string_append (filename, node->data);
+      {
+        gchar *utf8;
+
+        /* Otherwise, we already have it, so just use it. */
+        node = name;
+        filename = g_string_new (NULL);
+        utf8 = g_filename_display_name (node->data);
+        g_string_append (filename, utf8);
+        g_free (utf8);
+      }
 #endif
 
       g_set_error (error, G_IO_ERROR, g_io_error_from_errno (saved_errno),
@@ -2610,17 +2641,15 @@ g_local_file_measure_size_of_file (gint           parent_fd,
                                    MeasureState  *state,
                                    GError       **error)
 {
-  struct stat buf;
+  GLocalFileStat buf;
 
   if (g_cancellable_set_error_if_cancelled (state->cancellable, error))
     return FALSE;
 
 #if defined (AT_FDCWD)
   if (fstatat (parent_fd, name->data, &buf, AT_SYMLINK_NOFOLLOW) != 0)
-#elif defined (HAVE_LSTAT)
-  if (lstat (name->data, &buf) != 0)
 #else
-  if (stat (name->data, &buf) != 0)
+  if (g_lstat (name->data, &buf) != 0)
 #endif
     return g_local_file_measure_size_error (state->flags, errno, name, error);
 
@@ -2690,7 +2719,11 @@ g_local_file_measure_size_of_file (gint           parent_fd,
         return FALSE;
 
 #ifdef AT_FDCWD
-      dir_fd = openat (parent_fd, name->data, O_RDONLY | O_DIRECTORY);
+#ifdef HAVE_OPEN_O_DIRECTORY
+      dir_fd = openat (parent_fd, name->data, O_RDONLY|O_DIRECTORY);
+#else
+      dir_fd = openat (parent_fd, name->data, O_RDONLY);
+#endif
       if (dir_fd < 0)
         return g_local_file_measure_size_error (state->flags, errno, name, error);
 #endif
@@ -2709,16 +2742,21 @@ g_local_file_measure_size_of_contents (gint           fd,
                                        GError       **error)
 {
   gboolean success = TRUE;
-  struct dirent *entry;
-  DIR *dirp;
+  const gchar *name;
+  GDir *dir;
 
 #ifdef AT_FDCWD
-  dirp = fdopendir (fd);
+  {
+    /* If this fails, we want to preserve the errno from fopendir() */
+    DIR *dirp;
+    dirp = fdopendir (fd);
+    dir = dirp ? GLIB_PRIVATE_CALL(g_dir_new_from_dirp) (dirp) : NULL;
+  }
 #else
-  dirp = opendir (dir_name->data);
+  dir = GLIB_PRIVATE_CALL(g_dir_open_with_errno) (dir_name->data, 0);
 #endif
 
-  if (dirp == NULL)
+  if (dir == NULL)
     {
       gint saved_errno = errno;
 
@@ -2729,24 +2767,17 @@ g_local_file_measure_size_of_contents (gint           fd,
       return g_local_file_measure_size_error (state->flags, saved_errno, dir_name, error);
     }
 
-  while (success && (entry = readdir (dirp)))
+  while (success && (name = g_dir_read_name (dir)))
     {
-      gchar *name = entry->d_name;
       GSList node;
 
       node.next = dir_name;
 #ifdef AT_FDCWD
-      node.data = name;
+      node.data = (gchar *) name;
 #else
       node.data = g_build_filename (dir_name->data, name, NULL);
 #endif
 
-      /* skip '.' and '..' */
-      if (name[0] == '.' &&
-          (name[1] == '\0' ||
-           (name[1] == '.' && name[2] == '\0')))
-        continue;
-
       success = g_local_file_measure_size_of_file (fd, &node, state, error);
 
 #ifndef AT_FDCWD
@@ -2754,7 +2785,7 @@ g_local_file_measure_size_of_contents (gint           fd,
 #endif
     }
 
-  closedir (dirp);
+  g_dir_close (dir);
 
   return success;
 }