annotate lib/local.c @ 22:cc6431f1ca55

2002-09-16 Brian Masney <masneyb@gftp.org> * po/de.po - Updated German translation (from Matthias Haase <matthias_haase@bennewitz.com>) * po/ru.po - Updated Russian translation (from Vitaly Lipatov <LAV@VL3143.spb.edu>)
author masneyb
date Tue, 17 Sep 2002 12:29:05 +0000
parents 3b2dcdefc7e9
children c8ec7877432e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1 /*****************************************************************************/
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2 /* local.c - functions that will use the local system */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
3 /* Copyright (C) 1998-2002 Brian Masney <masneyb@gftp.org> */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
4 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
5 /* This program is free software; you can redistribute it and/or modify */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
6 /* it under the terms of the GNU General Public License as published by */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
7 /* the Free Software Foundation; either version 2 of the License, or */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
8 /* (at your option) any later version. */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
9 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
10 /* This program is distributed in the hope that it will be useful, */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
13 /* GNU General Public License for more details. */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
14 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
15 /* You should have received a copy of the GNU General Public License */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
16 /* along with this program; if not, write to the Free Software */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
18 /*****************************************************************************/
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
19
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
20 #include "gftp.h"
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
21
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
22 static void local_destroy ( gftp_request * request );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
23 static void local_remove_key ( gpointer key,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
24 gpointer value,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
25 gpointer user_data );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
26 static int local_connect ( gftp_request * request );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
27 static void local_disconnect ( gftp_request * request );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
28 static long local_get_file ( gftp_request * request,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
29 const char *filename,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
30 FILE * fd,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
31 off_t startsize );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
32 static int local_put_file ( gftp_request * request,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
33 const char *filename,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
34 FILE * fd,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
35 off_t startsize,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
36 off_t totalsize );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
37 static int local_end_transfer ( gftp_request * request );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
38 static int local_get_next_file ( gftp_request * request,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
39 gftp_file * fle,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
40 FILE * fd );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
41 static int local_list_files ( gftp_request * request );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
42 static off_t local_get_file_size ( gftp_request * request,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
43 const char *filename );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
44 static int local_chdir ( gftp_request * request,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
45 const char *directory );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
46 static int local_rmdir ( gftp_request * request,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
47 const char *directory );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
48 static int local_rmfile ( gftp_request * request,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
49 const char *file );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
50 static int local_mkdir ( gftp_request * request,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
51 const char *directory );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
52 static int local_rename ( gftp_request * request,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
53 const char *oldname,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
54 const char *newname );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
55 static int local_chmod ( gftp_request * request,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
56 const char *file,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
57 int mode );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
58 static int local_set_file_time ( gftp_request * request,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
59 const char *file,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
60 time_t datetime );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
61 static char *make_text_mode ( gftp_file * fle,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
62 mode_t mode );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
63 static gint hash_compare ( gconstpointer path1,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
64 gconstpointer path2 );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
65 static guint hash_function ( gconstpointer key );
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
66
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
67 typedef struct local_protocol_data_tag
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
68 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
69 DIR *dir;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
70 GHashTable *userhash, *grouphash;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
71 } local_protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
72
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
73
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
74 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
75 local_init (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
76 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
77 local_protocol_data *lpd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
78
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
79 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
80
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
81 request->protonum = GFTP_LOCAL_NUM;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
82 request->init = local_init;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
83 request->destroy = local_destroy;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
84 request->connect = local_connect;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
85 request->disconnect = local_disconnect;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
86 request->get_file = local_get_file;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
87 request->put_file = local_put_file;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
88 request->transfer_file = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
89 request->get_next_file_chunk = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
90 request->put_next_file_chunk = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
91 request->end_transfer = local_end_transfer;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
92 request->list_files = local_list_files;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
93 request->get_next_file = local_get_next_file;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
94 request->set_data_type = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
95 request->get_file_size = local_get_file_size;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
96 request->chdir = local_chdir;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
97 request->rmdir = local_rmdir;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
98 request->rmfile = local_rmfile;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
99 request->mkdir = local_mkdir;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
100 request->rename = local_rename;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
101 request->chmod = local_chmod;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
102 request->set_file_time = local_set_file_time;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
103 request->site = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
104 request->parse_url = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
105 request->url_prefix = "file";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
106 request->protocol_name = "Local";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
107 request->need_hostport = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
108 request->need_userpass = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
109 request->use_cache = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
110 request->use_threads = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
111 request->always_connected = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
112 gftp_set_config_options (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
113
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
114 lpd = g_malloc0 (sizeof (*lpd));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
115 request->protocol_data = lpd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
116 lpd->userhash = g_hash_table_new (hash_function, hash_compare);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
117 lpd->grouphash = g_hash_table_new (hash_function, hash_compare);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
118 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
119
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
120
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
121 static void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
122 local_destroy (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
123 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
124 local_protocol_data * lpd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
125
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
126 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
127 g_return_if_fail (request->protonum == GFTP_LOCAL_NUM);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
128
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
129 lpd = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
130 g_hash_table_foreach (lpd->userhash, local_remove_key, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
131 g_hash_table_destroy (lpd->userhash);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
132 g_hash_table_foreach (lpd->grouphash, local_remove_key, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
133 g_hash_table_destroy (lpd->grouphash);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
134 lpd->userhash = lpd->grouphash = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
135 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
136
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
137
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
138 static void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
139 local_remove_key (gpointer key, gpointer value, gpointer user_data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
140 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
141 g_free (value);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
142 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
143
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
144
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
145 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
146 local_connect (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
147 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
148 char tempstr[PATH_MAX];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
149
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
150 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
151 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
152
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
153 /* Just to simulate that we are actually connected */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
154 request->sockfd = (void *) 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
155
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
156 if (request->directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
157 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
158 if (chdir (request->directory) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
159 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
160 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
161 _("Could not change local directory to %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
162 request->directory, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
163 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
164 g_free (request->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
165 request->directory = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
166 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
167
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
168 if (getcwd (tempstr, sizeof (tempstr)) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
169 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
170 tempstr[sizeof (tempstr) - 1] = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
171 request->directory = g_malloc (strlen (tempstr) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
172 strcpy (request->directory, tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
173 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
174 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
175 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
176 _("Could not get current working directory: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
177 g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
178
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
179 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
180 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
181
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
182
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
183 static void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
184 local_disconnect (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
185 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
186 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
187 g_return_if_fail (request->protonum == GFTP_LOCAL_NUM);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
188
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
189 if (request->datafd != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
190 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
191 if (fclose (request->datafd) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
192 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
193 _("Error closing file descriptor: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
194 g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
195 request->datafd = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
196 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
197 request->sockfd = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
198 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
199
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
200
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
201 static long
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
202 local_get_file (gftp_request * request, const char *filename, FILE * fd,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
203 off_t startsize)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
204 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
205 size_t size;
7
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
206 int sock, flags;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
207
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
208 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
209 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
210 g_return_val_if_fail (filename != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
211
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
212 if (fd == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
213 {
7
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
214 flags = O_RDONLY;
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
215 #if defined (_LARGEFILE_SOURCE)
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
216 flags |= O_LARGEFILE;
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
217 #endif
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
218
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
219 if ((sock = open (filename, flags)) < 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
220 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
221 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
222 _("Error: Cannot open local file %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
223 filename, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
224 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
225 }
7
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
226
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
227 if ((request->datafd = fdopen (sock, "rb+")) == NULL)
7
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
228 {
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
229 request->logging_function (gftp_logging_error, request->user_data,
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
230 _("Cannot fdopen() socket for %s: %s\n"),
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
231 filename, g_strerror (errno));
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
232 close (sock);
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
233 return (-2);
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
234 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
235 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
236 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
237 request->datafd = fd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
238
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
239 if (lseek (fileno (request->datafd), 0, SEEK_END) == -1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
240 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
241 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
242 _("Error: Cannot seek on file %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
243 filename, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
244 fclose (request->datafd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
245 request->datafd = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
246 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
247
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
248 if ((size = ftell (request->datafd)) == -1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
249 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
250 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
251 _("Error: Cannot seek on file %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
252 filename, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
253 fclose (request->datafd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
254 request->datafd = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
255 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
256
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
257 if (lseek (fileno (request->datafd), startsize, SEEK_SET) == -1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
258 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
259 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
260 _("Error: Cannot seek on file %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
261 filename, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
262 fclose (request->datafd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
263 request->datafd = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
264 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
265
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
266 return (size);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
267 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
268
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
269
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
270 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
271 local_put_file (gftp_request * request, const char *filename, FILE * fd,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
272 off_t startsize, off_t totalsize)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
273 {
7
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
274 int sock, flags;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
275
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
276 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
277 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
278 g_return_val_if_fail (filename != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
279
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
280 if (fd == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
281 {
7
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
282 flags = O_WRONLY | O_CREAT;
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
283 if (startsize > 0)
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
284 flags |= O_APPEND;
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
285 #if defined (_LARGEFILE_SOURCE)
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
286 flags |= O_LARGEFILE;
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
287 #endif
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
288
5551ab2301fe * Fixed a DND crash
masneyb
parents: 1
diff changeset
289 if ((sock = open (filename, flags, S_IRUSR | S_IWUSR)) < 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
290 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
291 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
292 _("Error: Cannot open local file %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
293 filename, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
294 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
295 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
296
19
3b2dcdefc7e9 2002-09-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 14
diff changeset
297 if ((request->datafd = fdopen (sock, "ab")) == NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
298 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
299 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
300 _("Cannot fdopen() socket for %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
301 filename, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
302 close (sock);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
303 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
304 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
305 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
306 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
307 request->datafd = fd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
308
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
309 if (ftruncate (fileno (request->datafd), startsize) == -1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
310 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
311 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
312 _("Error: Cannot truncate local file %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
313 filename, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
314 fclose (request->datafd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
315 request->datafd = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
316 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
317 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
318
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
319 if (fseek (request->datafd, startsize, SEEK_SET) == -1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
320 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
321 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
322 _("Error: Cannot seek on file %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
323 filename, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
324 fclose (request->datafd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
325 request->datafd = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
326 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
327 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
328 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
329 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
330
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
331
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
332 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
333 local_end_transfer (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
334 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
335 local_protocol_data * lpd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
336
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
337 lpd = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
338 if (lpd->dir)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
339 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
340 closedir (lpd->dir);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
341 lpd->dir = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
342 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
343
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
344 if (request->datafd != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
345 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
346 if (fclose (request->datafd) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
347 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
348 _("Error closing file descriptor: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
349 g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
350
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
351 request->datafd = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
352 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
353
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
354 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
355 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
356
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
357
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
358 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
359 local_get_next_file (gftp_request * request, gftp_file * fle, FILE * fd)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
360 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
361 local_protocol_data * lpd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
362 struct dirent *dirp;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
363 char *user, *group;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
364 struct passwd *pw;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
365 struct group *gr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
366 struct stat st;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
367
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
368 /* the struct passwd and struct group are not thread safe. But,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
369 we're ok here because I have threading turned off for the local
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
370 protocol (see use_threads in local_init above) */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
371 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
372 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
373 g_return_val_if_fail (fle != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
374
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
375 lpd = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
376 memset (fle, 0, sizeof (*fle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
377
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
378 if ((dirp = readdir (lpd->dir)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
379 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
380 closedir (lpd->dir);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
381 lpd->dir = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
382 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
383 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
384
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
385 fle->file = g_malloc (strlen (dirp->d_name) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
386 strcpy (fle->file, dirp->d_name);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
387 if (lstat (fle->file, &st) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
388 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
389 closedir (lpd->dir);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
390 lpd->dir = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
391 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
392 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
393
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
394 if ((user = g_hash_table_lookup (lpd->userhash,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
395 GUINT_TO_POINTER(st.st_uid))) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
396 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
397 fle->user = g_malloc (strlen (user) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
398 strcpy (fle->user, user);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
399 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
400 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
401 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
402 if ((pw = getpwuid (st.st_uid)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
403 fle->user = g_strdup_printf ("%u", st.st_uid);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
404 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
405 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
406 fle->user = g_malloc (strlen (pw->pw_name) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
407 strcpy (fle->user, pw->pw_name);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
408 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
409
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
410 user = g_malloc (strlen (fle->user) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
411 strcpy (user, fle->user);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
412 g_hash_table_insert (lpd->userhash, GUINT_TO_POINTER (st.st_uid), user);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
413 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
414
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
415 if ((group = g_hash_table_lookup (lpd->grouphash,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
416 GUINT_TO_POINTER(st.st_gid))) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
417 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
418 fle->group = g_malloc (strlen (group) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
419 strcpy (fle->group, group);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
420 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
421 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
422 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
423 if ((gr = getgrgid (st.st_gid)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
424 fle->group = g_strdup_printf ("%u", st.st_gid);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
425 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
426 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
427 fle->group = g_malloc (strlen (gr->gr_name) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
428 strcpy (fle->group, gr->gr_name);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
429 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
430
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
431 group = g_malloc (strlen (fle->group) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
432 strcpy (group, fle->group);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
433 g_hash_table_insert (lpd->grouphash, GUINT_TO_POINTER (st.st_gid), group);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
434 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
435
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
436 fle->attribs = make_text_mode (fle, st.st_mode);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
437 fle->datetime = st.st_mtime;
14
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
438
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
439 if ((fle->attribs[0] == 'b' || fle->attribs[0] == 'u' ||
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
440 fle->attribs[0] == 'c'))
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
441 {
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
442 /* FIXME find out if sys/sysmacros.h is portable, and if
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
443 #define {major,minor} is portable. If so, use that instead. If not,
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
444 I will have to add a configure flag to find out the size of the
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
445 major numbers */
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
446 fle->size = ((((int) st.st_rdev) >> 8) & 0xFF) << 16;
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
447 fle->size |= st.st_rdev & 0xFF;
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
448 }
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
449 else
83090328581e * More largefile support. Hopefully all that is left is the configure stuff
masneyb
parents: 7
diff changeset
450 fle->size = st.st_size;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
451
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
452 if (*fle->attribs == 'd')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
453 fle->isdir = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
454 if (*fle->attribs == 'l')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
455 fle->islink = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
456 if (strchr (fle->attribs, 'x') != NULL && !fle->isdir && !fle->islink)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
457 fle->isexe = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
458 if (*fle->attribs == 'b')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
459 fle->isblock = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
460 if (*fle->attribs == 'c')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
461 fle->ischar = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
462 if (*fle->attribs == 's')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
463 fle->issocket = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
464 if (*fle->attribs == 'p')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
465 fle->isfifo = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
466 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
467 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
468
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
469
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
470 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
471 local_list_files (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
472 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
473 local_protocol_data *lpd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
474 char *tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
475
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
476 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
477 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
478 lpd = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
479
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
480 tempstr = g_strconcat (request->directory, "/", NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
481
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
482 if ((lpd->dir = opendir (tempstr)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
483 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
484 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
485 _("Could not get local directory listing %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
486 tempstr, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
487 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
488 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
489 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
490
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
491 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
492 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
493 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
494
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
495
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
496 static off_t
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
497 local_get_file_size (gftp_request * request, const char *filename)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
498 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
499 struct stat st;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
500
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
501 if (stat (filename, &st) == -1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
502 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
503 return (st.st_size);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
504 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
505
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
506
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
507 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
508 local_chdir (gftp_request * request, const char *directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
509 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
510 char tempstr[255];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
511
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
512 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
513 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
514 g_return_val_if_fail (directory != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
515
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
516 if (chdir (directory) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
517 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
518 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
519 _("Successfully changed local directory to %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
520 directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
521 if (request->directory != directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
522 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
523 if (getcwd (tempstr, sizeof (tempstr)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
524 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
525 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
526 _("Could not get current working directory: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
527 g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
528 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
529 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
530 if (request->directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
531 g_free (request->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
532 request->directory = g_malloc (strlen (tempstr) + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
533 strcpy (request->directory, tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
534 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
535 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
536 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
537 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
538 _("Could not change local directory to %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
539 directory, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
540 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
541 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
542
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
543
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
544 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
545 local_rmdir (gftp_request * request, const char *directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
546 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
547 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
548 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
549 g_return_val_if_fail (directory != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
550
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
551 if (rmdir (directory) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
552 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
553 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
554 _("Successfully removed %s\n"), directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
555 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
556 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
557 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
558 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
559 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
560 _("Error: Could not remove directory %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
561 directory, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
562 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
563 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
564 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
565
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
566
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
567 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
568 local_rmfile (gftp_request * request, const char *file)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
569 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
570 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
571 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
572 g_return_val_if_fail (file != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
573
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
574 if (unlink (file) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
575 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
576 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
577 _("Successfully removed %s\n"), file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
578 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
579 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
580 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
581 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
582 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
583 _("Error: Could not remove file %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
584 file, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
585 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
586 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
587 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
588
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
589
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
590 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
591 local_mkdir (gftp_request * request, const char *directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
592 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
593 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
594 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
595 g_return_val_if_fail (directory != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
596
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
597 if (mkdir (directory, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
598 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
599 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
600 _("Successfully made directory %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
601 directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
602 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
603 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
604 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
605 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
606 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
607 _("Error: Could not make directory %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
608 directory, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
609 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
610 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
611 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
612
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
613
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
614 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
615 local_rename (gftp_request * request, const char *oldname,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
616 const char *newname)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
617 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
618 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
619 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
620 g_return_val_if_fail (oldname != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
621 g_return_val_if_fail (newname != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
622
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
623 if (rename (oldname, newname) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
624 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
625 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
626 _("Successfully renamed %s to %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
627 oldname, newname);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
628 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
629 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
630 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
631 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
632 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
633 _("Error: Could not rename %s to %s: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
634 oldname, newname, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
635 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
636 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
637 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
638
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
639
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
640 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
641 local_chmod (gftp_request * request, const char *file, int mode)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
642 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
643 char buf[10];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
644 int newmode;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
645
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
646 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
647 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
648 g_return_val_if_fail (file != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
649
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
650 g_snprintf (buf, sizeof (buf), "%d", mode);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
651 newmode = strtol (buf, NULL, 8);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
652
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
653 if (chmod (file, newmode) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
654 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
655 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
656 _("Successfully changed mode of %s to %d\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
657 file, mode);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
658 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
659 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
660 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
661 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
662 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
663 _("Error: Could not change mode of %s to %d: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
664 file, mode, g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
665 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
666 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
667 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
668
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
669
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
670 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
671 local_set_file_time (gftp_request * request, const char *file,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
672 time_t datetime)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
673 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
674 struct utimbuf time_buf;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
675
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
676 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
677 g_return_val_if_fail (request->protonum == GFTP_LOCAL_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
678 g_return_val_if_fail (file != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
679
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
680 time_buf.modtime = time_buf.actime = datetime;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
681 return (utime (file, &time_buf));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
682 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
683
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
684
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
685 static char *
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
686 make_text_mode (gftp_file * fle, mode_t mode)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
687 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
688 char *str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
689
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
690 str = g_malloc0 (11);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
691
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
692 str[0] = '?';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
693 if (S_ISREG (mode))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
694 str[0] = '-';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
695
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
696 if (S_ISLNK (mode))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
697 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
698 fle->islink = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
699 str[0] = 'l';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
700 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
701
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
702 if (S_ISBLK (mode))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
703 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
704 fle->isblock = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
705 str[0] = 'b';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
706 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
707
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
708 if (S_ISCHR (mode))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
709 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
710 fle->ischar = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
711 str[0] = 'c';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
712 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
713
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
714 if (S_ISFIFO (mode))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
715 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
716 fle->isfifo = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
717 str[0] = 'p';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
718 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
719
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
720 if (S_ISSOCK (mode))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
721 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
722 fle->issocket = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
723 str[0] = 's';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
724 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
725
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
726 if (S_ISDIR (mode))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
727 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
728 fle->isdir = 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
729 str[0] = 'd';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
730 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
731
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
732 str[1] = mode & S_IRUSR ? 'r' : '-';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
733 str[2] = mode & S_IWUSR ? 'w' : '-';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
734
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
735 if ((mode & S_ISUID) && (mode & S_IXUSR))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
736 str[3] = 's';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
737 else if (mode & S_ISUID)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
738 str[3] = 'S';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
739 else if (mode & S_IXUSR)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
740 str[3] = 'x';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
741 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
742 str[3] = '-';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
743
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
744 str[4] = mode & S_IRGRP ? 'r' : '-';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
745 str[5] = mode & S_IWGRP ? 'w' : '-';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
746
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
747 if ((mode & S_ISGID) && (mode & S_IXGRP))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
748 str[6] = 's';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
749 else if (mode & S_ISGID)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
750 str[6] = 'S';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
751 else if (mode & S_IXGRP)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
752 str[6] = 'x';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
753 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
754 str[6] = '-';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
755
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
756 str[7] = mode & S_IROTH ? 'r' : '-';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
757 str[8] = mode & S_IWOTH ? 'w' : '-';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
758
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
759 if ((mode & S_ISVTX) && (mode & S_IXOTH))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
760 str[9] = 't';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
761 else if (mode & S_ISVTX)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
762 str[9] = 'T';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
763 else if (mode & S_IXOTH)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
764 str[9] = 'x';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
765 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
766 str[9] = '-';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
767 return (str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
768 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
769
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
770
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
771 static gint
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
772 hash_compare (gconstpointer path1, gconstpointer path2)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
773 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
774 return (GPOINTER_TO_UINT (path1) == GPOINTER_TO_UINT (path2));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
775 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
776
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
777
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
778 static guint
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
779 hash_function (gconstpointer key)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
780 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
781 return (GPOINTER_TO_UINT (key));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
782 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
783