source: trunk/third/gnome-vfs/test/test-directory-visit.c @ 15497

Revision 15497, 3.0 KB checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r15496, which included commits to RCS files with non-trunk default branches.
Line 
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#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <stdio.h>
29#include <gnome.h>
30
31#include "gnome-vfs.h"
32
33
34static const gchar *
35type_to_string (GnomeVFSFileType type)
36{
37        switch (type) {
38        case GNOME_VFS_FILE_TYPE_UNKNOWN:
39                return "Unknown";
40        case GNOME_VFS_FILE_TYPE_REGULAR:
41                return "Regular";
42        case GNOME_VFS_FILE_TYPE_DIRECTORY:
43                return "Directory";
44        case GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK:
45                return "Symbolic Link";
46        case GNOME_VFS_FILE_TYPE_FIFO:
47                return "FIFO";
48        case GNOME_VFS_FILE_TYPE_SOCKET:
49                return "Socket";
50        case GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE:
51                return "Character device";
52        case GNOME_VFS_FILE_TYPE_BLOCK_DEVICE:
53                return "Block device";
54        default:
55                return "???";
56        }
57}
58
59static gboolean
60directory_visit_callback (const gchar *rel_path,
61                          GnomeVFSFileInfo *info,
62                          gboolean recursing_will_loop,
63                          gpointer data,
64                          gboolean *recurse)
65{
66        printf ("directory_visit_callback -- rel_path `%s' data `%s'\n",
67                rel_path, (gchar *) data);
68
69        printf ("  File `%s'%s (%s, %s), size %ld, mode %04o\n",
70                info->name,
71                GNOME_VFS_FILE_INFO_SYMLINK (info) ? " [link]" : "",
72                type_to_string (info->type),
73                gnome_vfs_file_info_get_mime_type (info),
74                (glong) info->size, info->permissions);
75
76        if (info->name[0] != '.'
77            || (info->name[1] != '.' && info->name[1] != 0)
78            || info->name[2] != 0) {
79                if (recursing_will_loop) {
80                        printf ("Loop detected\n");
81                        exit (1);
82                }
83                *recurse = TRUE;
84        } else {
85                *recurse = FALSE;
86        }
87
88        return TRUE;
89}
90
91
92int
93main (int argc, char **argv)
94{
95        GnomeVFSResult result;
96
97        if (argc != 2) {
98                fprintf (stderr, "Usage: %s <directory>\n", argv[0]);
99                return 1;
100        }
101
102        gnome_vfs_init ();
103
104        result = gnome_vfs_directory_visit
105                (argv[1],
106                 (GNOME_VFS_FILE_INFO_FOLLOW_LINKS
107                  | GNOME_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE),
108                 NULL,
109                 GNOME_VFS_DIRECTORY_VISIT_LOOPCHECK,
110                 directory_visit_callback,
111                 "stringa");
112
113        printf ("Result: %s\n", gnome_vfs_result_to_string (result));
114
115        return 0;
116}
Note: See TracBrowser for help on using the repository browser.