[prev in list] [next in list] [prev in thread] [next in thread] 

List:       coreutils
Subject:    Re: [PATCH] split: fix cases where -n l/... creates extraneous files
From:       Pádraig_Brady <P () draigBrady ! com>
Date:       2011-05-25 12:11:42
Message-ID: 4DDCF1FE.7080801 () draigBrady ! com
[Download RAW message or body]

On 24/05/11 20:47, Jim Meyering wrote:
> Nice work.
> The only nit I see is that there's no reason to redirect stdout here,
> since it should be unused:
> 
> diff --git a/tests/misc/split-lchunk b/tests/misc/split-lchunk
> index 762138b..12d76e8 100755
> --- a/tests/misc/split-lchunk
> +++ b/tests/misc/split-lchunk
> @@ -75,7 +75,7 @@ for ELIDE_EMPTY in '' '-e'; do
> 
>        if test -z "$ELIDE_EMPTY"; then
>          split ---io-blksize=$IO_BLKSIZE $ELIDE_EMPTY -n l/2/$N in > chunk.k
> -        stat x* >/dev/null 2>/dev/null && fail=1
> +        stat x* 2>/dev/null && fail=1
>        fi
> 
>        split ---io-blksize=$IO_BLKSIZE $ELIDE_EMPTY -n l/$N in
> 

Good point.
Also if split does the wrong thing,
it will be better to have output for debugging.

I've fixed that along with another issue I
noticed with the previous patch. Attached.

cheers,
Pádraig.

["split-n-extra-file.diff" (text/x-patch)]

>From 73a7cf295f75376755c2f949deee4ff9607418f4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pádraig Brady?= <P@draigBrady.com>
Date: Wed, 25 May 2011 13:05:37 +0100
Subject: [PATCH] split: fix an edge case where -n l/... creates an extra file

* src/split.c (lines_bytes_chunk): Handle the edge case
where the file is truncated as we read.
* tests/misc/split-lchunk: Cleanup, no functional change.
---
 src/split.c             |   11 ++++++-----
 tests/misc/split-lchunk |    4 ++--
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/split.c b/src/split.c
index e09ebce..6c75080 100644
--- a/src/split.c
+++ b/src/split.c
@@ -599,6 +599,7 @@ lines_chunk_split (uintmax_t k, uintmax_t n, char *buf, size_t bufsize,
   off_t chunk_end = chunk_size - 1;
   off_t n_written = 0;
   bool new_file_flag = true;
+  bool chunk_truncated = false;

   if (k > 1)
     {
@@ -620,6 +621,7 @@ lines_chunk_split (uintmax_t k, uintmax_t n, char *buf, size_t bufsize,
         error (EXIT_FAILURE, errno, "%s", infile);
       else if (n_read == 0)
         break; /* eof.  */
+      chunk_truncated = false;
       eob = buf + n_read;

       while (bp != eob)
@@ -659,11 +661,7 @@ lines_chunk_split (uintmax_t k, uintmax_t n, char *buf, size_t bufsize,
               if (!next && bp == eob)
                 {
                   /* replenish buf, before going to next chunk.  */
-
-                  /* If we're going to stop reading,
-                     then count the current chunk.  */
-                  if (n_written >= file_size)
-                    chunk_no++;
+                  chunk_truncated = true;
                   break;
                 }
               chunk_no++;
@@ -684,6 +682,9 @@ lines_chunk_split (uintmax_t k, uintmax_t n, char *buf, size_t bufsize,
         }
     }

+  if (chunk_truncated)
+    chunk_no++;
+
   /* Ensure NUMBER files are created, which truncates
      any existing files or notifies any consumers on fifos.
      FIXME: Should we do this before EXIT_FAILURE?  */
diff --git a/tests/misc/split-lchunk b/tests/misc/split-lchunk
index 762138b..8b4d157 100755
--- a/tests/misc/split-lchunk
+++ b/tests/misc/split-lchunk
@@ -74,8 +74,8 @@ for ELIDE_EMPTY in '' '-e'; do
       rm -f x*

       if test -z "$ELIDE_EMPTY"; then
-        split ---io-blksize=$IO_BLKSIZE $ELIDE_EMPTY -n l/2/$N in > chunk.k
-        stat x* >/dev/null 2>/dev/null && fail=1
+        split ---io-blksize=$IO_BLKSIZE -n l/2/$N in > chunk.k
+        stat x* 2>/dev/null && fail=1
       fi

       split ---io-blksize=$IO_BLKSIZE $ELIDE_EMPTY -n l/$N in
--
1.7.5.1



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic