Commit da509fd6 authored by Ondrej Holy's avatar Ondrej Holy Committed by Matthias Clasen

gunixmounts: Add g_unix_mount_for() support

GLib has g_unix_mount_at (mount_path) already, let's add g_unix_mount_for
(file_path) for whatever path. GLib already contains some private code
for such task. Let's make this code public. This functionality is needed
by GVfs (see Bug 771431) in order to avoid copy-and-pasting.

https://bugzilla.gnome.org/show_bug.cgi?id=772160
parent 67ce5305
......@@ -193,6 +193,7 @@ local_sources = \
ghttpproxy.h \
glocalfile.c \
glocalfile.h \
glocalfileprivate.h \
glocalfileenumerator.c \
glocalfileenumerator.h \
glocalfileinfo.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,
......
/* 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 <http://www.gnu.org/licenses/>.
*
* Author: Ondrej Holy <oholy@redhat.com>
*/
#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__ */
......@@ -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.
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment