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. |
---|
4 | |
---|
5 | Copyright (C) 1999 Free Software Foundation |
---|
6 | |
---|
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. |
---|
11 | |
---|
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. |
---|
16 | |
---|
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. |
---|
21 | |
---|
22 | Author: Ettore Perazzoli <ettore@comm2000.it> */ |
---|
23 | |
---|
24 | #include <config.h> |
---|
25 | |
---|
26 | #include <libgnomevfs/gnome-vfs-directory.h> |
---|
27 | #include <libgnomevfs/gnome-vfs-init.h> |
---|
28 | #include <stdio.h> |
---|
29 | #include <stdlib.h> |
---|
30 | |
---|
31 | static const gchar * |
---|
32 | type_to_string (GnomeVFSFileType type) |
---|
33 | { |
---|
34 | switch (type) { |
---|
35 | case GNOME_VFS_FILE_TYPE_UNKNOWN: |
---|
36 | return "Unknown"; |
---|
37 | case GNOME_VFS_FILE_TYPE_REGULAR: |
---|
38 | return "Regular"; |
---|
39 | case GNOME_VFS_FILE_TYPE_DIRECTORY: |
---|
40 | return "Directory"; |
---|
41 | case GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK: |
---|
42 | return "Symbolic Link"; |
---|
43 | case GNOME_VFS_FILE_TYPE_FIFO: |
---|
44 | return "FIFO"; |
---|
45 | case GNOME_VFS_FILE_TYPE_SOCKET: |
---|
46 | return "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"; |
---|
51 | default: |
---|
52 | return "???"; |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | static gboolean |
---|
57 | directory_visit_callback (const gchar *rel_path, |
---|
58 | GnomeVFSFileInfo *info, |
---|
59 | gboolean recursing_will_loop, |
---|
60 | gpointer data, |
---|
61 | gboolean *recurse) |
---|
62 | { |
---|
63 | printf ("directory_visit_callback -- rel_path `%s' data `%s'\n", |
---|
64 | rel_path, (gchar *) data); |
---|
65 | |
---|
66 | printf (" File `%s'%s (%s, %s), size %ld, mode %04o\n", |
---|
67 | info->name, |
---|
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); |
---|
72 | |
---|
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"); |
---|
78 | exit (1); |
---|
79 | } |
---|
80 | *recurse = TRUE; |
---|
81 | } else { |
---|
82 | *recurse = FALSE; |
---|
83 | } |
---|
84 | |
---|
85 | return TRUE; |
---|
86 | } |
---|
87 | |
---|
88 | int |
---|
89 | main (int argc, char **argv) |
---|
90 | { |
---|
91 | GnomeVFSResult result; |
---|
92 | |
---|
93 | if (argc != 2) { |
---|
94 | fprintf (stderr, "Usage: %s <directory>\n", argv[0]); |
---|
95 | return 1; |
---|
96 | } |
---|
97 | |
---|
98 | gnome_vfs_init (); |
---|
99 | |
---|
100 | result = gnome_vfs_directory_visit |
---|
101 | (argv[1], |
---|
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, |
---|
106 | "stringa"); |
---|
107 | |
---|
108 | printf ("Result: %s\n", gnome_vfs_result_to_string (result)); |
---|
109 | |
---|
110 | return 0; |
---|
111 | } |
---|