Re: GtkFileSelection and symbolic links




Jamie Guinan <guinan@bluebutton.com> writes:

> Quentin Delamarre posted this back in July,
> http://www.gnome.org/mailing-lists/archives/gtk-list/1999-July/0113.shtml
> 
> There were no replies, unfortunatley.
> 
> I have a very small network, yet I like to use automounting and
> often one or more of my other machines are not running.  So,
> when Glib or Gtk or whichever layer decides to stat() *every*
> file in my /home directory it trips the automounter which takes
> a minute or two to time out.  This is just silly.  If I start a
> program in "/home/guinan/xyz", then in the program I bring up 
> the file selector and I select the directory drop-list, I see,
> 
>   /
>   /home
>   /home/guinan
>   /home/guinan/xyz
> 
> So when I click on "/home/guinan", I don't see any reason for
> the program to go and stat() directories like "/home/joeblow",
> (which is a symlink to an automounter-controlled mount point).
> 
> Running this under gdb, it appears that open_new_dir() gets 
> called for *every* directory leading up to the selected directory, 
> doing a readdir()/stat() on every file/directory found, and then a 
> qsort() on the resulting list.  
> 
> Shouldn't this only happen for the selected directory?

Well, the problem is that GtkFileSelector was written for
conceptual simplicity (everything is Tab completion) as opposed
to efficiency or real simplicity. So things like this
are harder to fix than they may seem.

There is a hard-coded hack in GtkFileSelection to assume
certain directories contain only other directories, which
avoids the stat() calls. Currently, this includes /afs
and /net. You could certainly add "/home" there as a local
workaround. 

(Maybe GTK+ needs ./configure --with-no-stat-subdirs=/home:/afs)

But I think things can be improved a bit - by choosing
the directory to complete from to be as long as possible.
The following patch tries to do this. It won't perfectly solve
your problem - if you go to the /home directory it is going
to stat all the subdirs, but it should help.

Could you try it out and see how it works for you?

Thanks,
                                        Owen

Index: gtkfilesel.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkfilesel.c,v
retrieving revision 1.46.2.2
diff -u -r1.46.2.2 gtkfilesel.c
--- gtkfilesel.c	1999/08/17 14:34:33	1.46.2.2
+++ gtkfilesel.c	1999/09/30 18:55:48
@@ -1811,10 +1811,27 @@
 
   if (text_to_complete[0] == '/' || !cmpl_state->reference_dir)
     {
-      new_dir = open_dir("/", cmpl_state);
+      gchar *tmp = g_strdup(text_to_complete);
+      gchar *p;
 
+      p = tmp;
+      while (*p && *p != '*' && *p != '?')
+	p++;
+
+      *p = '\0';
+      p = strrchr(tmp, '/');
+      if (p == tmp)
+	p++;
+      
+      *p = '\0';
+
+      new_dir = open_dir(tmp, cmpl_state);
+
       if(new_dir)
-	*remaining_text = text_to_complete + 1;
+	*remaining_text = text_to_complete + 
+	  ((p == tmp + 1) ? (p - tmp) : (p + 1 - tmp));
+
+      g_free (tmp);
     }
   else if (text_to_complete[0] == '~')
     {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]