[ostree] commit: Reject non-regular/non-symlinks earlier with better error message



commit 5034bf3a9d9afc3918fa2ffd106c43de2414072b
Author: Colin Walters <walters verbum org>
Date:   Fri Jan 17 10:32:34 2014 -0500

    commit: Reject non-regular/non-symlinks earlier with better error message
    
    Also avoid _NOT_SUPPORTED as that triggers the --help behavior from
    the commandline; just use _FAILED.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=722410

 src/libostree/ostree-repo-commit.c |   20 ++++++++++++++++++--
 tests/test-basic.sh                |   11 +++++++++++
 2 files changed, 29 insertions(+), 2 deletions(-)
---
diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c
index caa5103..b20f277 100644
--- a/src/libostree/ostree-repo-commit.c
+++ b/src/libostree/ostree-repo-commit.c
@@ -385,7 +385,7 @@ write_object (OstreeRepo         *self,
 
       if (!(temp_file_is_regular || is_symlink))
         {
-          g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                        "Unsupported file type %u", g_file_info_get_file_type (file_info));
           goto out;
         }
@@ -1785,9 +1785,25 @@ write_directory_to_mtree_internal (OstreeRepo                  *self,
 
           if (filter_result == OSTREE_REPO_COMMIT_FILTER_ALLOW)
             {
+              GFileType file_type;
+
               child = g_file_get_child (dir, name);
 
-              if (g_file_info_get_file_type (child_info) == G_FILE_TYPE_DIRECTORY)
+              file_type = g_file_info_get_file_type (child_info);
+              switch (file_type)
+                {
+                case G_FILE_TYPE_DIRECTORY:
+                case G_FILE_TYPE_SYMBOLIC_LINK:
+                case G_FILE_TYPE_REGULAR:
+                  break;
+                default:
+                  g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                               "Unsupported file type: '%s'",
+                               gs_file_get_path_cached (child));
+                  goto out;
+                }
+
+              if (file_type == G_FILE_TYPE_DIRECTORY)
                 {
                   if (!ostree_mutable_tree_ensure_dir (mtree, name, &child_mtree, error))
                     goto out;
diff --git a/tests/test-basic.sh b/tests/test-basic.sh
index 2ac197f..0a9908d 100755
--- a/tests/test-basic.sh
+++ b/tests/test-basic.sh
@@ -317,3 +317,14 @@ stat '--format=%Y' test2-checkout/baz/cow > cow-mtime
 assert_file_has_content cow-mtime 0
 echo "ok content mtime"
 
+cd ${test_tmpdir}
+rm -rf test2-checkout
+mkdir -p test2-checkout
+cd test2-checkout
+mkfifo afifo
+if $OSTREE commit -b test2 -s "Attempt to commit a FIFO" 2>../errmsg; then
+    assert_not_reached "Committing a FIFO unexpetedly succeeded!"
+    assert_file_has_content ../errmsg "Unsupported file type"
+fi
+echo "ok commit of fifo was rejected"
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]