2 * Copyright (C) 2002 Jorn Baayen
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include <sys/types.h>
30 #include <glib/gstdio.h>
31 #include <libgnome/gnome-init.h>
32 #include <libgnomevfs/gnome-vfs-uri.h>
33 #include <libgnomevfs/gnome-vfs-utils.h>
34 #include <libgnomevfs/gnome-vfs-ops.h>
35 #include <libgnomevfs/gnome-vfs-xfer.h>
37 #include "ev-file-helpers.h"
39 static gchar *dot_dir = NULL;
40 static gchar *tmp_dir = NULL;
41 static gint count = 0;
44 ensure_dir_exists (const char *dir)
46 if (g_file_test (dir, G_FILE_TEST_IS_DIR))
49 if (g_mkdir (dir, 488) == 0)
53 return g_file_test (dir, G_FILE_TEST_IS_DIR);
55 g_warning ("Failed to create directory %s: %s", dir, strerror (errno));
62 if (dot_dir == NULL) {
65 dot_dir = g_build_filename (gnome_user_dir_get (),
69 exists = ensure_dir_exists (dot_dir);
80 if (tmp_dir == NULL) {
84 dirname = g_strdup_printf ("evince-%u", getpid ());
85 tmp_dir = g_build_filename (g_get_tmp_dir (),
90 exists = ensure_dir_exists (tmp_dir);
98 ev_file_helpers_init (void)
103 ev_file_helpers_shutdown (void)
116 ev_tmp_filename (void)
119 gchar *filename = NULL;
122 if (filename != NULL)
125 basename = g_strdup_printf ("document-%d", count ++);
127 filename = g_build_filename (ev_tmp_dir (),
131 } while (g_file_test (filename, G_FILE_TEST_EXISTS));
137 ev_xfer_uri_simple (const char *from,
141 GnomeVFSResult result;
142 GnomeVFSURI *source_uri;
143 GnomeVFSURI *target_uri;
148 source_uri = gnome_vfs_uri_new (from);
149 target_uri = gnome_vfs_uri_new (to);
151 result = gnome_vfs_xfer_uri (source_uri, target_uri,
152 GNOME_VFS_XFER_DEFAULT | GNOME_VFS_XFER_FOLLOW_LINKS,
153 GNOME_VFS_XFER_ERROR_MODE_ABORT,
154 GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
157 gnome_vfs_uri_unref (target_uri);
158 gnome_vfs_uri_unref (source_uri);
160 if (result != GNOME_VFS_OK)
164 gnome_vfs_result_to_string (result));
165 return (result == GNOME_VFS_OK);