Blame SOURCES/coreutils-8.32-split-number.patch

4d1984
From bb0e7fabcaed9a7e71e30f05e638e9f243cdb13e Mon Sep 17 00:00:00 2001
4d1984
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P@draigBrady.com>
4d1984
Date: Mon, 25 Jan 2021 14:12:48 +0000
4d1984
Subject: [PATCH] split: fix --number=K/N to output correct part of file
4d1984
4d1984
This functionality regressed with the adjustments
4d1984
in commit v8.25-4-g62e7af032
4d1984
4d1984
* src/split.c (bytes_chunk_extract): Account for already read data
4d1984
when seeking into the file.
4d1984
* tests/split/b-chunk.sh: Use the hidden ---io-blksize option,
4d1984
to test this functionality.
4d1984
Fixes https://bugs.gnu.org/46048
4d1984
4d1984
Upstream-commit: bb21daa125aeb4e32546309d370918ca47e612db
4d1984
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
4d1984
---
4d1984
 src/split.c            |  2 +-
4d1984
 tests/split/b-chunk.sh | 45 ++++++++++++++++++++++++------------------
4d1984
 2 files changed, 27 insertions(+), 20 deletions(-)
4d1984
4d1984
diff --git a/src/split.c b/src/split.c
4d1984
index 09e610b..19248f6 100644
4d1984
--- a/src/split.c
4d1984
+++ b/src/split.c
4d1984
@@ -1001,7 +1001,7 @@ bytes_chunk_extract (uintmax_t k, uintmax_t n, char *buf, size_t bufsize,
4d1984
     }
4d1984
   else
4d1984
     {
4d1984
-      if (lseek (STDIN_FILENO, start, SEEK_CUR) < 0)
4d1984
+      if (lseek (STDIN_FILENO, start - initial_read, SEEK_CUR) < 0)
4d1984
         die (EXIT_FAILURE, errno, "%s", quotef (infile));
4d1984
       initial_read = SIZE_MAX;
4d1984
     }
4d1984
diff --git a/tests/split/b-chunk.sh b/tests/split/b-chunk.sh
4d1984
index 864ce55..39a6799 100755
4d1984
--- a/tests/split/b-chunk.sh
4d1984
+++ b/tests/split/b-chunk.sh
4d1984
@@ -35,32 +35,39 @@ split -e -n 10 /dev/null || fail=1
4d1984
 returns_ 1 stat x?? 2>/dev/null || fail=1
4d1984
 
4d1984
 printf '1\n2\n3\n4\n5\n' > input || framework_failure_
4d1984
+printf '1\n2' > exp-1 || framework_failure_
4d1984
+printf '\n3\n' > exp-2 || framework_failure_
4d1984
+printf '4\n5\n' > exp-3 || framework_failure_
4d1984
 
4d1984
 for file in input /proc/version /sys/kernel/profiling; do
4d1984
   test -f $file || continue
4d1984
 
4d1984
-  split -n 3 $file > out || fail=1
4d1984
-  split -n 1/3 $file > b1 || fail=1
4d1984
-  split -n 2/3 $file > b2 || fail=1
4d1984
-  split -n 3/3 $file > b3 || fail=1
4d1984
+  for blksize in 1 2 4096; do
4d1984
+    if ! test "$file" = 'input'; then
4d1984
+      # For /proc like files we must be able to read all
4d1984
+      # into the internal buffer to be able to determine size.
4d1984
+      test "$blksize" = 4096 || continue
4d1984
+    fi
4d1984
 
4d1984
-  case $file in
4d1984
-    input)
4d1984
-      printf '1\n2' > exp-1
4d1984
-      printf '\n3\n' > exp-2
4d1984
-      printf '4\n5\n' > exp-3
4d1984
+    split -n 3 ---io-blksize=$blksize $file > out || fail=1
4d1984
+    split -n 1/3 ---io-blksize=$blksize $file > b1 || fail=1
4d1984
+    split -n 2/3 ---io-blksize=$blksize $file > b2 || fail=1
4d1984
+    split -n 3/3 ---io-blksize=$blksize $file > b3 || fail=1
4d1984
 
4d1984
-      compare exp-1 xaa || fail=1
4d1984
-      compare exp-2 xab || fail=1
4d1984
-      compare exp-3 xac || fail=1
4d1984
-      ;;
4d1984
-  esac
4d1984
+    case $file in
4d1984
+      input)
4d1984
+        compare exp-1 xaa || fail=1
4d1984
+        compare exp-2 xab || fail=1
4d1984
+        compare exp-3 xac || fail=1
4d1984
+        ;;
4d1984
+    esac
4d1984
 
4d1984
-  compare xaa b1 || fail=1
4d1984
-  compare xab b2 || fail=1
4d1984
-  compare xac b3 || fail=1
4d1984
-  cat xaa xab xac | compare - $file || fail=1
4d1984
-  test -f xad && fail=1
4d1984
+    compare xaa b1 || fail=1
4d1984
+    compare xab b2 || fail=1
4d1984
+    compare xac b3 || fail=1
4d1984
+    cat xaa xab xac | compare - $file || fail=1
4d1984
+    test -f xad && fail=1
4d1984
+  done
4d1984
 done
4d1984
 
4d1984
 Exit $fail
4d1984
-- 
4d1984
2.26.2
4d1984