]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Test -T with varying end-of-line conventions, including --null -T with
authorTim Kientzle <kientzle@gmail.com>
Sun, 23 Aug 2009 04:16:58 +0000 (00:16 -0400)
committerTim Kientzle <kientzle@gmail.com>
Sun, 23 Aug 2009 04:16:58 +0000 (00:16 -0400)
a filename that includes a NL character.  Fix the line parser in
util.c to correctly handle these cases.

SVN-Revision: 1384

tar/test/test_option_T.c
tar/util.c

index 36fe1ef4d9020c60ea7b26fed64435a90d942b9d..c2551e6ee6e0a8cd1ff06a4624326f66236c4023 100644 (file)
@@ -51,21 +51,30 @@ DEFINE_TEST(test_option_T)
        if (!touch("d1/d2/f3")) return;
        if (!touch("d1/d2/f4")) return;
        if (!touch("d1/d2/f5")) return;
+       if (!touch("d1/d2/f6")) return;
+       if (!touch("d1/d2/f\x0a")) return;
 
        /* Populate a file list */
        f = fopen("filelist", "w+");
        if (!assert(f != NULL))
                return;
-       fprintf(f, "d1/f1\n");
-       fprintf(f, "d1/d2/f4\n");
+       /* Use a variety of text line endings. */
+       fprintf(f, "d1/f1\x0d\x0a"); /* CRLF */
+       fprintf(f, "d1/d2/f4\x0a"); /* NL */
+       fprintf(f, "d1/d2/f6"); /* EOF */
        fclose(f);
 
        /* Populate a second file list */
        f = fopen("filelist2", "w+");
        if (!assert(f != NULL))
                return;
-       fprintf(f, "d1/d2/f3\n");
-       fprintf(f, "d1/d2/f5\n");
+       /* Use null-terminated names. */
+       fprintf(f, "d1/d2/f3");
+       fwrite("\0", 1, 1, f);
+       fprintf(f, "d1/d2/f5");
+       fwrite("\0", 1, 1, f);
+       fprintf(f, "d1/d2/f\x0a");
+       fwrite("\0", 1, 1, f);
        fclose(f);
 
        /* Use -c -T to archive up the files. */
@@ -89,9 +98,11 @@ DEFINE_TEST(test_option_T)
        assertFileNotExists("test1/d1/d2/f3");
        assertFileExists("test1/d1/d2/f4");
        assertFileNotExists("test1/d1/d2/f5");
+       assertFileExists("test1/d1/d2/f6");
+       assertFileNotExists("test1/d1/d2/f\x0a");
 
        /* Use -r -T to add more files to the archive. */
-       systemf("%s -r -f test1.tar -T filelist2 > test2.out 2> test2.err",
+       systemf("%s -r -f test1.tar --null -T filelist2 > test2.out 2> test2.err",
            testprog);
        assertEmptyFile("test2.out");
        assertEmptyFile("test2.err");
@@ -108,6 +119,8 @@ DEFINE_TEST(test_option_T)
        assertFileExists("test3/d1/d2/f3");
        assertFileExists("test3/d1/d2/f4");
        assertFileExists("test3/d1/d2/f5");
+       assertFileExists("test3/d1/d2/f6");
+       assertFileExists("test3/d1/d2/f\x0a");
 
        /* Use -x -T to dearchive the files (verify -x -T together) */
        if (!assertEqualInt(0, mkdir("test2", 0755))) return;
@@ -121,6 +134,8 @@ DEFINE_TEST(test_option_T)
        assertFileNotExists("test2/d1/d2/f3");
        assertFileExists("test2/d1/d2/f4");
        assertFileNotExists("test2/d1/d2/f5");
+       assertFileExists("test2/d1/d2/f6");
+       assertFileNotExists("test2/d1/d2/f\x0a");
 
        assertEqualInt(0, mkdir("test4", 0755));
        assertEqualInt(0, mkdir("test4_out", 0755));
@@ -148,6 +163,7 @@ DEFINE_TEST(test_option_T)
        } else {
                skipping("bsdtar does not support -s option on this platform");
        }
+
        /* TODO: Include some use of -C directory-changing within the filelist. */
        /* I'm pretty sure -C within the filelist is broken on extract. */
 }
index 274ff03ccca2e155fd443ded92bfec976a2b91a4..fb60f222fd1c50f78a813057122d5901005f7234 100644 (file)
@@ -286,10 +286,8 @@ process_lines(struct bsdtar *bsdtar, const char *pathname,
        FILE *f;
        char *buff, *buff_end, *line_start, *line_end, *p;
        size_t buff_length, new_buff_length, bytes_read, bytes_wanted;
-       int separator;
        int ret;
 
-       separator = bsdtar->option_null ? '\0' : '\n';
        ret = 0;
 
        if (strcmp(pathname, "-") == 0)
@@ -310,10 +308,20 @@ process_lines(struct bsdtar *bsdtar, const char *pathname,
                buff_end += bytes_read;
                /* Process all complete lines in the buffer. */
                while (line_end < buff_end) {
-                       if (*line_end == separator) {
+                       if (bsdtar->option_null) {
+                               if (*line_end == '\0') {
+                                       if ((*process)(bsdtar, line_start) != 0)
+                                               ret = -1;
+                                       line_start = line_end + 1;
+                                       line_end = line_start;
+                               } else
+                                       line_end++;
+                       } else if (*line_end == '\r' || *line_end == '\n') {
                                *line_end = '\0';
-                               if ((*process)(bsdtar, line_start) != 0)
-                                       ret = -1;
+                               if (line_end - line_start > 1) {
+                                       if ((*process)(bsdtar, line_start) != 0)
+                                               ret = -1;
+                               }
                                line_start = line_end + 1;
                                line_end = line_start;
                        } else