diff --git a/ChangeLog b/ChangeLog index 309e783a7e..761afedf3e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-09-03 Christian Stimming + + * src/backend/file/gnc-backend-file.c: Fix error checking for + non-existing filenames. Will now always give a "file not found" + message on nonexisting paths or filenames. #351351. + 2006-08-20 David Hampton * src/backend/file/gnc-account-xml-v2.c: diff --git a/src/backend/file/gnc-backend-file.c b/src/backend/file/gnc-backend-file.c index b4fba1c098..a0e841bbb6 100644 --- a/src/backend/file/gnc-backend-file.c +++ b/src/backend/file/gnc-backend-file.c @@ -199,37 +199,51 @@ file_session_begin(QofBackend *be_start, QofSession *session, gboolean ignore_lock, gboolean create_if_nonexistent) { FileBackend *be = (FileBackend*) be_start; - char *p; ENTER (" "); /* Make sure the directory is there */ - be->dirname = xaccResolveFilePath(book_id); - if (NULL == be->dirname) + be->fullpath = xaccResolveFilePath(book_id); + if (NULL == be->fullpath) { qof_backend_set_error (be_start, ERR_FILEIO_FILE_NOT_FOUND); return; } - be->fullpath = g_strdup (be->dirname); be->be.fullpath = be->fullpath; - p = strrchr (be->dirname, G_DIR_SEPARATOR); - if (p && p != be->dirname) + be->dirname = g_path_get_dirname (be->fullpath); + { struct stat statbuf; int rc; - *p = '\0'; + /* Again check whether the directory can be accessed */ rc = stat (be->dirname, &statbuf); if (rc != 0 || !S_ISDIR(statbuf.st_mode)) { + /* Error on stat or if it isn't a directory means we + cannot find this filename */ qof_backend_set_error (be_start, ERR_FILEIO_FILE_NOT_FOUND); g_free (be->fullpath); be->fullpath = NULL; g_free (be->dirname); be->dirname = NULL; return; } + + /* Now check whether we can stat(2) the file itself */ rc = stat (be->fullpath, &statbuf); + if (rc != 0) + { + /* Error on stat means the file doesn't exist */ + qof_backend_set_error (be_start, ERR_FILEIO_FILE_NOT_FOUND); + g_free (be->fullpath); be->fullpath = NULL; + g_free (be->dirname); be->dirname = NULL; + return; + } if (rc == 0 && S_ISDIR(statbuf.st_mode)) { + /* FIXME: What is actually checked here? Whether the + fullpath erroneously points to a directory or what? + Then the error message should be changed into something + much more clear! */ qof_backend_set_error (be_start, ERR_FILEIO_UNKNOWN_FILE_TYPE); g_free (be->fullpath); be->fullpath = NULL; g_free (be->dirname); be->dirname = NULL;