I have a virtual file system, which is inherently slow because it uses web service as a backend (Google Docs API).
It works totally fine with one caveat: GTK applications use GtkFileChooser, which tries to determine content type for the file to display icon or something. When it encounters a file, which it can not recognize by extension, it reads initial chunk of data to try to use that to determine file type. In my case this causes the entire file to be downloaded from the network, which extremely slows down directory listing in file dialogs.
It turns out that Gio (backend for GtkFileChooser) supports 2 modes for content type discovery regular (with attribute 'standard::content-type') and fast ('standard::fast-content-type'), which only looks at the file extension. However, it seems that GtkFileChooser queries only for 'standard::content-type'.
Does GTK really always try to use slow algorithm for content type discovery? Even for known to be slow filesystems like NFS?
Is there any way to mount my file system such that it would only use fast content type discovery?
Looking at the source code of glib, I believe there is no way to force fast content-type discovery for a virtual file system which is mounted in the OS's file system hierarchy. From gio's POV, it is a local file system, thus it assumes it has fast read access. Other remote file systems (such as NFS) are not impacted, since precise content-type discovery only needs to look at the first 4KB of data.
Therefore, for your case, I suggest the following solution:
Download glib's source code. In Ubuntu you can do this by typing:
apt-get source glib2.0
Open the file gio/glocalfile.c
.
get_content_type
.At the beginning of the function add the following line:
fast = 1;
Compile glib.
LD_PRELOAD
to load the new gio library.Hope this helps. Don't hesitate to tell me if you need more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With