dia r4174 - in trunk: . app
- From: hans svn gnome org
- To: svn-commits-list gnome org
- Subject: dia r4174 - in trunk: . app
- Date: Mon, 5 Jan 2009 17:51:55 +0000 (UTC)
Author: hans
Date: Mon Jan 5 17:51:55 2009
New Revision: 4174
URL: http://svn.gnome.org/viewvc/dia?rev=4174&view=rev
Log:
2009-01-05 Hans Breuer <hans breuer org>
* app/diagram.c(diagram_save) : for links resolve to the real filename
before calculating the backup filename and actually overwriting the
file. Fixes bug #501777
Modified:
trunk/ChangeLog
trunk/app/load_save.c
Modified: trunk/app/load_save.c
==============================================================================
--- trunk/app/load_save.c (original)
+++ trunk/app/load_save.c Mon Jan 5 17:51:55 2009
@@ -961,10 +961,11 @@
* indicated, an error message will already have been given to the user.
*/
static int
-diagram_data_save(DiagramData *data, const char *filename)
+diagram_data_save(DiagramData *data, const char *user_filename)
{
FILE *file;
- char *bakname,*tmpname,*dirname,*p;
+ char *bakname=NULL,*tmpname=NULL,*dirname=NULL,*p;
+ char *filename = (char *)user_filename;
int mode,_umask;
int fildes;
int ret;
@@ -977,10 +978,20 @@
&& g_access(filename, W_OK) != 0) {
message_error(_("Not allowed to write to output file %s\n"),
dia_message_filename(filename));
- return FALSE;
+ goto CLEANUP;
}
#endif
+ if (g_file_test(user_filename, G_FILE_TEST_IS_SYMLINK)) {
+ GError *error = NULL;
+ filename = g_file_read_link(user_filename, &error);
+ if (!filename) {
+ message_error("%s", error->message);
+ g_error_free(error);
+ goto CLEANUP;
+ }
+ }
+
/* build the temporary and backup file names */
dirname = g_strdup(filename);
p = strrchr((char *)dirname,G_DIR_SEPARATOR);
@@ -999,7 +1010,7 @@
&& g_access(dirname, W_OK) != 0) {
message_error(_("Not allowed to write temporary files in %s\n"),
dia_message_filename(dirname));
- return FALSE;
+ goto CLEANUP;
}
#endif
@@ -1021,7 +1032,7 @@
if (file==NULL) {
message_error(_("Can't open output file %s: %s\n"),
dia_message_filename(tmpname), strerror(errno));
- return FALSE;
+ goto CLEANUP;
}
fclose(file);
@@ -1033,10 +1044,7 @@
message_error(_("Internal error %d writing file %s\n"),
ret, dia_message_filename(tmpname));
g_unlink(tmpname);
- g_free(tmpname);
- g_free(dirname);
- g_free(bakname);
- return FALSE;
+ goto CLEANUP;
}
/* save succeeded. We kill the old backup file, move the old file into
backup, and the temp file into the new saved file. */
@@ -1048,6 +1056,9 @@
dia_message_filename(filename),
dia_message_filename(filename), strerror(errno));
}
+CLEANUP:
+ if (filename != user_filename)
+ g_free(filename);
g_free(tmpname);
g_free(dirname);
g_free(bakname);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]