[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50480] trunk/blender/source/blender/ blenkernel/intern/blender.c: minor improvements to saving quit.blend, print the OS error if the file fails to be created or written.
Campbell Barton
ideasman42 at gmail.com
Sun Sep 9 01:07:53 CEST 2012
Revision: 50480
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50480
Author: campbellbarton
Date: 2012-09-08 23:07:53 +0000 (Sat, 08 Sep 2012)
Log Message:
-----------
minor improvements to saving quit.blend, print the OS error if the file fails to be created or written.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/blender.c
Modified: trunk/blender/source/blender/blenkernel/intern/blender.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/blender.c 2012-09-08 19:40:34 UTC (rev 50479)
+++ trunk/blender/source/blender/blenkernel/intern/blender.c 2012-09-08 23:07:53 UTC (rev 50480)
@@ -44,7 +44,8 @@
#include <stdio.h>
#include <stddef.h>
#include <string.h>
-#include <fcntl.h> // for open
+#include <fcntl.h> /* for open */
+#include <errno.h>
#include "MEM_guardedalloc.h"
@@ -716,36 +717,48 @@
MemFileChunk *chunk;
int file;
char str[FILE_MAX];
-
- if ( (U.uiflag & USER_GLOBALUNDO) == 0) return;
-
+
+ if ((U.uiflag & USER_GLOBALUNDO) == 0) {
+ return;
+ }
+
uel = curundo;
if (uel == NULL) {
- printf("No undo buffer to save recovery file\n");
+ fprintf(stderr, "No undo buffer to save recovery file\n");
return;
}
-
+
/* no undo state to save */
- if (undobase.first == undobase.last) return;
-
+ if (undobase.first == undobase.last) {
+ return;
+ }
+
+ /* save the undo state as quit.blend */
BLI_make_file_string("/", str, BLI_temporary_dir(), "quit.blend");
+ errno = 0;
file = BLI_open(str, O_BINARY + O_WRONLY + O_CREAT + O_TRUNC, 0666);
if (file == -1) {
- //XXX error("Unable to save %s, check you have permissions", str);
+ fprintf(stderr, "Unable to save '%s': %s\n",
+ str, errno ? strerror(errno) : "Unknown error opening file");
return;
}
- chunk = uel->memfile.chunks.first;
- while (chunk) {
- if (write(file, chunk->buf, chunk->size) != chunk->size) break;
- chunk = chunk->next;
+ for (chunk = uel->memfile.chunks.first; chunk; chunk = chunk->next) {
+ if (write(file, chunk->buf, chunk->size) != chunk->size) {
+ break;
+ }
}
-
+
close(file);
- if (chunk) ; //XXX error("Unable to save %s, internal error", str);
- else printf("Saved session recovery to %s\n", str);
+ if (chunk) {
+ fprintf(stderr, "Unable to save '%s': %s\n",
+ str, errno ? strerror(errno) : "Unknown error writing file");
+ }
+ else {
+ printf("Saved session recovery to '%s'\n", str);
+ }
}
/* sets curscene */
More information about the Bf-blender-cvs
mailing list