source: trunk/third/gnome-vfs2/test/test-info.c @ 18576

Revision 18576, 5.7 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18575, 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-info.c - Test program for the `get_file_info()' functionality of the
3   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
25#include <config.h>
26
27#include <glib/gmessages.h>
28#include <libgnomevfs/gnome-vfs-init.h>
29#include <libgnomevfs/gnome-vfs-ops.h>
30#include <stdio.h>
31#include <time.h>
32
33static const gchar *
34type_to_string (GnomeVFSFileType type)
35{
36        switch (type) {
37        case GNOME_VFS_FILE_TYPE_UNKNOWN:
38                return "Unknown";
39        case GNOME_VFS_FILE_TYPE_REGULAR:
40                return "Regular";
41        case GNOME_VFS_FILE_TYPE_DIRECTORY:
42                return "Directory";
43        case GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK:
44                return "Symbolic Link";
45        case GNOME_VFS_FILE_TYPE_FIFO:
46                return "FIFO";
47        case GNOME_VFS_FILE_TYPE_SOCKET:
48                return "Socket";
49        case GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE:
50                return "Character device";
51        case GNOME_VFS_FILE_TYPE_BLOCK_DEVICE:
52                return "Block device";
53        default:
54                return "???";
55        }
56}
57
58
59static void
60print_file_info (const GnomeVFSFileInfo *info)
61{
62#define FLAG_STRING(info, which)                                \
63        (GNOME_VFS_FILE_INFO_##which (info) ? "YES" : "NO")
64
65        printf ("Name              : %s\n", info->name);
66
67        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_TYPE)
68                printf ("Type              : %s\n", type_to_string (info->type));
69
70        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_SYMLINK_NAME && info->symlink_name != NULL)
71                printf ("Symlink to        : %s\n", info->symlink_name);
72
73        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE)
74                printf ("MIME type         : %s\n", info->mime_type);
75
76        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_SIZE)
77                printf ("Size              : %" GNOME_VFS_SIZE_FORMAT_STR "\n",
78                        info->size);
79
80        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT)
81                printf ("Blocks            : %" GNOME_VFS_SIZE_FORMAT_STR "\n",
82                        info->block_count);
83
84        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_IO_BLOCK_SIZE)
85                printf ("I/O block size    : %d\n", info->io_block_size);
86
87        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_FLAGS) {
88                printf ("Local             : %s\n", FLAG_STRING (info, LOCAL));
89                printf ("SUID              : %s\n", FLAG_STRING (info, SUID));
90                printf ("SGID              : %s\n", FLAG_STRING (info, SGID));
91                printf ("Sticky            : %s\n", FLAG_STRING (info, STICKY));
92        }
93
94        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS)
95                printf ("Permissions       : %04o\n", info->permissions);
96
97       
98        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_LINK_COUNT)
99                printf ("Link count        : %d\n", info->link_count);
100       
101        printf ("UID               : %d\n", info->uid);
102        printf ("GID               : %d\n", info->gid);
103
104        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_ATIME)
105                printf ("Access time       : %s", ctime (&info->atime));
106
107        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_MTIME)
108                printf ("Modification time : %s", ctime (&info->mtime));
109
110        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_CTIME)
111                printf ("Change time       : %s", ctime (&info->ctime));
112
113        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_DEVICE)
114                printf ("Device #          : %ld\n", (gulong) info->device);
115
116        if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_INODE)
117                printf ("Inode #           : %ld\n", (gulong) info->inode);
118
119     if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_ACCESS) {
120             printf ("Readable          : %s\n",
121                     (info->permissions&GNOME_VFS_PERM_ACCESS_READABLE?"YES":"NO"));
122             printf ("Writable          : %s\n",
123                     (info->permissions&GNOME_VFS_PERM_ACCESS_WRITABLE?"YES":"NO"));
124             printf ("Executable        : %s\n",
125                     (info->permissions&GNOME_VFS_PERM_ACCESS_EXECUTABLE?"YES":"NO"));
126     }
127     
128
129#undef FLAG_STRING
130}
131
132int
133main (int argc,
134      char **argv)
135{
136        GnomeVFSFileInfo *info;
137        GnomeVFSURI *vfs_uri;
138        GnomeVFSResult result;
139        gchar *uri;
140        int i=1;
141
142        if (argc < 2) {
143                fprintf (stderr, "Usage: %s <uri> [<uri>...]\n", argv[0]);
144                return 1;
145        }
146
147        if (!gnome_vfs_init ()) {
148                fprintf (stderr, "%s: Cannot initialize the GNOME Virtual File System.\n",
149                         argv[0]);
150                return 1;
151        }
152
153        while (i < argc) {
154                const char *path;
155
156                uri = argv[i];
157
158                g_print("Getting info for \"%s\".\n", uri);
159
160                info = gnome_vfs_file_info_new ();
161                result = gnome_vfs_get_file_info (uri,
162                                                  info,
163                                                  (GNOME_VFS_FILE_INFO_GET_MIME_TYPE
164                                                   | GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS
165                                                   | GNOME_VFS_FILE_INFO_FOLLOW_LINKS));
166                if (result != GNOME_VFS_OK) {
167                        fprintf (stderr, "%s: %s: %s\n",
168                                 argv[0], uri, gnome_vfs_result_to_string (result));
169                        i++;
170                        return result;
171                }
172
173                print_file_info (info);
174
175                gnome_vfs_file_info_unref (info);
176
177                vfs_uri = gnome_vfs_uri_new (uri);
178                path = gnome_vfs_uri_get_path (vfs_uri);
179                printf ("Path: %s\n", path ? path : "<null>");
180                printf (gnome_vfs_uri_is_local (vfs_uri)
181                        ? "File is local\n" : "File is not local\n");
182                gnome_vfs_uri_unref (vfs_uri);
183
184                i++;
185        }
186
187        return 0;
188}
Note: See TracBrowser for help on using the repository browser.