Is there a way to force content type detection for a slow file system

I have a virtual file system which is inherently slow because it uses the web service as a backend (Google Docs API).

It works great with one caveat: GTK applications use GtkFileChooser, which tries to determine the type of file content to display an icon or something else. When it encounters a file that it cannot recognize by extension, it reads the original piece of data to try to use it to determine the type of file. In my case, this leads to downloading the entire file from the network, which greatly slows down the list of directories in the file dialog.

It turns out that Gio (backend for GtkFileChooser) supports 2 modes for regularly detecting the content type (with the attribute 'standard :: content-type') and fast ('standard :: fast-content-type'), which only looks at the file extension . However, it seems that GtkFileChooser only asks for "standard :: content-type".

Is GTK always trying to use a slow algorithm to detect the type of content? Even for well-known slow file systems such as NFS?

Is it possible to mount my file system so that it uses only fast detection of the content type?

+6
source share
1 answer

Looking at the glib source code, I find it impossible to set up quick detection of the content type for a virtual file system that is mounted in the OS file system hierarchy. From gio POV, it is a local file system, so it is assumed that it has quick read access. Other remote file systems (such as NFS) are not affected, since accurate detection of the content type should only look at the first 4 Kbytes of data.

Therefore, for your case, I propose the following solution:

  • Download the glib source code. In Ubuntu, you can do this by typing:

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

  • Find the get_content_type function.
  • At the beginning of the function, add the following line:

     fast = 1; 
  • Compile glib.

  • Either set glib to the system location, or use LD_PRELOAD to load the new gio library.

Hope this helps. Feel free to tell me if you need more details.

+2
source

Source: https://habr.com/ru/post/911117/


All Articles