[Bf-blender-cvs] [91bd588] master: Include why file operations fail in reports

Campbell Barton noreply at git.blender.org
Wed Feb 3 06:50:17 CET 2016


Commit: 91bd58869c34d97e01823a3e04010e41724a7f68
Author: Campbell Barton
Date:   Wed Feb 3 16:37:02 2016 +1100
Branches: master
https://developer.blender.org/rB91bd58869c34d97e01823a3e04010e41724a7f68

Include why file operations fail in reports

===================================================================

M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_file/file_ops.c

===================================================================

diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 2d9ecbd..52d0106 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -31,6 +31,7 @@
 
 #include <math.h>
 #include <string.h>
+#include <errno.h>
 
 #include "BLI_blenlib.h"
 #include "BLI_utildefines.h"
@@ -426,7 +427,16 @@ static void renamebutton_cb(bContext *C, void *UNUSED(arg1), char *oldname)
 
 	if (!STREQ(orgname, newname)) {
 		if (!BLI_exists(newname)) {
-			BLI_rename(orgname, newname);
+			errno = 0;
+			if ((BLI_rename(orgname, newname) != 0) ||
+			    !BLI_exists(newname))
+			{
+				WM_reportf(RPT_ERROR,
+				           "Could not rename: %s",
+				           errno ? strerror(errno) : "unknown error");
+				WM_report_banner_show();
+			}
+
 			/* to make sure we show what is on disk */
 			ED_fileselect_clear(wm, sa, sfile);
 		}
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 1b5428c..ddb8b1c 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -69,6 +69,7 @@
 #include <string.h>
 #include <stdio.h>
 #include <ctype.h>
+#include <errno.h>
 
 /* ---------- FILE SELECTION ------------ */
 static FileSelection find_file_mouse_rect(SpaceFile *sfile, ARegion *ar, const rcti *rect_region)
@@ -1783,16 +1784,18 @@ int file_directory_new_exec(bContext *C, wmOperator *op)
 	}
 
 	/* create the file */
-	if (!BLI_dir_create_recursive(path)) {
-		BKE_report(op->reports, RPT_ERROR, "Could not create new folder");
+	errno = 0;
+	if (!BLI_dir_create_recursive(path) ||
+	    /* Should no more be needed,
+	     * now that BLI_dir_create_recursive returns a success state - but kept just in case. */
+	    !BLI_exists(path))
+	{
+		BKE_reportf(op->reports, RPT_ERROR,
+		            "Could not create new folder: %s",
+		            errno ? strerror(errno) : "unknown error");
 		return OPERATOR_CANCELLED;
 	}
 
-	/* Should no more be needed, now that BLI_dir_create_recursive returns a success state - but kept just in case. */
-	if (!BLI_exists(path)) {
-		BKE_report(op->reports, RPT_ERROR, "Could not create new folder");
-		return OPERATOR_CANCELLED;
-	}
 
 	/* now remember file to jump into editing */
 	BLI_strncpy(sfile->params->renamefile, name, FILE_MAXFILE);
@@ -2256,7 +2259,7 @@ static int file_delete_poll(bContext *C)
 	return poll;
 }
 
-int file_delete_exec(bContext *C, wmOperator *UNUSED(op))
+int file_delete_exec(bContext *C, wmOperator *op)
 {
 	char str[FILE_MAX];
 	wmWindowManager *wm = CTX_wm_manager(C);
@@ -2266,14 +2269,26 @@ int file_delete_exec(bContext *C, wmOperator *UNUSED(op))
 	int numfiles = filelist_files_ensure(sfile->files);
 	int i;
 
+	bool report_error = false;
+	errno = 0;
 	for (i = 0; i < numfiles; i++) {
 		if (filelist_entry_select_index_get(sfile->files, i, CHECK_FILES)) {
 			file = filelist_file(sfile->files, i);
 			BLI_make_file_string(G.main->name, str, sfile->params->dir, file->relpath);
-			BLI_delete(str, false, false);
+			if (BLI_delete(str, false, false) != 0 ||
+			    BLI_exists(str))
+			{
+				report_error = true;
+			}
 		}
 	}
 	
+	if (report_error) {
+		BKE_reportf(op->reports, RPT_ERROR,
+		            "Could not delete file: %s",
+		            errno ? strerror(errno) : "unknown error");
+	}
+
 	ED_fileselect_clear(wm, sa, sfile);
 	WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);




More information about the Bf-blender-cvs mailing list