AUDIT: r14789 - gnucash/trunk - Fix error checking for non-existing filenames. Will now always give a

Christian Stimming cstim at cvs.gnucash.org
Sun Sep 3 07:07:17 EDT 2006


Author: cstim
Date: 2006-09-03 07:07:16 -0400 (Sun, 03 Sep 2006)
New Revision: 14789
Trac: http://svn.gnucash.org/trac/changeset/14789

Modified:
   gnucash/trunk/ChangeLog
   gnucash/trunk/src/backend/file/gnc-backend-file.c
Log:
Fix error checking for non-existing filenames. Will now always give a
"file not found" message on nonexisting paths or filenames. #351351.
BP



Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2006-09-03 10:23:34 UTC (rev 14788)
+++ gnucash/trunk/ChangeLog	2006-09-03 11:07:16 UTC (rev 14789)
@@ -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-20  David Hampton  <hampton at employees.org>
 
 	* src/backend/file/gnc-account-xml-v2.c:

Modified: gnucash/trunk/src/backend/file/gnc-backend-file.c
===================================================================
--- gnucash/trunk/src/backend/file/gnc-backend-file.c	2006-09-03 10:23:34 UTC (rev 14788)
+++ gnucash/trunk/src/backend/file/gnc-backend-file.c	2006-09-03 11:07:16 UTC (rev 14789)
@@ -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, 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;



More information about the gnucash-changes mailing list