1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* test-directory-visit.c - Test program for the directory visiting functions
3 of the GNOME Virtual File System.
5 Copyright (C) 1999 Free Software Foundation
7 The Gnome Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 The Gnome Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with the Gnome Library; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
22 Author: Ettore Perazzoli <ettore@comm2000.it> */
26 #include <libgnomevfs/gnome-vfs-directory.h>
27 #include <libgnomevfs/gnome-vfs-init.h>
32 type_to_string (GnomeVFSFileType type)
35 case GNOME_VFS_FILE_TYPE_UNKNOWN:
37 case GNOME_VFS_FILE_TYPE_REGULAR:
39 case GNOME_VFS_FILE_TYPE_DIRECTORY:
41 case GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK:
42 return "Symbolic Link";
43 case GNOME_VFS_FILE_TYPE_FIFO:
45 case GNOME_VFS_FILE_TYPE_SOCKET:
47 case GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE:
48 return "Character device";
49 case GNOME_VFS_FILE_TYPE_BLOCK_DEVICE:
50 return "Block device";
57 directory_visit_callback (const gchar *rel_path,
58 GnomeVFSFileInfo *info,
59 gboolean recursing_will_loop,
63 printf ("directory_visit_callback -- rel_path `%s' data `%s'\n",
64 rel_path, (gchar *) data);
66 printf (" File `%s'%s (%s, %s), size %ld, mode %04o\n",
68 GNOME_VFS_FILE_INFO_SYMLINK (info) ? " [link]" : "",
69 type_to_string (info->type),
70 gnome_vfs_file_info_get_mime_type (info),
71 (glong) info->size, info->permissions);
73 if (info->name[0] != '.'
74 || (info->name[1] != '.' && info->name[1] != 0)
75 || info->name[2] != 0) {
76 if (recursing_will_loop) {
77 printf ("Loop detected\n");
89 main (int argc, char **argv)
91 GnomeVFSResult result;
94 fprintf (stderr, "Usage: %s <directory>\n", argv[0]);
100 result = gnome_vfs_directory_visit
102 (GNOME_VFS_FILE_INFO_FOLLOW_LINKS
103 | GNOME_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE),
104 GNOME_VFS_DIRECTORY_VISIT_LOOPCHECK,
105 directory_visit_callback,
108 printf ("Result: %s\n", gnome_vfs_result_to_string (result));