Fix error checking for non-existing filenames. Will now always give a

"file not found" message on nonexisting paths or filenames. #351351.
BP



git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@14789 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2006-09-03 11:07:16 +00:00
parent dea41099b4
commit 6b7bb49fc4
2 changed files with 27 additions and 7 deletions

View File

@ -1,3 +1,9 @@
2006-09-03 Christian Stimming <stimming@tuhh.de>
* 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 <hampton@employees.org>
* src/backend/file/gnc-account-xml-v2.c:

View File

@ -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;