source: trunk/third/gnome-vfs/libgnomevfs/gnome-vfs-cancellable-ops.c @ 15497

Revision 15497, 11.3 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/* gnome-vfs-private-ops.c - Private synchronous operations for the GNOME
3   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@gnu.org> */
23
24/* This file provides private versions of the ops for internal use.  These are
25   meant to be used within the GNOME VFS and its modules: they are not for
26   public consumption through the external API.  */
27
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31#include <string.h>
32
33#include "gnome-vfs.h"
34#include "gnome-vfs-private.h"
35
36GnomeVFSResult
37gnome_vfs_open_uri_cancellable (GnomeVFSHandle **handle,
38                                GnomeVFSURI *uri,
39                                GnomeVFSOpenMode open_mode,
40                                GnomeVFSContext *context)
41{
42        GnomeVFSMethodHandle *method_handle;
43        GnomeVFSResult result;
44
45        g_return_val_if_fail (handle != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
46        g_return_val_if_fail (uri != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
47        g_return_val_if_fail (uri->method != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
48
49        if (gnome_vfs_context_check_cancellation (context))
50                return GNOME_VFS_ERROR_CANCELLED;
51
52        if (uri->method->open == NULL)
53                return GNOME_VFS_ERROR_NOT_SUPPORTED;
54
55        result = uri->method->open (uri->method, &method_handle, uri, open_mode,
56                                    context);
57
58        if (result != GNOME_VFS_OK)
59                return result;
60
61        *handle = gnome_vfs_handle_new (uri, method_handle, open_mode);
62       
63        return GNOME_VFS_OK;
64}
65
66GnomeVFSResult
67gnome_vfs_create_uri_cancellable (GnomeVFSHandle **handle,
68                                  GnomeVFSURI *uri,
69                                  GnomeVFSOpenMode open_mode,
70                                  gboolean exclusive,
71                                  guint perm,
72                                  GnomeVFSContext *context)
73{
74        GnomeVFSMethodHandle *method_handle;
75        GnomeVFSResult result;
76
77        g_return_val_if_fail (handle != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
78        g_return_val_if_fail (uri != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
79
80        if (gnome_vfs_context_check_cancellation (context))
81                return GNOME_VFS_ERROR_CANCELLED;
82
83        if (uri->method->create == NULL)
84                return GNOME_VFS_ERROR_NOT_SUPPORTED;
85
86        result = uri->method->create (uri->method, &method_handle, uri, open_mode,
87                                      exclusive, perm, context);
88        if (result != GNOME_VFS_OK)
89                return result;
90
91        *handle = gnome_vfs_handle_new (uri, method_handle, open_mode);
92
93        return GNOME_VFS_OK;
94}
95
96GnomeVFSResult
97gnome_vfs_close_cancellable (GnomeVFSHandle *handle,
98                             GnomeVFSContext *context)
99{
100        g_return_val_if_fail (handle != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
101
102        if (gnome_vfs_context_check_cancellation (context))
103                return GNOME_VFS_ERROR_CANCELLED;
104
105        return gnome_vfs_handle_do_close (handle, context);
106}
107
108GnomeVFSResult
109gnome_vfs_read_cancellable (GnomeVFSHandle *handle,
110                            gpointer buffer,
111                            GnomeVFSFileSize bytes,
112                            GnomeVFSFileSize *bytes_written,
113                            GnomeVFSContext *context)
114{
115        g_return_val_if_fail (handle != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
116
117        if (gnome_vfs_context_check_cancellation (context))
118                return GNOME_VFS_ERROR_CANCELLED;
119
120        return gnome_vfs_handle_do_read (handle, buffer, bytes, bytes_written,
121                                         context);
122}
123
124GnomeVFSResult
125gnome_vfs_write_cancellable (GnomeVFSHandle *handle,
126                             gconstpointer buffer,
127                             GnomeVFSFileSize bytes,
128                             GnomeVFSFileSize *bytes_written,
129                             GnomeVFSContext *context)
130{
131        g_return_val_if_fail (handle != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
132
133        if (gnome_vfs_context_check_cancellation (context))
134                return GNOME_VFS_ERROR_CANCELLED;
135
136        return gnome_vfs_handle_do_write (handle, buffer, bytes,
137                                          bytes_written, context);
138}
139
140GnomeVFSResult
141gnome_vfs_seek_cancellable (GnomeVFSHandle *handle,
142                            GnomeVFSSeekPosition whence,
143                            GnomeVFSFileOffset offset,
144                            GnomeVFSContext *context)
145{
146        g_return_val_if_fail (handle != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
147
148        if (gnome_vfs_context_check_cancellation (context))
149                return GNOME_VFS_ERROR_CANCELLED;
150
151        return gnome_vfs_handle_do_seek (handle, whence, offset, context);
152}
153
154GnomeVFSResult
155gnome_vfs_get_file_info_uri_cancellable (GnomeVFSURI *uri,
156                                         GnomeVFSFileInfo *info,
157                                         GnomeVFSFileInfoOptions options,
158                                         GnomeVFSContext *context)
159{
160        GnomeVFSResult result;
161
162        if (gnome_vfs_context_check_cancellation (context))
163                return GNOME_VFS_ERROR_CANCELLED;
164
165        if (uri->method->get_file_info == NULL)
166                return GNOME_VFS_ERROR_NOT_SUPPORTED;
167
168        result = uri->method->get_file_info (uri->method, uri, info, options,
169                                             context);
170
171        return result;
172}
173
174GnomeVFSResult
175gnome_vfs_get_file_info_from_handle_cancellable (GnomeVFSHandle *handle,
176                                                 GnomeVFSFileInfo *info,
177                                                 GnomeVFSFileInfoOptions options,
178                                                 GnomeVFSContext *context)
179
180{
181        GnomeVFSResult result;
182
183        g_return_val_if_fail (handle != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
184
185        if (gnome_vfs_context_check_cancellation (context))
186                return GNOME_VFS_ERROR_CANCELLED;
187
188
189        result =  gnome_vfs_handle_do_get_file_info (handle, info,
190                                                     options,
191                                                     context);
192
193        return result;
194}
195
196GnomeVFSResult
197gnome_vfs_truncate_uri_cancellable (GnomeVFSURI *uri,
198                                    GnomeVFSFileSize length,
199                                    GnomeVFSContext *context)
200{
201        g_return_val_if_fail (uri != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
202
203        if (gnome_vfs_context_check_cancellation (context))
204                return GNOME_VFS_ERROR_CANCELLED;
205
206        if (uri->method->truncate == NULL)
207                return GNOME_VFS_ERROR_NOT_SUPPORTED;
208
209        return uri->method->truncate(uri->method, uri, length, context);
210}
211
212GnomeVFSResult
213gnome_vfs_truncate_handle_cancellable (GnomeVFSHandle *handle,
214                                       GnomeVFSFileSize length,
215                                       GnomeVFSContext *context)
216{
217        g_return_val_if_fail (handle != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
218
219        if (gnome_vfs_context_check_cancellation (context))
220                return GNOME_VFS_ERROR_CANCELLED;
221
222        return gnome_vfs_handle_do_truncate (handle, length, context);
223}
224
225GnomeVFSResult
226gnome_vfs_make_directory_for_uri_cancellable (GnomeVFSURI *uri,
227                                              guint perm,
228                                              GnomeVFSContext *context)
229{
230        GnomeVFSResult result;
231
232        g_return_val_if_fail (uri != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
233
234        if (gnome_vfs_context_check_cancellation (context))
235                return GNOME_VFS_ERROR_CANCELLED;
236
237        if (uri->method->make_directory == NULL)
238                return GNOME_VFS_ERROR_NOT_SUPPORTED;
239
240        result = uri->method->make_directory (uri->method, uri, perm, context);
241        return result;
242}
243
244GnomeVFSResult
245gnome_vfs_find_directory_cancellable (GnomeVFSURI *near_uri,
246                                      GnomeVFSFindDirectoryKind kind,
247                                      GnomeVFSURI **result_uri,
248                                      gboolean create_if_needed,
249                                      gboolean find_if_needed,
250                                      guint permissions,
251                                      GnomeVFSContext *context)
252{
253        GnomeVFSResult result;
254
255        g_return_val_if_fail (result_uri != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
256
257        if (gnome_vfs_context_check_cancellation (context))
258                return GNOME_VFS_ERROR_CANCELLED;
259
260        if (near_uri != NULL) {
261                gnome_vfs_uri_ref (near_uri);
262        } else {
263                /* assume file: method and the home directory */
264                near_uri = gnome_vfs_uri_new (g_get_home_dir());
265        }
266
267        g_assert (near_uri != NULL);
268               
269        if (near_uri->method->find_directory == NULL) {
270                gnome_vfs_uri_unref (near_uri);
271                return GNOME_VFS_ERROR_NOT_SUPPORTED;
272        }
273
274        result = near_uri->method->find_directory (near_uri->method, near_uri, kind,
275                result_uri, create_if_needed, find_if_needed, permissions, context);
276
277        gnome_vfs_uri_unref (near_uri);
278        return result;
279}
280
281GnomeVFSResult
282gnome_vfs_remove_directory_from_uri_cancellable (GnomeVFSURI *uri,
283                                                 GnomeVFSContext *context)
284{
285        GnomeVFSResult result;
286
287        g_return_val_if_fail (uri != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
288
289        if (gnome_vfs_context_check_cancellation (context)) {
290                return GNOME_VFS_ERROR_CANCELLED;
291        }
292
293        if (uri->method->remove_directory == NULL) {
294                return GNOME_VFS_ERROR_NOT_SUPPORTED;
295        }
296
297        result = uri->method->remove_directory (uri->method, uri, context);
298        return result;
299}
300
301GnomeVFSResult
302gnome_vfs_unlink_from_uri_cancellable (GnomeVFSURI *uri,
303                                       GnomeVFSContext *context)
304{
305        g_return_val_if_fail (uri != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
306
307        if (gnome_vfs_context_check_cancellation (context)) {
308                return GNOME_VFS_ERROR_CANCELLED;
309        }
310
311        if (uri->method->unlink == NULL) {
312                return GNOME_VFS_ERROR_NOT_SUPPORTED;
313        }
314
315        return uri->method->unlink (uri->method, uri, context);
316}
317
318GnomeVFSResult
319gnome_vfs_create_symbolic_link_cancellable (GnomeVFSURI *uri,
320                                            const char *target_reference,
321                                            GnomeVFSContext *context)
322{
323        g_return_val_if_fail (uri != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
324       
325        if (gnome_vfs_context_check_cancellation (context)) {
326                return GNOME_VFS_ERROR_CANCELLED;
327        }
328
329        if (uri->method->create_symbolic_link == NULL) {
330                return GNOME_VFS_ERROR_NOT_SUPPORTED;
331        }
332
333        return uri->method->create_symbolic_link (uri->method, uri, target_reference, context);
334}
335
336static gboolean
337check_same_fs_in_uri (GnomeVFSURI *a,
338                      GnomeVFSURI *b)
339{
340        if (a->method != b->method) {
341                return FALSE;
342        }
343       
344        if (strcmp (a->method_string, b->method_string) != 0) {
345                return FALSE;
346        }
347
348        return TRUE;
349}
350
351GnomeVFSResult
352gnome_vfs_move_uri_cancellable (GnomeVFSURI *old,
353                                GnomeVFSURI *new,
354                                gboolean force_replace,
355                                GnomeVFSContext *context)
356{
357        g_return_val_if_fail (old != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
358        g_return_val_if_fail (new != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
359
360        if (gnome_vfs_context_check_cancellation (context))
361                return GNOME_VFS_ERROR_CANCELLED;
362
363        if (! check_same_fs_in_uri (old, new))
364                return GNOME_VFS_ERROR_NOT_SAME_FILE_SYSTEM;
365
366        if (old->method->move == NULL)
367                return GNOME_VFS_ERROR_NOT_SUPPORTED;
368
369        return old->method->move (old->method, old, new, force_replace, context);
370}
371
372GnomeVFSResult
373gnome_vfs_check_same_fs_uris_cancellable (GnomeVFSURI *a,
374                                          GnomeVFSURI *b,
375                                          gboolean *same_fs_return,
376                                          GnomeVFSContext *context)
377{
378        g_return_val_if_fail (a != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
379        g_return_val_if_fail (b != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
380        g_return_val_if_fail (same_fs_return != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
381
382        if (gnome_vfs_context_check_cancellation (context))
383                return GNOME_VFS_ERROR_CANCELLED;
384
385        if (! check_same_fs_in_uri (a, b)) {
386                *same_fs_return = FALSE;
387                return GNOME_VFS_OK;
388        }
389
390        if (a->method->check_same_fs == NULL) {
391                *same_fs_return = FALSE;
392                return GNOME_VFS_OK;
393        }
394
395        return a->method->check_same_fs (a->method, a, b, same_fs_return, context);
396}
397
398GnomeVFSResult
399gnome_vfs_set_file_info_cancellable (GnomeVFSURI *a,
400                                     const GnomeVFSFileInfo *info,
401                                     GnomeVFSSetFileInfoMask mask,
402                                     GnomeVFSContext *context)
403{
404        g_return_val_if_fail (a != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
405        g_return_val_if_fail (info != NULL, GNOME_VFS_ERROR_BAD_PARAMETERS);
406
407        if (gnome_vfs_context_check_cancellation (context))
408                return GNOME_VFS_ERROR_CANCELLED;
409
410        if (a->method->set_file_info == NULL)
411                return GNOME_VFS_ERROR_NOT_SUPPORTED;
412
413        return a->method->set_file_info (a->method, a, info, mask, context);
414}
Note: See TracBrowser for help on using the repository browser.