r14883 - gnucash/branches/2.0 - Fix error checking for non-existing filenames. #351351.
Derek Atkins
warlord at cvs.gnucash.org
Fri Sep 22 23:08:51 EDT 2006
Author: warlord
Date: 2006-09-22 23:08:49 -0400 (Fri, 22 Sep 2006)
New Revision: 14883
Trac: http://svn.gnucash.org/trac/changeset/14883
Modified:
gnucash/branches/2.0/
gnucash/branches/2.0/ChangeLog
gnucash/branches/2.0/src/backend/file/gnc-backend-file.c
Log:
Fix error checking for non-existing filenames. #351351.
Will now always give a "file not found" message on nonexisting
paths or filenames.
Merge from r14789.
Property changes on: gnucash/branches/2.0
___________________________________________________________________
Name: svk:merge
- d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/branches/2.0:13330
d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/trunk:13282
+ d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/branches/2.0:13334
d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/trunk:13282
Modified: gnucash/branches/2.0/ChangeLog
===================================================================
--- gnucash/branches/2.0/ChangeLog 2006-09-22 20:26:29 UTC (rev 14882)
+++ gnucash/branches/2.0/ChangeLog 2006-09-23 03:08:49 UTC (rev 14883)
@@ -1,3 +1,9 @@
+2006-09-03 Christian Stimming <stimming at 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-22 Chris Shoemaker <chris.shoemaker at cox.net>
Drop gtktreedatalist (and gnctreemodelsort) from the build because it can
Modified: gnucash/branches/2.0/src/backend/file/gnc-backend-file.c
===================================================================
--- gnucash/branches/2.0/src/backend/file/gnc-backend-file.c 2006-09-22 20:26:29 UTC (rev 14882)
+++ gnucash/branches/2.0/src/backend/file/gnc-backend-file.c 2006-09-23 03:08:49 UTC (rev 14883)
@@ -199,37 +199,51 @@
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, '/');
- 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;
More information about the gnucash-changes
mailing list