diff --git a/gtk/gtkfilethumbnail.c b/gtk/gtkfilethumbnail.c index 60ae5ca31..4454d1fbb 100644 --- a/gtk/gtkfilethumbnail.c +++ b/gtk/gtkfilethumbnail.c @@ -29,6 +29,13 @@ #include "gtkfilethumbnail.h" +#ifdef G_OS_WIN32 +#include +#endif +#ifdef __linux__ +#include +#endif + #ifndef O_BINARY #define O_BINARY 0 #endif @@ -130,6 +137,30 @@ thumbnail_matches (const gchar *path, return matches; } +#ifndef G_OS_WIN32 +/* Filesystem types of network shares and FUSE mounts, as statfs() names + * them on the BSDs and macOS, and GIO on Linux: smbfs, smb2, nfs4, + * fusefs.sshfs, perfuse|sshfs, macfuse... GLib itself knows only a few + * of them as remote. */ +static const gchar *const remote_types[] = { + "nfs", "smb", "cifs", "afpfs", "webdav", "ncp", "coda", "afs", "9p", + "ceph", "fuse", "puffs", "perfuse", "macfuse", "osxfuse" +}; + +#ifdef __linux__ +/* Linux calls every FUSE mount "fuse"; those on a disk of their own, + * fuseblk with NTFS or exFAT, have the device number of the disk, + * where sshfs and the like have one of major 0 */ +static gboolean +local_fuse_mount (const gchar *path) +{ + GStatBuf buf; + + return g_stat (path, &buf) == 0 && major (buf.st_dev) != 0; +} +#endif +#endif + /* Network shares, and FUSE mounts like sshfs, are left alone; the * answer is kept per folder */ static gboolean @@ -138,7 +169,6 @@ on_remote_filesystem (Job *job) static gchar *last_folder; static gboolean last_remote; gchar *folder = g_path_get_dirname (job->path); - GFileInfo *info; if (g_strcmp0 (folder, last_folder) == 0) { @@ -146,19 +176,45 @@ on_remote_filesystem (Job *job) return last_remote; } - last_remote = TRUE; - info = g_file_query_filesystem_info (job->file, - G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE "," - G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, - job->cancellable, NULL); - if (info) +#ifdef G_OS_WIN32 + /* GIO tells nothing of the kind here: \\server\share, and drives + * that are mapped to one */ + if (G_IS_DIR_SEPARATOR (folder[0]) && G_IS_DIR_SEPARATOR (folder[1])) + last_remote = TRUE; + else { - const gchar *type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE); + wchar_t root[4] = { 0, L':', L'\\', 0 }; - last_remote = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE) || - (type && g_str_has_prefix (type, "fuse")); - g_object_unref (info); + root[0] = g_ascii_isalpha (folder[0]) && folder[1] == ':' ? folder[0] : 0; + last_remote = root[0] == 0 || GetDriveTypeW (root) == DRIVE_REMOTE; } +#else + { + GFileInfo *info = g_file_query_filesystem_info (job->file, + G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE "," + G_FILE_ATTRIBUTE_FILESYSTEM_TYPE, + job->cancellable, NULL); + const gchar *type; + guint i; + + /* no answer, as when cancelled: not kept */ + if (info == NULL) + { + g_free (folder); + return TRUE; + } + + type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE); + last_remote = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_REMOTE); + for (i = 0; type && !last_remote && i < G_N_ELEMENTS (remote_types); i++) + last_remote = g_str_has_prefix (type, remote_types[i]); +#ifdef __linux__ + if (last_remote && g_strcmp0 (type, "fuse") == 0) + last_remote = !local_fuse_mount (job->path); +#endif + g_object_unref (info); + } +#endif g_free (last_folder); last_folder = folder;