[ostree] core: Fix handling of hardlinks for tar commits



commit 78f435d2451d19215f71f805ccd67613a354e1e3
Author: Colin Walters <walters verbum org>
Date:   Sun Dec 4 14:38:30 2011 -0500

    core: Fix handling of hardlinks for tar commits
    
    We were creating files with the wrong name.  Add a test.

 src/libostree/ostree-repo.c |   11 +++++++++--
 tests/t0006-libarchive.sh   |   35 +++++++++++++++++++++++++++++++++--
 2 files changed, 42 insertions(+), 4 deletions(-)
---
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index 6d541d3..de8230f 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -1730,10 +1730,10 @@ import_libarchive (OstreeRepo           *self,
           if (!file_tree_walk (root, hardlink_split_path, 0, &hardlink_parent, error))
             goto out;
 
-          g_assert (parent);
 
           hardlink_basename = hardlink_split_path->pdata[hardlink_split_path->len - 1];
 
+          g_assert (parent);
           hardlink_source_checksum = g_hash_table_lookup (hardlink_parent->file_checksums, hardlink_basename);
           if (!hardlink_source_checksum)
             {
@@ -1743,8 +1743,15 @@ import_libarchive (OstreeRepo           *self,
               goto out;
             }
 
+          if (g_hash_table_lookup (parent->subdirs, basename))
+            {
+              g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                           "Directory exists: %s", hardlink);
+              goto out;
+            }
+
           g_hash_table_replace (parent->file_checksums,
-                                g_strdup (hardlink_basename),
+                                g_strdup (basename),
                                 g_strdup (hardlink_source_checksum));
           continue;
         }
diff --git a/tests/t0006-libarchive.sh b/tests/t0006-libarchive.sh
index 6f1a9e1..76bcd88 100755
--- a/tests/t0006-libarchive.sh
+++ b/tests/t0006-libarchive.sh
@@ -19,7 +19,7 @@
 
 set -e
 
-echo "1..1"
+echo "1..4"
 
 . libtest.sh
 
@@ -39,5 +39,36 @@ echo not > subdir/2/notempty
 
 tar -c -z -f ../foo.tar.gz .
 cd ..
-$OSTREE commit -s "from tar" -b test2 --tar foo.tar.gz
+$OSTREE commit -s "from tar" -b test-tar --tar foo.tar.gz
 echo "ok tar commit"
+
+cd ${test_tmpdir}
+$OSTREE checkout test-tar test-tar-checkout
+cd test-tar-checkout
+assert_file_has_content hi hi
+assert_file_has_content hello hi
+assert_file_has_content subdir/more contents
+assert_has_file subdir/1/empty
+assert_has_file subdir/2/empty
+cd ${test_tmpdir}
+rm -rf test-tar-checkout
+echo "ok tar contents"
+
+cd ${test_tmpdir}
+mkdir hardlinktest
+cd hardlinktest
+echo other > otherfile
+echo foo1 > foo
+ln foo bar
+tar czf ${test_tmpdir}/hardlinktest.tar.gz .
+cd ${test_tmpdir}
+$OSTREE commit -s 'hardlinks' -b test-hardlinks --tar hardlinktest.tar.gz
+rm -rf hardlinktest
+echo "ok hardlink commit"
+
+cd ${test_tmpdir}
+$OSTREE checkout test-hardlinks test-hardlinks-checkout
+cd test-hardlinks-checkout
+assert_file_has_content foo foo1
+assert_file_has_content bar foo1
+echo "ok hardlink contents"



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