forked from AuroraMiddleware/gtk
Use g_file_set_contents(). (#308722, Morten Welinder)
2005-06-23 Matthias Clasen <mclasen@redhat.com> * gtk/gtkfilesystemunix.c (bookmark_list_write): Use g_file_set_contents(). (#308722, Morten Welinder)
This commit is contained in:
parent
e9bab05794
commit
af1c6bb05e
@ -1,3 +1,8 @@
|
||||
2005-06-23 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* gtk/gtkfilesystemunix.c (bookmark_list_write): Use
|
||||
g_file_set_contents(). (#308722, Morten Welinder)
|
||||
|
||||
2005-06-22 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* gdk/x11/gdkdnd-x11.c (xdnd_finished_filter): Set the
|
||||
|
@ -1,3 +1,8 @@
|
||||
2005-06-23 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* gtk/gtkfilesystemunix.c (bookmark_list_write): Use
|
||||
g_file_set_contents(). (#308722, Morten Welinder)
|
||||
|
||||
2005-06-22 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* gdk/x11/gdkdnd-x11.c (xdnd_finished_filter): Set the
|
||||
|
@ -1,3 +1,8 @@
|
||||
2005-06-23 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* gtk/gtkfilesystemunix.c (bookmark_list_write): Use
|
||||
g_file_set_contents(). (#308722, Morten Welinder)
|
||||
|
||||
2005-06-22 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* gdk/x11/gdkdnd-x11.c (xdnd_finished_filter): Set the
|
||||
|
@ -42,7 +42,6 @@
|
||||
#include <time.h>
|
||||
|
||||
#define BOOKMARKS_FILENAME ".gtk-bookmarks"
|
||||
#define BOOKMARKS_TMP_FILENAME ".gtk-bookmarks-XXXXXX"
|
||||
|
||||
#define HIDDEN_FILENAME ".hidden"
|
||||
|
||||
@ -1377,13 +1376,12 @@ is_local_uri (const char *uri)
|
||||
}
|
||||
|
||||
static char *
|
||||
bookmark_get_filename (gboolean tmp_file)
|
||||
bookmark_get_filename (void)
|
||||
{
|
||||
char *filename;
|
||||
|
||||
filename = g_build_filename (g_get_home_dir (),
|
||||
tmp_file ? BOOKMARKS_TMP_FILENAME : BOOKMARKS_FILENAME,
|
||||
NULL);
|
||||
BOOKMARKS_FILENAME, NULL);
|
||||
g_assert (filename != NULL);
|
||||
return filename;
|
||||
}
|
||||
@ -1395,7 +1393,7 @@ bookmark_list_read (GSList **bookmarks, GError **error)
|
||||
gchar *contents;
|
||||
gboolean result = FALSE;
|
||||
|
||||
filename = bookmark_get_filename (FALSE);
|
||||
filename = bookmark_get_filename ();
|
||||
*bookmarks = NULL;
|
||||
|
||||
if (g_file_get_contents (filename, &contents, NULL, error))
|
||||
@ -1429,78 +1427,40 @@ bookmark_list_read (GSList **bookmarks, GError **error)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
bookmark_list_write (GSList *bookmarks, GError **error)
|
||||
bookmark_list_write (GSList *bookmarks,
|
||||
GError **error)
|
||||
{
|
||||
char *tmp_filename;
|
||||
char *filename;
|
||||
gboolean result = TRUE;
|
||||
FILE *file;
|
||||
int fd;
|
||||
int saved_errno;
|
||||
|
||||
/* First, write a temporary file */
|
||||
|
||||
tmp_filename = bookmark_get_filename (TRUE);
|
||||
filename = bookmark_get_filename (FALSE);
|
||||
|
||||
fd = g_mkstemp (tmp_filename);
|
||||
if (fd == -1)
|
||||
{
|
||||
saved_errno = errno;
|
||||
goto io_error;
|
||||
}
|
||||
|
||||
if ((file = fdopen (fd, "w")) != NULL)
|
||||
{
|
||||
GSList *l;
|
||||
GString *string;
|
||||
char *filename;
|
||||
GError *tmp_error = NULL;
|
||||
gboolean result;
|
||||
|
||||
string = g_string_new ("");
|
||||
|
||||
for (l = bookmarks; l; l = l->next)
|
||||
if (fputs (l->data, file) == EOF
|
||||
|| fputs ("\n", file) == EOF)
|
||||
{
|
||||
saved_errno = errno;
|
||||
goto io_error;
|
||||
g_string_append (string, l->data);
|
||||
g_string_append_c (string, '\n');
|
||||
}
|
||||
|
||||
if (fclose (file) == EOF)
|
||||
filename = bookmark_get_filename ();
|
||||
|
||||
result = g_file_set_contents (filename, string->str, -1, &tmp_error);
|
||||
|
||||
g_free (filename);
|
||||
g_string_free (string, TRUE);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
saved_errno = errno;
|
||||
goto io_error;
|
||||
}
|
||||
|
||||
if (rename (tmp_filename, filename) == -1)
|
||||
{
|
||||
saved_errno = errno;
|
||||
goto io_error;
|
||||
}
|
||||
|
||||
result = TRUE;
|
||||
goto out;
|
||||
}
|
||||
else
|
||||
{
|
||||
saved_errno = errno;
|
||||
|
||||
/* fdopen() failed, so we can't do much error checking here anyway */
|
||||
close (fd);
|
||||
}
|
||||
|
||||
io_error:
|
||||
|
||||
g_set_error (error,
|
||||
GTK_FILE_SYSTEM_ERROR,
|
||||
GTK_FILE_SYSTEM_ERROR_FAILED,
|
||||
_("Bookmark saving failed: %s"),
|
||||
g_strerror (saved_errno));
|
||||
result = FALSE;
|
||||
tmp_error->message);
|
||||
|
||||
if (fd != -1)
|
||||
unlink (tmp_filename); /* again, not much error checking we can do here */
|
||||
|
||||
out:
|
||||
|
||||
g_free (filename);
|
||||
g_free (tmp_filename);
|
||||
g_error_free (tmp_error);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user