git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH jn/fast-import-blob-access] t9300: avoid short reads from dd

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Dec 13, 2010, 06:31 UTC
Message-ID
<20101213063151.GB20812@burratino>
In-Reply-To
<2F4185D2-5846-45CB-BC92-6BC07AE5CEC8@gernhardtsoftware.com>
dd is a thin wrapper around read(2).  As open group Issue 7 explains:
	It shall read the input one block at a time, using the specified
	input block size; it shall then process the block of data
	actually returned, which could be smaller than the requested
	block size.

Any short read --- for example from a pipe whose capacity cannot fill a block --- results in that block being truncated. As a result, the first cat-blob test (9300.114) fails on Mac OS X, where the pipe capacity is around 8 KiB.

Fix the test by using a block size of 1. Each read will block until the next byte of input is available.

It would be even nicer to use head -c which expresses the intention more clearly. Alas, IRIX "head" does not support the -c option.

Reported-by: Brian Gernhardt <brian@gernhardtsoftware.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 t/t9300-fast-import.sh |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 055ddc6..ed28d3c 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -1794,7 +1794,7 @@ test_expect_success PIPE 'R: copy using cat-file' '
 
 	read blob_id type size <&3 &&
 	echo "$blob_id $type $size" >response &&
-	dd of=blob bs=$size count=1 <&3 &&
+	dd of=blob bs=1 count=$size <&3 &&
 	read newline <&3 &&
 
 	cat <<EOF &&
@@ -1845,7 +1845,7 @@ test_expect_success PIPE 'R: print blob mid-commit' '
 		EOF
 
 		read blob_id type size <&3 &&
-		dd of=actual bs=$size count=1 <&3 &&
+		dd of=actual bs=1 count=$size <&3 &&
 		read newline <&3 &&
 
 		echo
@@ -1880,7 +1880,7 @@ test_expect_success PIPE 'R: print staged blob within commit' '
 		echo "cat-blob $to_get" &&
 
 		read blob_id type size <&3 &&
-		dd of=actual bs=$size count=1 <&3 &&
+		dd of=actual bs=1 count=$size <&3 &&
 		read newline <&3 &&
 
 		echo deleteall
-- 
1.7.2.4
Previous: Brian GernhardtNext: Junio C Hamano
Message 4 of 6 in “SIGPIPE in t9300-fast-import”
  1. Brian GernhardtDec 12, 2010
  2. Jonathan NiederDec 12, 2010
  3. Brian GernhardtDec 12, 2010
  4. t9300: avoid short reads from ddJonathan Nieder, Dec 13, 2010
  5. Junio C HamanoDec 13, 2010
  6. t9300: use perl "head -c" clone in place of "dd bs=1 count=16000" klugeJonathan Nieder, Dec 13, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.