Merge branch 'wip/oholy/remote-attribute-fixes' into 'master'

Various GLocalFile fixes related to the filesystem::remote attribute

See merge request GNOME/glib!1534
This commit is contained in:
Philip Withnall 2020-06-19 10:08:03 +00:00
commit 97b5bc4a01
5 changed files with 41 additions and 79 deletions

View File

@ -51,7 +51,6 @@
#include "gfileattribute.h"
#include "glocalfile.h"
#include "glocalfileprivate.h"
#include "glocalfileinfo.h"
#include "glocalfileenumerator.h"
#include "glocalfileinputstream.h"
@ -113,6 +112,10 @@ G_DEFINE_TYPE_WITH_CODE (GLocalFile, g_local_file, G_TYPE_OBJECT,
static char *find_mountpoint_for (const char *file, dev_t dev, gboolean resolve_basename_symlink);
#ifndef G_OS_WIN32
static gboolean is_remote_fs_type (const gchar *fsname);
#endif
static void
g_local_file_finalize (GObject *object)
{
@ -690,6 +693,8 @@ get_fs_type (long f_type)
return "smackfs";
case 0x517B:
return "smb";
case 0xfe534d42:
return "smb2";
case 0x534F434B:
return "sockfs";
case 0x73717368:
@ -1110,11 +1115,13 @@ g_local_file_query_filesystem_info (GFile *file,
get_mount_info (info, local->filename, attribute_matcher);
#endif /* G_OS_WIN32 */
}
#ifndef G_OS_WIN32
if (g_file_attribute_matcher_matches (attribute_matcher,
G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE))
g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE,
g_local_file_is_remote (local->filename));
G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE))
g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE,
is_remote_fs_type (fstype));
#endif
g_file_attribute_matcher_unref (attribute_matcher);
@ -2509,7 +2516,7 @@ g_local_file_move (GFile *source,
#ifdef G_OS_WIN32
gboolean
g_local_file_is_remote (const gchar *filename)
g_local_file_is_nfs_home (const gchar *filename)
{
return FALSE;
}
@ -2517,58 +2524,29 @@ g_local_file_is_remote (const gchar *filename)
#else
static gboolean
is_remote_fs (const gchar *filename)
is_remote_fs_type (const gchar *fsname)
{
const char *fsname = NULL;
#ifdef USE_STATFS
struct statfs statfs_buffer;
int statfs_result = 0;
#if STATFS_ARGS == 2
statfs_result = statfs (filename, &statfs_buffer);
#elif STATFS_ARGS == 4
statfs_result = statfs (filename, &statfs_buffer, sizeof (statfs_buffer), 0);
#endif
#elif defined(USE_STATVFS)
struct statvfs statfs_buffer;
int statfs_result = 0;
statfs_result = statvfs (filename, &statfs_buffer);
#else
return FALSE;
#endif
if (statfs_result == -1)
return FALSE;
#ifdef USE_STATFS
#if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME)
fsname = statfs_buffer.f_fstypename;
#else
fsname = get_fs_type (statfs_buffer.f_type);
#endif
#elif defined(USE_STATVFS) && defined(HAVE_STRUCT_STATVFS_F_BASETYPE)
fsname = statfs_buffer.f_basetype;
#endif
if (fsname != NULL)
{
if (strcmp (fsname, "nfs") == 0)
return TRUE;
if (strcmp (fsname, "nfs4") == 0)
return TRUE;
if (strcmp (fsname, "cifs") == 0)
return TRUE;
if (strcmp (fsname, "smb") == 0)
return TRUE;
if (strcmp (fsname, "smb2") == 0)
return TRUE;
}
return FALSE;
}
gboolean
g_local_file_is_remote (const gchar *filename)
g_local_file_is_nfs_home (const gchar *filename)
{
static gboolean remote_home;
static gboolean remote_home = FALSE;
static gsize initialized;
const gchar *home;
@ -2577,7 +2555,19 @@ g_local_file_is_remote (const gchar *filename)
{
if (g_once_init_enter (&initialized))
{
remote_home = is_remote_fs (home);
GFile *file;
GFileInfo *info;
const gchar *fs_type = NULL;
file = _g_local_file_new (home);
info = g_local_file_query_filesystem_info (file, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, NULL, NULL);
if (info != NULL)
fs_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE);
if (g_strcmp0 (fs_type, "nfs") == 0 || g_strcmp0 (fs_type, "nfs4") == 0)
remote_home = TRUE;
g_clear_object (&info);
g_object_unref (file);
g_once_init_leave (&initialized, TRUE);
}
return remote_home;

View File

@ -46,11 +46,13 @@ GFile * _g_local_file_new (const char *filename);
const char * _g_local_file_get_filename (GLocalFile *file);
gboolean g_local_file_is_remote (const gchar *filename);
gboolean g_local_file_is_nfs_home (const gchar *filename);
GFile * g_local_file_new_from_dirname_and_basename (const char *dirname,
const char *basename);
gchar *_g_local_file_find_topdir_for (const char *file_path);
G_END_DECLS
#endif /* __G_LOCAL_FILE_H__ */

View File

@ -878,7 +878,7 @@ g_local_file_monitor_new_for_path (const gchar *pathname,
GLocalFileMonitor *monitor;
gboolean is_remote_fs;
is_remote_fs = g_local_file_is_remote (pathname);
is_remote_fs = g_local_file_is_nfs_home (pathname);
monitor = g_local_file_monitor_new (is_remote_fs, is_directory, error);
@ -900,7 +900,7 @@ g_local_file_monitor_new_in_worker (const gchar *pathname,
GLocalFileMonitor *monitor;
gboolean is_remote_fs;
is_remote_fs = g_local_file_is_remote (pathname);
is_remote_fs = g_local_file_is_nfs_home (pathname);
monitor = g_local_file_monitor_new (is_remote_fs, is_directory, error);

View File

@ -1,30 +0,0 @@
/* 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.1 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__ */

View File

@ -64,10 +64,10 @@
#endif
#include "gunixmounts.h"
#include "glocalfileprivate.h"
#include "gfile.h"
#include "gfilemonitor.h"
#include "glibintl.h"
#include "glocalfile.h"
#include "gthemedicon.h"
#include "gcontextspecificgroup.h"