2 * ROX-Filer, filer for the ROX desktop project
3 * Copyright (C) 2006, Thomas Leonard and others (see changelog for details).
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 2 of the License, or (at your option)
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16 * Place, Suite 330, Boston, MA 02111-1307 USA
19 /* dir.c - directory scanning and caching */
23 * A Directory contains a list DirItems, each having a name and some details
24 * (size, image, owner, etc).
26 * There is a list of file names that need to be rechecked. While this
27 * list is non-empty, items are taken from the list in an idle callback
28 * and checked. Missing items are removed from the Directory, new items are
29 * added and existing items are updated if they've changed.
31 * When a whole directory is to be rescanned:
33 * - A list of all filenames in the directory is fetched, without any
34 * of the extra details.
35 * - This list is compared to the current DirItems, removing any that are now
37 * - Each window onto the directory is asked which items it will actually
38 * display, and the union of these sets is the new recheck list.
40 * This system is designed to get the number of items and their names quickly,
41 * so that the auto-sizer can make a good guess. It also prevents checking
42 * hidden files if they're not going to be displayed.
44 * To get the Directory object, use dir_cache, which will automatically
45 * trigger a rescan if needed.
47 * To get notified when the Directory changes, use the dir_attach() and
48 * dir_detach() functions.
63 #include "gui_support.h"
69 #include "usericons.h"
73 /* Newer Linux kernels can tell us when the directories we are watching
74 * change, using the dnotify system.
76 static GHashTable
*dnotify_fd_to_dir
= NULL
;
77 gboolean dnotify_wakeup_flag
= FALSE
;
78 static int dnotify_last_fd
= -1;
81 /* For debugging. Can't detach when this is non-zero. */
82 static int in_callback
= 0;
84 GFSCache
*dir_cache
= NULL
;
86 /* Static prototypes */
87 static void update(Directory
*dir
, gchar
*pathname
, gpointer data
);
88 static void set_idle_callback(Directory
*dir
);
89 static DirItem
*insert_item(Directory
*dir
, const guchar
*leafname
);
90 static void remove_missing(Directory
*dir
, GPtrArray
*keep
);
91 static void dir_recheck(Directory
*dir
,
92 const guchar
*path
, const guchar
*leafname
);
93 static GPtrArray
*hash_to_array(GHashTable
*hash
);
94 static void dir_force_update_item(Directory
*dir
, const gchar
*leaf
);
95 static Directory
*dir_new(const char *pathname
);
96 static void dir_rescan(Directory
*dir
);
98 static void dir_rescan_soon(Directory
*dir
);
99 static void dnotify_handler(int sig
, siginfo_t
*si
, void *data
);
102 /****************************************************************
103 * EXTERNAL INTERFACE *
104 ****************************************************************/
108 dir_cache
= g_fscache_new((GFSLoadFunc
) dir_new
,
109 (GFSUpdateFunc
) update
, NULL
);
111 /* Check for dnotify support in the kernel */
114 struct sigaction act
;
116 act
.sa_sigaction
= dnotify_handler
;
117 sigemptyset(&act
.sa_mask
);
118 act
.sa_flags
= SA_SIGINFO
;
119 sigaction(SIGRTMIN
, &act
, NULL
);
121 /* Sometimes we get this instead of SIGRTMIN.
122 * Don't know why :-( but don't crash...
124 act
.sa_handler
= SIG_IGN
;
125 sigemptyset(&act
.sa_mask
);
127 sigaction(SIGIO
, &act
, NULL
);
129 dnotify_fd_to_dir
= g_hash_table_new(NULL
, NULL
);
134 /* Periodically calls callback to notify about changes to the contents
136 * Before this function returns, it calls the callback once to add all
137 * the items currently in the directory (unless the dir is empty).
138 * It then calls callback(DIR_QUEUE_INTERESTING) to find out which items the
139 * caller cares about.
140 * If we are not scanning, it also calls callback(DIR_END_SCAN).
142 void dir_attach(Directory
*dir
, DirCallback callback
, gpointer data
)
147 g_return_if_fail(dir
!= NULL
);
148 g_return_if_fail(callback
!= NULL
);
150 user
= g_new(DirUser
, 1);
151 user
->callback
= callback
;
159 if (dir
->dnotify_fd
!= -1)
160 g_warning("dir_attach: dnotify error\n");
162 fd
= open(dir
->pathname
, O_RDONLY
);
163 g_return_if_fail(g_hash_table_lookup(dnotify_fd_to_dir
,
164 GINT_TO_POINTER(fd
)) == NULL
);
167 dir
->dnotify_fd
= fd
;
168 g_hash_table_insert(dnotify_fd_to_dir
,
169 GINT_TO_POINTER(fd
), dir
);
170 fcntl(fd
, F_SETSIG
, SIGRTMIN
);
171 fcntl(fd
, F_NOTIFY
, DN_CREATE
| DN_DELETE
| DN_RENAME
|
172 DN_ATTRIB
| DN_MULTISHOT
);
177 dir
->users
= g_list_prepend(dir
->users
, user
);
181 items
= hash_to_array(dir
->known_items
);
183 callback(dir
, DIR_ADD
, items
, data
);
184 g_ptr_array_free(items
, TRUE
);
186 if (dir
->needs_update
&& !dir
->scanning
)
189 callback(dir
, DIR_QUEUE_INTERESTING
, NULL
, data
);
191 /* May start scanning if noone was watching before */
192 set_idle_callback(dir
);
195 callback(dir
, DIR_END_SCAN
, NULL
, data
);
198 /* Undo the effect of dir_attach */
199 void dir_detach(Directory
*dir
, DirCallback callback
, gpointer data
)
204 g_return_if_fail(dir
!= NULL
);
205 g_return_if_fail(callback
!= NULL
);
206 g_return_if_fail(in_callback
== 0);
208 for (list
= dir
->users
; list
; list
= list
->next
)
210 user
= (DirUser
*) list
->data
;
211 if (user
->callback
== callback
&& user
->data
== data
)
214 dir
->users
= g_list_remove(dir
->users
, user
);
217 /* May stop scanning if noone's watching */
218 set_idle_callback(dir
);
221 if (!dir
->users
&& dir
->dnotify_fd
!= -1)
223 close(dir
->dnotify_fd
);
224 g_hash_table_remove(dnotify_fd_to_dir
,
225 GINT_TO_POINTER(dir
->dnotify_fd
));
226 dir
->dnotify_fd
= -1;
233 g_warning("dir_detach: Callback/data pair not attached!\n");
236 void dir_update(Directory
*dir
, gchar
*pathname
)
238 update(dir
, pathname
, NULL
);
241 /* Rescan this directory */
242 void refresh_dirs(const char *path
)
244 g_fscache_update(dir_cache
, path
);
247 /* When something has happened to a particular object, call this
248 * and all appropriate changes will be made.
250 void dir_check_this(const guchar
*path
)
256 dir_path
= g_path_get_dirname(path
);
257 real_path
= pathdup(dir_path
);
260 dir
= g_fscache_lookup_full(dir_cache
, real_path
,
261 FSCACHE_LOOKUP_PEEK
, NULL
);
264 dir_recheck(dir
, real_path
, g_basename(path
));
272 static void drop_dnotify(gpointer key
, gpointer value
, gpointer data
)
274 close(GPOINTER_TO_INT(key
));
278 /* Used when we fork an action child, otherwise we can't delete or unmount
279 * any directory which we're watching!
281 void dir_drop_all_dnotifies(void)
284 g_hash_table_foreach(dnotify_fd_to_dir
, drop_dnotify
, NULL
);
288 /* Tell watchers that this item has changed, but don't rescan.
289 * (used when thumbnail has been created for an item)
291 void dir_force_update_path(const gchar
*path
)
296 g_return_if_fail(path
[0] == '/');
298 dir_path
= g_path_get_dirname(path
);
300 dir
= g_fscache_lookup_full(dir_cache
, dir_path
, FSCACHE_LOOKUP_PEEK
,
304 dir_force_update_item(dir
, g_basename(path
));
311 /* Ensure that 'leafname' is up-to-date. Returns the new/updated
312 * DirItem, or NULL if the file no longer exists.
314 DirItem
*dir_update_item(Directory
*dir
, const gchar
*leafname
)
318 time(&diritem_recent_time
);
319 item
= insert_item(dir
, leafname
);
325 /* Add item to the recheck_list if it's marked as needing it.
326 * Item must have ITEM_FLAG_NEED_RESCAN_QUEUE.
327 * Items on the list will get checked later in an idle callback.
329 void dir_queue_recheck(Directory
*dir
, DirItem
*item
)
331 g_return_if_fail(dir
!= NULL
);
332 g_return_if_fail(item
!= NULL
);
333 g_return_if_fail(item
->flags
& ITEM_FLAG_NEED_RESCAN_QUEUE
);
335 dir
->recheck_list
= g_list_prepend(dir
->recheck_list
,
336 g_strdup(item
->leafname
));
337 item
->flags
&= ~ITEM_FLAG_NEED_RESCAN_QUEUE
;
340 static void free_recheck_list(Directory
*dir
)
342 destroy_glist(&dir
->recheck_list
);
345 /* If scanning state has changed then notify all filer windows */
346 static void dir_set_scanning(Directory
*dir
, gboolean scanning
)
350 if (scanning
== dir
->scanning
)
355 dir
->scanning
= scanning
;
357 for (next
= dir
->users
; next
; next
= next
->next
)
359 DirUser
*user
= (DirUser
*) next
->data
;
362 scanning
? DIR_START_SCAN
: DIR_END_SCAN
,
367 /* Useful for profiling */
378 /* Notify everyone that the error status of the directory has changed */
379 static void dir_error_changed(Directory
*dir
)
385 for (next
= dir
->users
; next
; next
= next
->next
)
387 DirUser
*user
= (DirUser
*) next
->data
;
389 user
->callback(dir
, DIR_ERROR_CHANGED
, NULL
, user
->data
);
395 /* This is called in the background when there are items on the
396 * dir->recheck_list to process.
398 static gboolean
recheck_callback(gpointer data
)
400 Directory
*dir
= (Directory
*) data
;
404 g_return_val_if_fail(dir
!= NULL
, FALSE
);
405 g_return_val_if_fail(dir
->recheck_list
!= NULL
, FALSE
);
407 /* Remove the first name from the list */
408 next
= dir
->recheck_list
;
409 dir
->recheck_list
= g_list_remove_link(dir
->recheck_list
, next
);
410 leaf
= (guchar
*) next
->data
;
415 insert_item(dir
, leaf
);
419 if (dir
->recheck_list
)
420 return TRUE
; /* Call again */
422 /* The recheck_list list empty. Stop scanning, unless
423 * needs_update, in which case we start scanning again.
428 dir
->have_scanned
= TRUE
;
429 dir_set_scanning(dir
, FALSE
);
430 g_source_remove(dir
->idle_callback
);
431 dir
->idle_callback
= 0;
433 if (dir
->needs_update
)
439 /* Add all the new items to the items array.
440 * Notify everyone who is watching us.
442 void dir_merge_new(Directory
*dir
)
444 GPtrArray
*new = dir
->new_items
;
445 GPtrArray
*up
= dir
->up_items
;
446 GPtrArray
*gone
= dir
->gone_items
;
452 for (list
= dir
->users
; list
; list
= list
->next
)
454 DirUser
*user
= (DirUser
*) list
->data
;
457 user
->callback(dir
, DIR_ADD
, new, user
->data
);
459 user
->callback(dir
, DIR_UPDATE
, up
, user
->data
);
461 user
->callback(dir
, DIR_REMOVE
, gone
, user
->data
);
466 for (i
= 0; i
< new->len
; i
++)
468 DirItem
*item
= (DirItem
*) new->pdata
[i
];
470 g_hash_table_insert(dir
->known_items
, item
->leafname
, item
);
473 for (i
= 0; i
< gone
->len
; i
++)
475 DirItem
*item
= (DirItem
*) gone
->pdata
[i
];
480 g_ptr_array_set_size(gone
, 0);
481 g_ptr_array_set_size(new, 0);
482 g_ptr_array_set_size(up
, 0);
486 /* Called from the mainloop shortly after dnotify_handler */
487 void dnotify_wakeup(void)
491 dnotify_wakeup_flag
= FALSE
;
493 dir
= g_hash_table_lookup(dnotify_fd_to_dir
,
494 GINT_TO_POINTER(dnotify_last_fd
));
497 dir_rescan_soon(dir
);
501 /****************************************************************
502 * INTERNAL FUNCTIONS *
503 ****************************************************************/
506 static gint
rescan_soon_timeout(gpointer data
)
508 Directory
*dir
= (Directory
*) data
;
510 dir
->rescan_timeout
= -1;
512 dir
->needs_update
= TRUE
;
518 /* Wait a fraction of a second and then rescan. If already waiting,
519 * this function does nothing.
521 static void dir_rescan_soon(Directory
*dir
)
523 if (dir
->rescan_timeout
!= -1)
525 dir
->rescan_timeout
= g_timeout_add(500, rescan_soon_timeout
, dir
);
529 static void free_items_array(GPtrArray
*array
)
533 for (i
= 0; i
< array
->len
; i
++)
535 DirItem
*item
= (DirItem
*) array
->pdata
[i
];
540 g_ptr_array_free(array
, TRUE
);
543 /* Tell everyone watching that these items have gone */
544 static void notify_deleted(Directory
*dir
, GPtrArray
*deleted
)
553 for (next
= dir
->users
; next
; next
= next
->next
)
555 DirUser
*user
= (DirUser
*) next
->data
;
557 user
->callback(dir
, DIR_REMOVE
, deleted
, user
->data
);
563 static void mark_unused(gpointer key
, gpointer value
, gpointer data
)
565 DirItem
*item
= (DirItem
*) value
;
567 item
->may_delete
= TRUE
;
570 static void keep_deleted(gpointer key
, gpointer value
, gpointer data
)
572 DirItem
*item
= (DirItem
*) value
;
573 GPtrArray
*deleted
= (GPtrArray
*) data
;
575 if (item
->may_delete
)
576 g_ptr_array_add(deleted
, item
);
579 static gboolean
check_unused(gpointer key
, gpointer value
, gpointer data
)
581 DirItem
*item
= (DirItem
*) value
;
583 return item
->may_delete
;
586 /* Remove all the old items that have gone.
587 * Notify everyone who is watching us of the removed items.
589 static void remove_missing(Directory
*dir
, GPtrArray
*keep
)
594 deleted
= g_ptr_array_new();
596 /* Mark all current items as may_delete */
597 g_hash_table_foreach(dir
->known_items
, mark_unused
, NULL
);
599 /* Unmark all items also in 'keep' */
600 for (i
= 0; i
< keep
->len
; i
++)
602 guchar
*leaf
= (guchar
*) keep
->pdata
[i
];
605 item
= g_hash_table_lookup(dir
->known_items
, leaf
);
608 item
->may_delete
= FALSE
;
611 /* Add each item still marked to 'deleted' */
612 g_hash_table_foreach(dir
->known_items
, keep_deleted
, deleted
);
614 /* Remove all items still marked */
615 g_hash_table_foreach_remove(dir
->known_items
, check_unused
, NULL
);
617 notify_deleted(dir
, deleted
);
619 free_items_array(deleted
);
622 static gint
notify_timeout(gpointer data
)
624 Directory
*dir
= (Directory
*) data
;
626 g_return_val_if_fail(dir
->notify_active
== TRUE
, FALSE
);
630 dir
->notify_active
= FALSE
;
636 /* Call dir_merge_new() after a while. */
637 static void delayed_notify(Directory
*dir
)
639 if (dir
->notify_active
)
642 g_timeout_add(1500, notify_timeout
, dir
);
643 dir
->notify_active
= TRUE
;
646 /* Stat this item and add, update or remove it.
647 * Returns the new/updated item, if any.
648 * (leafname may be from the current DirItem item)
649 * Ensure diritem_recent_time is reasonably up-to-date before calling this.
651 static DirItem
*insert_item(Directory
*dir
, const guchar
*leafname
)
653 const gchar
*full_path
;
656 gboolean do_compare
= FALSE
; /* (old is filled in) */
658 if (leafname
[0] == '.' && (leafname
[1] == '\n' ||
659 (leafname
[1] == '.' && leafname
[2] == '\n')))
660 return NULL
; /* Ignore '.' and '..' */
662 full_path
= make_path(dir
->pathname
, leafname
);
663 item
= g_hash_table_lookup(dir
->known_items
, leafname
);
667 if (item
->base_type
!= TYPE_UNKNOWN
)
669 /* Preserve the old details so we can compare */
672 g_object_ref(old
._image
);
675 diritem_restat(full_path
, item
, &dir
->stat_info
);
679 /* Item isn't already here. This won't normally happen,
680 * because blank items are added when scanning, before
683 item
= diritem_new(leafname
);
684 diritem_restat(full_path
, item
, &dir
->stat_info
);
685 if (item
->base_type
== TYPE_ERROR
&&
686 item
->lstat_errno
== ENOENT
)
691 g_ptr_array_add(dir
->new_items
, item
);
695 /* No need to queue the item for scanning. If we got here because
696 * the item was queued, this flag will normally already be clear.
698 item
->flags
&= ~ITEM_FLAG_NEED_RESCAN_QUEUE
;
700 if (item
->base_type
== TYPE_ERROR
&& item
->lstat_errno
== ENOENT
)
702 /* Item has been deleted */
703 g_hash_table_remove(dir
->known_items
, item
->leafname
);
704 g_ptr_array_add(dir
->gone_items
, item
);
705 if (do_compare
&& old
._image
)
706 g_object_unref(old
._image
);
713 /* It's a bit inefficient that we force the image to be
714 * loaded here, if we had an old image.
716 if (item
->lstat_errno
== old
.lstat_errno
717 && item
->base_type
== old
.base_type
718 && item
->flags
== old
.flags
719 && item
->size
== old
.size
720 && item
->mode
== old
.mode
721 && item
->atime
== old
.atime
722 && item
->ctime
== old
.ctime
723 && item
->mtime
== old
.mtime
724 && item
->uid
== old
.uid
725 && item
->gid
== old
.gid
726 && item
->mime_type
== old
.mime_type
727 && (old
._image
== NULL
|| di_image(item
) == old
._image
))
730 g_object_unref(old
._image
);
734 g_object_unref(old
._image
);
737 g_ptr_array_add(dir
->up_items
, item
);
743 static void update(Directory
*dir
, gchar
*pathname
, gpointer data
)
745 g_free(dir
->pathname
);
746 dir
->pathname
= pathdup(pathname
);
749 dir
->needs_update
= TRUE
;
754 /* If there is work to do, set the idle callback.
755 * Otherwise, stop scanning and unset the idle callback.
757 static void set_idle_callback(Directory
*dir
)
759 if (dir
->recheck_list
&& dir
->users
)
761 /* Work to do, and someone's watching */
762 dir_set_scanning(dir
, TRUE
);
763 if (dir
->idle_callback
)
765 time(&diritem_recent_time
);
766 dir
->idle_callback
= g_idle_add(recheck_callback
, dir
);
767 /* Do the first call now (will remove the callback itself) */
768 recheck_callback(dir
);
772 dir_set_scanning(dir
, FALSE
);
773 if (dir
->idle_callback
)
775 g_source_remove(dir
->idle_callback
);
776 dir
->idle_callback
= 0;
781 /* See dir_force_update_path() */
782 static void dir_force_update_item(Directory
*dir
, const gchar
*leaf
)
788 items
= g_ptr_array_new();
790 item
= g_hash_table_lookup(dir
->known_items
, leaf
);
794 g_ptr_array_add(items
, item
);
798 for (list
= dir
->users
; list
; list
= list
->next
)
800 DirUser
*user
= (DirUser
*) list
->data
;
802 user
->callback(dir
, DIR_UPDATE
, items
, user
->data
);
808 g_ptr_array_free(items
, TRUE
);
811 static void dir_recheck(Directory
*dir
,
812 const guchar
*path
, const guchar
*leafname
)
814 guchar
*old
= dir
->pathname
;
816 dir
->pathname
= g_strdup(path
);
819 time(&diritem_recent_time
);
820 insert_item(dir
, leafname
);
823 static void to_array(gpointer key
, gpointer value
, gpointer data
)
825 GPtrArray
*array
= (GPtrArray
*) data
;
827 g_ptr_array_add(array
, value
);
830 /* Convert a hash table to an unsorted GPtrArray.
831 * g_ptr_array_free() the result.
833 static GPtrArray
*hash_to_array(GHashTable
*hash
)
837 array
= g_ptr_array_new();
839 g_hash_table_foreach(hash
, to_array
, array
);
844 static gpointer parent_class
;
846 /* Note: dir_cache is never purged, so this shouldn't get called */
847 static void dir_finialize(GObject
*object
)
850 Directory
*dir
= (Directory
*) object
;
852 g_return_if_fail(dir
->users
== NULL
);
854 g_print("[ dir finalize ]\n");
856 free_recheck_list(dir
);
857 set_idle_callback(dir
);
858 if (dir
->rescan_timeout
!= -1)
859 g_source_remove(dir
->rescan_timeout
);
861 dir_merge_new(dir
); /* Ensures new, up and gone are empty */
863 g_ptr_array_free(dir
->up_items
, TRUE
);
864 g_ptr_array_free(dir
->new_items
, TRUE
);
865 g_ptr_array_free(dir
->gone_items
, TRUE
);
867 items
= hash_to_array(dir
->known_items
);
868 free_items_array(items
);
869 g_hash_table_destroy(dir
->known_items
);
872 g_free(dir
->pathname
);
874 G_OBJECT_CLASS(parent_class
)->finalize(object
);
877 static void directory_class_init(gpointer gclass
, gpointer data
)
879 GObjectClass
*object
= (GObjectClass
*) gclass
;
881 parent_class
= g_type_class_peek_parent(gclass
);
883 object
->finalize
= dir_finialize
;
886 static void directory_init(GTypeInstance
*object
, gpointer gclass
)
888 Directory
*dir
= (Directory
*) object
;
890 dir
->known_items
= g_hash_table_new(g_str_hash
, g_str_equal
);
891 dir
->recheck_list
= NULL
;
892 dir
->idle_callback
= 0;
893 dir
->scanning
= FALSE
;
894 dir
->have_scanned
= FALSE
;
897 dir
->needs_update
= TRUE
;
898 dir
->notify_active
= FALSE
;
899 dir
->pathname
= NULL
;
901 dir
->rescan_timeout
= -1;
903 dir
->dnotify_fd
= -1;
906 dir
->new_items
= g_ptr_array_new();
907 dir
->up_items
= g_ptr_array_new();
908 dir
->gone_items
= g_ptr_array_new();
911 static GType
dir_get_type(void)
913 static GType type
= 0;
917 static const GTypeInfo info
=
919 sizeof (DirectoryClass
),
920 NULL
, /* base_init */
921 NULL
, /* base_finalise */
922 directory_class_init
,
923 NULL
, /* class_finalise */
924 NULL
, /* class_data */
930 type
= g_type_register_static(G_TYPE_OBJECT
, "Directory",
937 static Directory
*dir_new(const char *pathname
)
941 dir
= g_object_new(dir_get_type(), NULL
);
943 dir
->pathname
= g_strdup(pathname
);
948 /* Get the names of all files in the directory.
949 * Remove any DirItems that are no longer listed.
950 * Replace the recheck_list with the items found.
952 static void dir_rescan(Directory
*dir
)
958 const char *pathname
;
961 g_return_if_fail(dir
!= NULL
);
963 pathname
= dir
->pathname
;
965 dir
->needs_update
= FALSE
;
967 names
= g_ptr_array_new();
973 null_g_free(&dir
->error
);
974 dir_error_changed(dir
);
977 /* Saves statting the parent for each item... */
978 if (mc_stat(pathname
, &dir
->stat_info
))
980 dir
->error
= g_strdup_printf(_("Can't stat directory: %s"),
982 dir_error_changed(dir
);
983 return; /* Report on attach */
986 d
= mc_opendir(pathname
);
989 dir
->error
= g_strdup_printf(_("Can't open directory: %s"),
991 dir_error_changed(dir
);
992 return; /* Report on attach */
995 dir_set_scanning(dir
, TRUE
);
999 /* Make a list of all the names in the directory */
1000 while ((ent
= mc_readdir(d
)))
1002 if (ent
->d_name
[0] == '.')
1004 if (ent
->d_name
[1] == '\0')
1005 continue; /* Ignore '.' */
1006 if (ent
->d_name
[1] == '.' && ent
->d_name
[2] == '\0')
1007 continue; /* Ignore '..' */
1010 g_ptr_array_add(names
, g_strdup(ent
->d_name
));
1014 /* Compare the list with the current DirItems, removing
1015 * any that are missing.
1017 remove_missing(dir
, names
);
1019 free_recheck_list(dir
);
1021 /* For each name found, mark it as needing to be put on the rescan
1022 * list at some point in the future.
1023 * If the item is new, put a blank place-holder item in the directory.
1025 for (i
= 0; i
< names
->len
; i
++)
1028 guchar
*name
= names
->pdata
[i
];
1030 old
= g_hash_table_lookup(dir
->known_items
, name
);
1033 /* This flag is cleared when the item is added
1034 * to the rescan list.
1036 old
->flags
|= ITEM_FLAG_NEED_RESCAN_QUEUE
;
1042 new = diritem_new(name
);
1043 g_ptr_array_add(dir
->new_items
, new);
1050 /* Ask everyone which items they need to display, and add them to
1051 * the recheck list. Typically, this means we don't waste time
1052 * scanning hidden items.
1055 for (next
= dir
->users
; next
; next
= next
->next
)
1057 DirUser
*user
= (DirUser
*) next
->data
;
1059 DIR_QUEUE_INTERESTING
,
1064 g_ptr_array_free(names
, TRUE
);
1066 set_idle_callback(dir
);
1071 /* Signal handler - don't do anything dangerous here */
1072 static void dnotify_handler(int sig
, siginfo_t
*si
, void *data
)
1074 /* Note: there is currently only one place to store the fd,
1075 * so we'll miss updates to several directories if they happen
1078 dnotify_last_fd
= si
->si_fd
;
1079 dnotify_wakeup_flag
= TRUE
;
1080 write(to_wakeup_pipe
, "\0", 1); /* Wake up! */