Include why file operations fail in reports

This commit is contained in:
Campbell Barton
2016-02-03 16:37:02 +11:00
parent 622019a085
commit 91bd58869c
2 changed files with 35 additions and 10 deletions

View File

@@ -31,6 +31,7 @@
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include "BLI_blenlib.h" #include "BLI_blenlib.h"
#include "BLI_utildefines.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 (!STREQ(orgname, newname)) {
if (!BLI_exists(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 */ /* to make sure we show what is on disk */
ED_fileselect_clear(wm, sa, sfile); ED_fileselect_clear(wm, sa, sfile);
} }

View File

@@ -69,6 +69,7 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h>
/* ---------- FILE SELECTION ------------ */ /* ---------- FILE SELECTION ------------ */
static FileSelection find_file_mouse_rect(SpaceFile *sfile, ARegion *ar, const rcti *rect_region) 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 */ /* create the file */
if (!BLI_dir_create_recursive(path)) { errno = 0;
BKE_report(op->reports, RPT_ERROR, "Could not create new folder"); 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; 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 */ /* now remember file to jump into editing */
BLI_strncpy(sfile->params->renamefile, name, FILE_MAXFILE); BLI_strncpy(sfile->params->renamefile, name, FILE_MAXFILE);
@@ -2256,7 +2259,7 @@ static int file_delete_poll(bContext *C)
return poll; return poll;
} }
int file_delete_exec(bContext *C, wmOperator *UNUSED(op)) int file_delete_exec(bContext *C, wmOperator *op)
{ {
char str[FILE_MAX]; char str[FILE_MAX];
wmWindowManager *wm = CTX_wm_manager(C); 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 numfiles = filelist_files_ensure(sfile->files);
int i; int i;
bool report_error = false;
errno = 0;
for (i = 0; i < numfiles; i++) { for (i = 0; i < numfiles; i++) {
if (filelist_entry_select_index_get(sfile->files, i, CHECK_FILES)) { if (filelist_entry_select_index_get(sfile->files, i, CHECK_FILES)) {
file = filelist_file(sfile->files, i); file = filelist_file(sfile->files, i);
BLI_make_file_string(G.main->name, str, sfile->params->dir, file->relpath); 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); ED_fileselect_clear(wm, sa, sfile);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL); WM_event_add_notifier(C, NC_SPACE | ND_SPACE_FILE_LIST, NULL);