After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 665092 - glocalfile* calls g_vfs_get_default()
glocalfile* calls g_vfs_get_default()
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: gio
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
: 691618 793187 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2011-11-29 00:15 UTC by Colin Walters
Modified: 2018-05-24 13:33 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gio: Don't call g_vfs_get_default() on GFiles created through local VFS (18.39 KB, patch)
2011-12-22 18:03 UTC, Colin Walters
none Details | Review
gio: Don't call g_vfs_get_default() on GFiles created through local VFS (19.76 KB, patch)
2011-12-22 18:04 UTC, Colin Walters
none Details | Review

Description Colin Walters 2011-11-29 00:15:40 UTC
In my project I want to use GIO as a convenient wrapper for the POSIX APIs, but I don't want to connect to the session bus (or in general use GVfs).

But glocalfile.c and glocalfileinfo.c both call g_vfs_get_default() behind my back, even if I use g_vfs_get_file_for_path (g_vfs_get_local (), path);
Comment 1 Matthias Clasen 2011-11-29 03:15:13 UTC
I guess the real question here is: what is g_vfs_get_local() good for ?

The only way to use a different implementation currently is to set GIO_USE_VFS=local in the environment.
Comment 2 Colin Walters 2011-11-29 15:45:05 UTC
(In reply to comment #1)
>
> The only way to use a different implementation currently is to set
> GIO_USE_VFS=local in the environment.

Well alex said I could use g_vfs_get_local() too.  The problem with setting an environment variable is mainly that it would propagate into any child processes, which I don't want.  (For example, say I spawn an editor from $EDITOR)
Comment 3 Colin Walters 2011-12-22 18:03:28 UTC
Created attachment 204103 [details] [review]
gio: Don't call g_vfs_get_default() on GFiles created through local VFS

My program is using GIO basically as "convenient Unix API wrapper",
like getting all data in g_malloc, allowing asynchronous operation
etc.  I don't ever want to do HTTP or FTP for example.

In particular the using default VFS implies connecting to the session
bus, which I definitely don't want to do (my program will in some
cases run as a root daemon).

Also, I tend to "profile" my app via "strace" to just get an idea of
what it's doing roughly - while connecting to the session bus isn't
expensive, it makes my strace profiles much uglier (for no benefit).

Before this patch, GIO had calls to g_vfs_get_default() scattered
randomly throughout GLocalFile, GLocalFileInfo etc.  This is ugly.  My
patch is effectively shifts the ugliness - I can't claim it's
beautiful.  One minor downside for example is we will start
instantiating the local VFS in apps that were just relying on
g_file_new_for_path().  (This is really pretty minor, it's just
another GObject).
Comment 4 Colin Walters 2011-12-22 18:04:36 UTC
Created attachment 204104 [details] [review]
gio: Don't call g_vfs_get_default() on GFiles created through local VFS

Missed "git add gio/gfile-priv.h"
Comment 5 Matthias Clasen 2011-12-23 19:13:21 UTC
Not a beauty, indeed. Do we really need all this tagging of individual objects ?
From my understanding, you simply want to _always_ use a local vfs instance, regardless of what the default is ? Wouldn't something like

g_vfs_set_default (gvfs_get_local ())

be a much more succinct way to achieve that ?

The idea that we may need to tag each object with its originating vfs, and propagate that along seems much more involved than simply being able to set the default.
Comment 6 Dan Winship 2011-12-23 20:06:48 UTC
the current GFile code seems backwards anyway... wouldn't it be more normal to have it emit a signal, which its parent VFS would catch and act on?

(Failing that, it seems like it would make more sense to tag the GFile with the GVfs itself, rather than a flag saying local-or-default.)
Comment 7 Colin Walters 2012-01-11 16:03:46 UTC
(In reply to comment #5)
> Not a beauty, indeed. Do we really need all this tagging of individual objects
> ?
> From my understanding, you simply want to _always_ use a local vfs instance,
> regardless of what the default is ? Wouldn't something like
> 
> g_vfs_set_default (gvfs_get_local ())
> 
> be a much more succinct way to achieve that ?

Well...further complicating things is that most of ostree is written as a library which I could imagine a gtk+ app wanting to use.  If I do something like the above, then it would break them.

Possibly what I could do is call that in main.c but not in the library.
 
I'll take a look.
Comment 8 Colin Walters 2012-01-11 16:05:47 UTC
(In reply to comment #6)
> the current GFile code seems backwards anyway... wouldn't it be more normal to
> have it emit a signal, which its parent VFS would catch and act on?

Mmm...that's probably one for alex to comment on.

> (Failing that, it seems like it would make more sense to tag the GFile with the
> GVfs itself, rather than a flag saying local-or-default.)

I started doing that originally, but then we're continually churning the refcount for the VFS instance as gfiles come and go; seemed ugly.

I think I'll just try g_vfs_set_default() instead.
Comment 9 David Zeuthen (not reading bugmail) 2012-01-31 19:51:30 UTC
Hi Colin,

Hmm, I don't _think_ what you want to achieve will work because of the guarantee that we map FUSE paths on file:/// back to GVfs URIs, e.g. this program

 gchar *uri;
 GFile *file;

 file = g_file_new_for_commandline_arg ("/home/davidz/.gvfs/SFTP\ on\ shell.lab.bos.redhat.com/home/boston/davidz/.bashrc");
 uri = g_file_get_get_uri (file);
 g_print ("%s\n", uri);
 g_free (uri);
 g_object_unref (file);

should print

 sftp://shell.lab.bos.redhat.com/home/boston/davidz/.bash_rc

Obviously for this to work, we need information from the GVfs daemon and the way it's implemented right now, I think, is that we do a D-Bus call (a smarter implementation may rely on a shared file in $XDG_RUNTIME_DIR to avoid the D-Bus call. But I don't think that's how things work right now.)

You might think this is a "pet feature" and we don't need it and so it's fine to break it ... but it is actually super important to have this because it is the corner-stone used to ensure interoperability between GVfs-using apps and non-GVfs-using apps (because we always pass POSIX-compliant paths when launching apps). For example, if we didn't have this we'd launch e.g. 'mplayer sftp://shell.lab.bos.redhat.com/home/boston/davidz/foo.avi' from your file manager and obviously this would not work at all. See

 http://developer.gnome.org/gio/unstable/GAppInfo.html#GAppInfo.description

for further information.

I have the same problem too in udisks btw, my solution is to do this

 http://cgit.freedesktop.org/udisks/tree/src/main.c?id=1.90.0#n106

e.g. the environment variable hack.
Comment 10 David Zeuthen (not reading bugmail) 2012-01-31 19:58:48 UTC
Btw, bug 526454 is obviously related and has additional discussion (maybe this bug is even a duplicate, dunno).
Comment 11 Alexander Larsson 2012-02-01 09:06:18 UTC
Review of attachment 204104 [details] [review]:

::: gio/glocalfile.c
@@ +1175,3 @@
+      class = G_VFS_GET_CLASS (vfs);
+      if (class->local_file_moved)
+	class->local_file_moved (vfs, local->filename, new_local->filename);

This isn't right at all. We want to chain this to the real vfs instance.
For instance, the GVfs implementation of this is what ensures that metadata follow files around when moved.

@@ +1255,3 @@
+	  class = G_VFS_GET_CLASS (vfs);
+	  if (class->add_writable_namespaces)
+	    class->add_writable_namespaces (vfs, list);

Similarly here, GVfs adds the "metadata" namespace as writable for local files.

@@ +1480,3 @@
+      class = G_VFS_GET_CLASS (vfs);
+      if (class->local_file_removed)
+	class->local_file_removed (vfs, local->filename);

Also used for metadata

@@ +2061,3 @@
+      class = G_VFS_GET_CLASS (vfs);
+      if (class->local_file_moved)
+	class->local_file_moved (vfs, local->filename, trashfile);

etc

@@ +2367,3 @@
+      class = G_VFS_GET_CLASS (vfs);
+      if (class->local_file_moved)
+	class->local_file_moved (vfs, local_source->filename, local_destination->filename);

etc

::: gio/glocalfileinfo.c
@@ +1748,3 @@
+                                      NULL,
+                                      &parent_info->extra_data,
+                                      &parent_info->free_extra_data);

This is needed to get metadata for local files.
Comment 12 Alexander Larsson 2012-02-01 09:08:07 UTC
The env var hack works, but we could also add an "early" set_default_vfs call to make this a bit cleaner (and more extensible, you could for instance supply an app-specific vfs implementation).
Comment 13 Philip Withnall 2018-02-09 12:33:35 UTC
*** Bug 691618 has been marked as a duplicate of this bug. ***
Comment 14 Philip Withnall 2018-02-09 12:34:07 UTC
Bug #691618 has some other ideas and a bit of discussion about this.
Comment 15 Philip Withnall 2018-02-09 12:44:03 UTC
*** Bug 793187 has been marked as a duplicate of this bug. ***
Comment 16 GNOME Infrastructure Team 2018-05-24 13:33:27 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/483.