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.
28 #include <libgnome/gnome-init.h>
29 #include <libgnomevfs/gnome-vfs-uri.h>
30 #include <libgnomevfs/gnome-vfs-utils.h>
31 #include <libgnomevfs/gnome-vfs-ops.h>
32 #include <libgnomevfs/gnome-vfs-xfer.h>
34 #include "ev-file-helpers.h"
36 static char *dot_dir = NULL;
37 static char *tmp_dir = NULL;
41 ensure_dir_exists (const char *dir)
43 if (g_file_test (dir, G_FILE_TEST_IS_DIR) == FALSE)
45 if (g_file_test (dir, G_FILE_TEST_EXISTS) == TRUE)
47 g_warning ("%s exists, please move it out of the way.", dir);
51 if (mkdir (dir, 488) != 0)
53 g_warning ("Failed to create directory %s.", dir);
68 dot_dir = g_build_filename (gnome_user_dir_get (),
72 exists = ensure_dir_exists (dot_dir);
80 ev_file_helpers_init (void)
85 ev_file_helpers_shutdown (void)
98 ev_tmp_filename (void)
101 gchar *filename = NULL;
103 if (tmp_dir == NULL) {
107 dirname = g_strdup_printf ("evince-%u", getpid());
108 tmp_dir = g_build_filename (g_get_tmp_dir (),
113 exists = ensure_dir_exists (tmp_dir);
119 if (filename != NULL)
122 basename = g_strdup_printf ("document-%d", count ++);
124 filename = g_build_filename (tmp_dir, basename, NULL);
127 } while (g_file_test (filename, G_FILE_TEST_EXISTS));
133 ev_xfer_uri_simple (const char *from,
137 GnomeVFSResult result;
138 GnomeVFSURI *source_uri;
139 GnomeVFSURI *target_uri;
144 source_uri = gnome_vfs_uri_new (from);
145 target_uri = gnome_vfs_uri_new (to);
147 result = gnome_vfs_xfer_uri (source_uri, target_uri,
148 GNOME_VFS_XFER_DEFAULT | GNOME_VFS_XFER_FOLLOW_LINKS,
149 GNOME_VFS_XFER_ERROR_MODE_ABORT,
150 GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
153 gnome_vfs_uri_unref (target_uri);
154 gnome_vfs_uri_unref (source_uri);
156 if (result != GNOME_VFS_OK)
160 gnome_vfs_result_to_string (result));
161 return (result == GNOME_VFS_OK);