From: Tim Kientzle Date: Mon, 14 Sep 2009 04:38:40 +0000 (-0400) Subject: Various fixes to symlink-related tests: X-Git-Tag: v2.8.0~350 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80de4f1b3e850164de1954c93bdaf45f5008796a;p=thirdparty%2Flibarchive.git Various fixes to symlink-related tests: * canSymlink() is no longer hardwired to always return false * cpio/test/test_gcpio_compat now has symlink-free test archives for use on platforms that lack symlink support * several other tests have slightly finer-grained avoidance of checks that rely on symlink support SVN-Revision: 1458 --- diff --git a/cpio/test/main.c b/cpio/test/main.c index d0d58013d..a525562de 100644 --- a/cpio/test/main.c +++ b/cpio/test/main.c @@ -1331,7 +1331,7 @@ int canSymlink(void) { /* Remember the test result */ - static int value = 0, tested = 1; + static int value = 0, tested = 0; if (tested) return (value); diff --git a/cpio/test/test_gcpio_compat.c b/cpio/test/test_gcpio_compat.c index 2a98dfc66..1e1e594bd 100644 --- a/cpio/test/test_gcpio_compat.c +++ b/cpio/test/test_gcpio_compat.c @@ -45,8 +45,11 @@ unpack_test(const char *from, const char *options, const char *se) assertEqualInt(r, 0); /* Verify that nothing went to stderr. */ - failure("Error invoking %s -i %s < %s", testprog, options, from); - assertTextFileContents(se, "unpack.err"); + if (canSymlink()) { + failure("Error invoking %s -i %s < %s", + testprog, options, from); + assertTextFileContents(se, "unpack.err"); + } /* * Verify unpacked files. @@ -61,7 +64,8 @@ unpack_test(const char *from, const char *options, const char *se) assertIsHardlink("linkfile", "file"); /* Symlink */ - assertIsSymlink("symlink", "file"); + if (canSymlink()) + assertIsSymlink("symlink", "file"); /* dir */ assertIsDir("dir", 0775); @@ -74,9 +78,25 @@ DEFINE_TEST(test_gcpio_compat) assertUmask(0); /* Dearchive sample files with a variety of options. */ - unpack_test("test_gcpio_compat_ref.bin", "--no-preserve-owner", "1 block\n"); - unpack_test("test_gcpio_compat_ref.crc", "--no-preserve-owner", "2 blocks\n"); - unpack_test("test_gcpio_compat_ref.newc", "--no-preserve-owner", "2 blocks\n"); - /* gcpio-2.9 only reads 6 blocks here */ - unpack_test("test_gcpio_compat_ref.ustar", "--no-preserve-owner", "7 blocks\n"); + if (canSymlink()) { + unpack_test("test_gcpio_compat_ref.bin", + "--no-preserve-owner", "1 block\n"); + unpack_test("test_gcpio_compat_ref.crc", + "--no-preserve-owner", "2 blocks\n"); + unpack_test("test_gcpio_compat_ref.newc", + "--no-preserve-owner", "2 blocks\n"); + /* gcpio-2.9 only reads 6 blocks here */ + unpack_test("test_gcpio_compat_ref.ustar", + "--no-preserve-owner", "7 blocks\n"); + } else { + unpack_test("test_gcpio_compat_ref_nosym.bin", + "--no-preserve-owner", "1 block\n"); + unpack_test("test_gcpio_compat_ref_nosym.crc", + "--no-preserve-owner", "2 blocks\n"); + unpack_test("test_gcpio_compat_ref_nosym.newc", + "--no-preserve-owner", "2 blocks\n"); + /* gcpio-2.9 only reads 6 blocks here */ + unpack_test("test_gcpio_compat_ref_nosym.ustar", + "--no-preserve-owner", "7 blocks\n"); + } } diff --git a/cpio/test/test_gcpio_compat_ref_nosym.bin.uu b/cpio/test/test_gcpio_compat_ref_nosym.bin.uu new file mode 100644 index 000000000..a3e87a716 --- /dev/null +++ b/cpio/test/test_gcpio_compat_ref_nosym.bin.uu @@ -0,0 +1,15 @@ +begin 644 test_gcpio_compat_ref_nosym.bin +MQW%4`-[Z_4'H`^@#`@`VNZU*NQX$``````!D:7(`QW%4`-SZI('H`^@#`@`G +MNZU*NQX%````"@!F:6QE```Q,C,T-38W.#D*QW%4`-SZI('H`^@#`@`GNZU* +MNQX)````"@!L:6YK9FEL90``,3(S-#4V-S@Y"L=Q``````````````$````` +M````"P``````5%)!24Q%4B$A(0`````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +1```````````````````````` +` +end diff --git a/cpio/test/test_gcpio_compat_ref_nosym.crc.uu b/cpio/test/test_gcpio_compat_ref_nosym.crc.uu new file mode 100644 index 000000000..38ba9fe14 --- /dev/null +++ b/cpio/test/test_gcpio_compat_ref_nosym.crc.uu @@ -0,0 +1,15 @@ +begin 644 test_gcpio_compat_ref_nosym.crc +M,#copy.out 2>copy.err", testprog); assertEqualInt(r, 0); -#if !defined(_WIN32) || defined(__CYGWIN__) failure("Regular -p without -L should preserve symlinks."); assertIsSymlink("copy/symlink", NULL); -#endif r = systemf(CAT " filelist | %s -pd -L copy-L >copy-L.out 2>copy-L.err", testprog); assertEqualInt(r, 0); @@ -68,32 +74,22 @@ DEFINE_TEST(test_option_L_upper) assertEqualInt(r, 0); assertMakeDir("unpack", 0755); -#if defined(_WIN32) && !defined(__CYGWIN__) assertChdir("unpack"); - r = systemf("type ..\\archive.out | %s -i >unpack.out 2>unpack.err", testprog); + r = systemf(CAT " ../archive.out | %s -i >unpack.out 2>unpack.err", testprog); assertChdir(".."); -#else - r = systemf("cat archive.out | (cd unpack ; %s -i >unpack.out 2>unpack.err)", testprog); -#endif failure("Error invoking %s -i", testprog); assertEqualInt(r, 0); -#if !defined(_WIN32) || defined(__CYGWIN__) assertIsSymlink("unpack/symlink", NULL); -#endif r = systemf(CAT " filelist | %s -oL >archive-L.out 2>archive-L.err", testprog); failure("Error invoking %s -oL", testprog); assertEqualInt(r, 0); assertMakeDir("unpack-L", 0755); -#if defined(_WIN32) && !defined(__CYGWIN__) assertChdir("unpack-L"); - r = systemf("type ..\\archive-L.out | %s -i >unpack-L.out 2>unpack-L.err", testprog); + r = systemf(CAT " ../archive-L.out | %s -i >unpack-L.out 2>unpack-L.err", testprog); assertChdir(".."); -#else - r = systemf("cat archive-L.out | (cd unpack-L ; %s -i >unpack-L.out 2>unpack-L.err)", testprog); -#endif failure("Error invoking %s -i < archive-L.out", testprog); assertEqualInt(r, 0); assertIsReg("unpack-L/symlink", -1); diff --git a/libarchive/config_freebsd.h b/libarchive/config_freebsd.h index 2ebfe2091..1e27c2cd1 100644 --- a/libarchive/config_freebsd.h +++ b/libarchive/config_freebsd.h @@ -117,7 +117,7 @@ #define HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC 1 #define HAVE_STRUCT_STAT_ST_FLAGS 1 #define HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC 1 -#define HAVE_SYMLINK 1 +/* #define HAVE_SYMLINK 1 */ #define HAVE_SYS_IOCTL_H 1 #define HAVE_SYS_SELECT_H 1 #define HAVE_SYS_STAT_H 1 diff --git a/libarchive/test/main.c b/libarchive/test/main.c index 0436ca6d5..18693d4ef 100644 --- a/libarchive/test/main.c +++ b/libarchive/test/main.c @@ -1330,7 +1330,7 @@ int canSymlink(void) { /* Remember the test result */ - static int value = 0, tested = 1; + static int value = 0, tested = 0; if (tested) return (value); diff --git a/tar/test/main.c b/tar/test/main.c index 51a468393..ea8686591 100644 --- a/tar/test/main.c +++ b/tar/test/main.c @@ -1141,6 +1141,9 @@ is_symlink(const char *file, int line, { #if defined(_WIN32) && !defined(__CYGWIN__) assertion_count(file, line); + /* Windows sort-of has real symlinks, but they're only usable + * by privileged users and are crippled even then, so there's + * really not much point in bothering with this. */ return (0); #else char buff[300]; @@ -1330,7 +1333,7 @@ int canSymlink(void) { /* Remember the test result */ - static int value = 0, tested = 1; + static int value = 0, tested = 0; if (tested) return (value); diff --git a/tar/test/test_strip_components.c b/tar/test/test_strip_components.c index 2ae108184..c9028a4d7 100644 --- a/tar/test/test_strip_components.c +++ b/tar/test/test_strip_components.c @@ -47,8 +47,10 @@ DEFINE_TEST(test_strip_components) assertEqualInt(1, touch("d1/d2/f1")); assertMakeHardlink("l1", "d1/d2/f1"); assertMakeHardlink("d1/l2", "d1/d2/f1"); - assertMakeSymlink("s1", "d1/d2/f1"); - assertMakeSymlink("d1/s2", "d2/f1"); + if (canSymlink()) { + assertMakeSymlink("s1", "d1/d2/f1"); + assertMakeSymlink("d1/s2", "d2/f1"); + } assertChdir(".."); assertEqualInt(0, systemf("%s -cf test.tar d0", testprog)); @@ -62,12 +64,11 @@ DEFINE_TEST(test_strip_components) failure("d0/d1/ is too short and should not get restored"); assertFileNotExists("target/d1"); failure("d0/d1/s2 is a symlink to something that won't be extracted"); -#if !defined(_WIN32) || defined(__CYGWIN__) + /* If platform supports symlinks, target/s2 is a broken symlink. */ + /* If platform does not support symlink, target/s2 doesn't exist. */ assertFileNotExists("target/s2"); - assertIsSymlink("target/s2", "d2/f1"); -#else - skipping("symlink"); -#endif + if (canSymlink()) + assertIsSymlink("target/s2", "d2/f1"); failure("d0/d1/d2 should be extracted"); assertIsDir("target/d2", -1); diff --git a/tar/test/test_symlink_dir.c b/tar/test/test_symlink_dir.c index 3a50e08cc..33d59579f 100644 --- a/tar/test/test_symlink_dir.c +++ b/tar/test/test_symlink_dir.c @@ -49,10 +49,6 @@ mkfile(const char *name, int mode, const char *contents, size_t size) DEFINE_TEST(test_symlink_dir) { -#if !defined(_WIN32) || defined(__CYGWIN__) - struct stat st; - struct stat st2; -#endif assertUmask(0); assertMakeDir("source", 0755); @@ -76,27 +72,25 @@ DEFINE_TEST(test_symlink_dir) * Extract with -x and without -P. */ assertMakeDir("dest1", 0755); - /* "dir" is a symlink to an existing "real_dir" */ + /* "dir" is a symlink to an existing "dest1/real_dir" */ assertMakeDir("dest1/real_dir", 0755); -#if !defined(_WIN32) || defined(__CYGWIN__) - assertEqualInt(0, symlink("real_dir", "dest1/dir")); - /* "dir2" is a symlink to a non-existing "real_dir2" */ - assertEqualInt(0, symlink("real_dir2", "dest1/dir2")); -#else - skipping("symlink does not work on this platform"); -#endif + if (canSymlink()) { + assertMakeSymlink("dest1/dir", "real_dir"); + /* "dir2" is a symlink to a non-existing "real_dir2" */ + assertMakeSymlink("dest1/dir2", "real_dir2"); + } else { + skipping("some symlink checks"); + } /* "dir3" is a symlink to an existing "non_dir3" */ assertEqualInt(0, mkfile("dest1/non_dir3", 0755, "abcdef", 6)); assertMakeSymlink("dest1/dir3", "non_dir3"); /* "file" is a symlink to existing "real_file" */ assertEqualInt(0, mkfile("dest1/real_file", 0755, "abcdefg", 7)); - assertMakeSymlink("dest1/file", "real_file"); -#if !defined(_WIN32) || defined(__CYGWIN__) - /* "file2" is a symlink to non-existing "real_file2" */ - assertMakeSymlink("dest1/file2", "real_file2"); -#else - skipping("symlink does not work on this platform"); -#endif + if (canSymlink()) { + assertMakeSymlink("dest1/file", "real_file"); + /* "file2" is a symlink to non-existing "real_file2" */ + assertMakeSymlink("dest1/file2", "real_file2"); + } assertEqualInt(0, systemf("%s -xf test.tar -C dest1", testprog)); /* dest1/dir symlink should be replaced */ @@ -121,47 +115,25 @@ DEFINE_TEST(test_symlink_dir) assertMakeDir("dest2", 0755); /* "dir" is a symlink to existing "real_dir" */ assertMakeDir("dest2/real_dir", 0755); -#if !defined(_WIN32) || defined(__CYGWIN__) assertMakeSymlink("dest2/dir", "real_dir"); /* "dir2" is a symlink to a non-existing "real_dir2" */ assertMakeSymlink("dest2/dir2", "real_dir2"); -#else - skipping("symlink does not work on this platform"); -#endif /* "dir3" is a symlink to an existing "non_dir3" */ assertEqualInt(0, mkfile("dest2/non_dir3", 0755, "abcdefgh", 8)); assertMakeSymlink("dest2/dir3", "non_dir3"); /* "file" is a symlink to existing "real_file" */ assertEqualInt(0, mkfile("dest2/real_file", 0755, "abcdefghi", 9)); assertMakeSymlink("dest2/file", "real_file"); -#if !defined(_WIN32) || defined(__CYGWIN__) /* "file2" is a symlink to non-existing "real_file2" */ assertMakeSymlink("dest2/file2", "real_file2"); -#else - skipping("symlink does not work on this platform"); -#endif assertEqualInt(0, systemf("%s -xPf test.tar -C dest2", testprog)); /* dest2/dir symlink should be followed */ -#if !defined(_WIN32) || defined(__CYGWIN__) - assertEqualInt(0, lstat("dest2/dir", &st)); - failure("tar -xP removed symlink instead of following it"); - if (assert(S_ISLNK(st.st_mode))) { - /* Only verify what the symlink points to if it - * really is a symlink. */ - failure("The symlink should point to a directory"); - assertEqualInt(0, stat("dest2/dir", &st)); - assert(S_ISDIR(st.st_mode)); - failure("The pre-existing directory should still be there"); - assertEqualInt(0, lstat("dest2/real_dir", &st2)); - assert(S_ISDIR(st2.st_mode)); - assertEqualInt(st.st_dev, st2.st_dev); - failure("symlink should still point to the existing directory"); - assertEqualInt(st.st_ino, st2.st_ino); + if (canSymlink()) { + assertIsSymlink("dest2/dir", "real_dir"); + assertIsDir("dest2/real_dir", -1); } -#else - skipping("symlink does not work on this platform"); -#endif + /* Contents of 'dir' should be restored */ assertIsDir("dest2/dir/d", -1); assertIsReg("dest2/dir/f", -1);