canSymlink(void)
{
/* Remember the test result */
- static int value = 0, tested = 1;
+ static int value = 0, tested = 0;
if (tested)
return (value);
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.
assertIsHardlink("linkfile", "file");
/* Symlink */
- assertIsSymlink("symlink", "file");
+ if (canSymlink())
+ assertIsSymlink("symlink", "file");
/* dir */
assertIsDir("dir", 0775);
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");
+ }
}
--- /dev/null
+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
--- /dev/null
+begin 644 test_gcpio_compat_ref_nosym.crc
+M,#<P-S`R,#`U-D9!1$4P,#`P-#%&1#`P,#`P,T4X,#`P,#`S13@P,#`P,#`P
+M,C1!040Q14)",#`P,#`P,#`P,#`P,#`P,#`P,#`P,#4T,#`P,#`P0D(P,35"
+M,#`S-C`P,#`P,#`T,#`P,#`P,#!D:7(````P-S`W,#(P,#4V1D%$0S`P,#`X
+M,4$T,#`P,#`S13@P,#`P,#-%.#`P,#`P,#`R-$%!1#%%0D(P,#`P,#`P,#`P
+M,#`P,#`P,#`P,#`P-30P,#`P,#!"0C`Q-4(P,#(W,#`P,#`P,#4P,#`P,#`P
+M,&9I;&4``#`W,#<P,C`P-39&041#,#`P,#@Q030P,#`P,#-%.#`P,#`P,T4X
+M,#`P,#`P,#(T04%$,45"0C`P,#`P,#!!,#`P,#`P,#`P,#`P,#`U-#`P,#`P
+M,$)",#$U0C`P,C<P,#`P,#`P.3`P,#`P,44W;&EN:V9I;&4``#$R,S0U-C<X
+M.0H``#`W,#<P,C`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P
+M,#`P,#$P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P
+M,#`P,#`P,#`P,#`P,#`P0C`P,#`P,#`P5%)!24Q%4B$A(0``````````````
+1````````````````````````
+`
+end
--- /dev/null
+begin 644 test_gcpio_compat_ref_nosym.newc
+M,#<P-S`Q,#`U-D9!1$4P,#`P-#%&1#`P,#`P,T4X,#`P,#`S13@P,#`P,#`P
+M,C1!040Q14)",#`P,#`P,#`P,#`P,#`P,#`P,#`P,#4T,#`P,#`P0D(P,35"
+M,#`S-C`P,#`P,#`T,#`P,#`P,#!D:7(````P-S`W,#$P,#4V1D%$0S`P,#`X
+M,4$T,#`P,#`S13@P,#`P,#-%.#`P,#`P,#`R-$%!1#%%0D(P,#`P,#`P,#`P
+M,#`P,#`P,#`P,#`P-30P,#`P,#!"0C`Q-4(P,#(W,#`P,#`P,#4P,#`P,#`P
+M,&9I;&4``#`W,#<P,3`P-39&041#,#`P,#@Q030P,#`P,#-%.#`P,#`P,T4X
+M,#`P,#`P,#(T04%$,45"0C`P,#`P,#!!,#`P,#`P,#`P,#`P,#`U-#`P,#`P
+M,$)",#$U0C`P,C<P,#`P,#`P.3`P,#`P,#`P;&EN:V9I;&4``#$R,S0U-C<X
+M.0H``#`W,#<P,3`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P
+M,#`P,#$P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P,#`P
+M,#`P,#`P,#`P,#`P,#`P0C`P,#`P,#`P5%)!24Q%4B$A(0``````````````
+1````````````````````````
+`
+end
--- /dev/null
+begin 644 test_gcpio_compat_ref_nosym.ustar
+M9&ER+P``````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````#`P,#`W-S4`,#`P,3<U,``P,#`Q-S4P`#`P,#`P,#`P,#`P
+M`#$Q,C4S,C$W,C<S`#`P,3$S-3$`-0``````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````!U<W1A<@`P,'1I;0``
+M````````````````````````````````````=&EM````````````````````
+M```````````````````P,#`P,C<S`#8V,#`P-C8`````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````!F:6QE````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````,#`P,#8T-``P,#`Q-S4P`#`P
+M,#$W-3``,#`P,#`P,#`P,3(`,3$R-3,R,3<R-S,`,#`Q,30R,P`P````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````'5S=&%R`#`P=&EM``````````````````````````````````````!T
+M:6T``````````````````````````````````````#`P,#`R-S,`-C8P,#`T
+M-P``````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````````````````````````````#$R,S0U-C<X.0H`
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````;&EN:V9I;&4`````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M`````````````````````#`P,#`V-#0`,#`P,3<U,``P,#`Q-S4P`#`P,#`P
+M,#`P,#`P`#$Q,C4S,C$W,C<S`#`P,3,Q,S<`,69I;&4`````````````````
+M````````````````````````````````````````````````````````````
+M``````````````````````````````````````````````````!U<W1A<@`P
+M,'1I;0``````````````````````````````````````=&EM````````````
+M```````````````````````````P,#`P,C<S`#8V,#`P-#<`````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+M````````````````````````````````````````````````````````````
+,````````````````
+`
+end
#include "test.h"
__FBSDID("$FreeBSD: src/usr.bin/cpio/test/test_option_L.c,v 1.2 2008/08/24 06:21:00 kientzle Exp $");
+/* This is a little pointless, as Windows doesn't support symlinks
+ * (except for the seriously crippled CreateSymbolicLink API) so these
+ * tests won't run on Windows. */
#if defined(_WIN32) && !defined(__CYGWIN__)
#define CAT "type"
#else
FILE *filelist;
int r;
+ if (!canSymlink()) {
+ skipping("Symlink tests");
+ return;
+ }
+
filelist = fopen("filelist", "w");
/* Create a file and a symlink to the file. */
r = systemf(CAT " filelist | %s -pd copy >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);
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);
#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
canSymlink(void)
{
/* Remember the test result */
- static int value = 0, tested = 1;
+ static int value = 0, tested = 0;
if (tested)
return (value);
{
#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];
canSymlink(void)
{
/* Remember the test result */
- static int value = 0, tested = 1;
+ static int value = 0, tested = 0;
if (tested)
return (value);
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));
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);
DEFINE_TEST(test_symlink_dir)
{
-#if !defined(_WIN32) || defined(__CYGWIN__)
- struct stat st;
- struct stat st2;
-#endif
assertUmask(0);
assertMakeDir("source", 0755);
* 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 */
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);