diff --git a/gio/Makefile.am b/gio/Makefile.am index ffe5ee28a..cbeeaa13c 100644 --- a/gio/Makefile.am +++ b/gio/Makefile.am @@ -193,6 +193,7 @@ local_sources = \ ghttpproxy.h \ glocalfile.c \ glocalfile.h \ + glocalfileprivate.h \ glocalfileenumerator.c \ glocalfileenumerator.h \ glocalfileinfo.c \ diff --git a/gio/glocalfile.c b/gio/glocalfile.c index 4075d4b52..a4c9fa5f5 100644 --- a/gio/glocalfile.c +++ b/gio/glocalfile.c @@ -51,6 +51,7 @@ #include "gfileattribute.h" #include "glocalfile.h" +#include "glocalfileprivate.h" #include "glocalfileinfo.h" #include "glocalfileenumerator.h" #include "glocalfileinputstream.h" @@ -1706,8 +1707,8 @@ find_mountpoint_for (const char *file, } } -static char * -find_topdir_for (const char *file) +char * +_g_local_file_find_topdir_for (const char *file) { char *dir; char *mountpoint = NULL; @@ -1961,8 +1962,8 @@ g_local_file_trash (GFile *file, uid = geteuid (); g_snprintf (uid_str, sizeof (uid_str), "%lu", (unsigned long)uid); - - topdir = find_topdir_for (local->filename); + + topdir = _g_local_file_find_topdir_for (local->filename); if (topdir == NULL) { g_set_io_error (error, diff --git a/gio/glocalfileprivate.h b/gio/glocalfileprivate.h new file mode 100644 index 000000000..b4090a743 --- /dev/null +++ b/gio/glocalfileprivate.h @@ -0,0 +1,30 @@ +/* GIO - GLib Input, Output and Streaming Library + * + * Copyright (C) 2016 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * 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, see . + * + * Author: Ondrej Holy + */ + +#ifndef __G_LOCAL_FILE_PRIVATE_H__ +#define __G_LOCAL_FILE_PRIVATE_H__ + +G_BEGIN_DECLS + +gchar *_g_local_file_find_topdir_for (const char *file_path); + +G_END_DECLS + +#endif /* __G_LOCAL_FILE_PRIVATE_H__ */ diff --git a/gio/gunixmounts.c b/gio/gunixmounts.c index b5e066f84..52be25a34 100644 --- a/gio/gunixmounts.c +++ b/gio/gunixmounts.c @@ -64,6 +64,7 @@ #endif #include "gunixmounts.h" +#include "glocalfileprivate.h" #include "gfile.h" #include "gfilemonitor.h" #include "glibintl.h" @@ -1443,6 +1444,40 @@ g_unix_mount_at (const char *mount_path, return found; } +/** + * g_unix_mount_for: (skip) + * @file_path: file path on some unix mount. + * @time_read: (out) (allow-none): guint64 to contain a timestamp. + * + * Gets a #GUnixMountEntry for a given file path. If @time_read + * is set, it will be filled with a unix timestamp for checking + * if the mounts have changed since with g_unix_mounts_changed_since(). + * + * Returns: (transfer full): a #GUnixMountEntry. + * + * Since: 2.52 + **/ +GUnixMountEntry * +g_unix_mount_for (const char *file_path, + guint64 *time_read) +{ + GUnixMountEntry *entry; + + g_return_val_if_fail (file_path != NULL, NULL); + + entry = g_unix_mount_at (file_path, time_read); + if (entry == NULL) + { + char *topdir; + + topdir = _g_local_file_find_topdir_for (file_path); + entry = g_unix_mount_at (topdir, time_read); + g_free (topdir); + } + + return entry; +} + /** * g_unix_mount_points_get: (skip) * @time_read: (out) (allow-none): guint64 to contain a timestamp. diff --git a/gio/gunixmounts.h b/gio/gunixmounts.h index faf811999..90b9f0369 100644 --- a/gio/gunixmounts.h +++ b/gio/gunixmounts.h @@ -119,6 +119,9 @@ GList * g_unix_mounts_get (guint64 *time_re GLIB_AVAILABLE_IN_ALL GUnixMountEntry *g_unix_mount_at (const char *mount_path, guint64 *time_read); +GLIB_AVAILABLE_IN_2_52 +GUnixMountEntry *g_unix_mount_for (const char *file_path, + guint64 *time_read); GLIB_AVAILABLE_IN_ALL gboolean g_unix_mounts_changed_since (guint64 time); GLIB_AVAILABLE_IN_ALL