After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 527979 - GKeyfile has no obvious API for saving
GKeyfile has no obvious API for saving
Status: RESOLVED DUPLICATE of bug 309224
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2008-04-14 08:13 UTC by Stefan Sauer (gstreamer, gtkdoc dev)
Modified: 2008-10-11 19:17 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Stefan Sauer (gstreamer, gtkdoc dev) 2008-04-14 08:13:18 UTC
Are all applications supposed to do something along the lines below, when saving a keyfile?

gchar *data;
gsize data_size;
    
if ((data = g_key_file_to_data (keyfile, &data_size, NULL))) {
  int fd;

  if ((fd = g_open (preset_path, O_WRONLY|O_CREAT|O_TRUNC))) {
    write(fd, data, data_size);
    close (fd);
  }
  g_free (data);
}

Shouldn't there be 
gboolean
g_key_file_save_to_file (GKeyFile       *key_file,
			   const gchar    *file,
			   GError        **error);
If yes, I can make a patch (adding g_file_error handling above).

Open question:
* do we have a policy for creating backup files (safe rename and create) or should this be left to the application?
Comment 1 Mathias Hasselmann (IRC: tbf) 2008-04-14 08:30:29 UTC
No, you are supposed to do this:

gchar *data;
gsize data_size;

if ((data = g_key_file_to_data (keyfile, &data_size, NULL)))
  g_file_set_contents (preset_path, data, data_size, NULL)

g_free (data);


The policy you asked for is implemented by g_file_set_contents().
Comment 2 Emilio Pozuelo Monfort 2008-10-11 19:07:16 UTC
dup of bug #527979?
Comment 3 Emilio Pozuelo Monfort 2008-10-11 19:09:54 UTC
Sorry, I mean bug #309224
Comment 4 Matthias Clasen 2008-10-11 19:17:52 UTC

*** This bug has been marked as a duplicate of 309224 ***