Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to force fast content type determination for slow file system

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?

like image 585
Dima Malenko Avatar asked Mar 19 '12 17:03

Dima Malenko


1 Answers

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:

  1. Download glib's source code. In Ubuntu you can do this by typing:

    apt-get source glib2.0
    
  2. Open the file gio/glocalfile.c.

  3. Locate the function get_content_type.
  4. At the beginning of the function add the following line:

    fast = 1;
    
  5. Compile glib.

  6. Either install glib in the system location, or use LD_PRELOAD to load the new gio library.

Hope this helps. Don't hesitate to tell me if you need more details.

like image 198
user1202136 Avatar answered Oct 17 '22 11:10

user1202136