File tree Expand file tree Collapse file tree
.vscode/cspell.dictionaries Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -215,3 +215,4 @@ TUNABLES
215215tunables
216216VMULL
217217vmull
218+ tmpfs
Original file line number Diff line number Diff line change @@ -310,13 +310,22 @@ fn try_mmap_stdin() -> Option<Mmap> {
310310}
311311
312312/// Copy stdin to a temp file, then read it into a buffer.
313+ /// Falls back to reading directly into memory if temp file creation fails.
313314fn read_stdin_to_buf ( ) -> std:: io:: Result < Vec < u8 > > {
314- let mut tmp = tempfile:: tempfile ( ) ?;
315- copy ( & mut stdin ( ) , & mut tmp) ?;
316- tmp. rewind ( ) ?;
317- let mut buf = Vec :: new ( ) ;
318- tmp. read_to_end ( & mut buf) ?;
319- Ok ( buf)
315+ // Try to create a temp file (respects TMPDIR)
316+ if let Ok ( mut tmp) = tempfile:: tempfile ( ) {
317+ // Temp file created - copy stdin to it, then read back
318+ copy ( & mut stdin ( ) , & mut tmp) ?;
319+ tmp. rewind ( ) ?;
320+ let mut buf = Vec :: new ( ) ;
321+ tmp. read_to_end ( & mut buf) ?;
322+ Ok ( buf)
323+ } else {
324+ // Fall back to reading directly into memory (e.g., bad TMPDIR)
325+ let mut buf = Vec :: new ( ) ;
326+ stdin ( ) . read_to_end ( & mut buf) ?;
327+ Ok ( buf)
328+ }
320329}
321330
322331fn try_mmap_path ( path : & Path ) -> Option < Mmap > {
Original file line number Diff line number Diff line change @@ -338,14 +338,12 @@ fn test_failed_write_is_reported() {
338338
339339#[ cfg( target_os = "linux" ) ]
340340#[ test]
341- fn test_stdin_tempfile_error_continues ( ) {
342- // Set TMPDIR to a non-writable location to force temp file creation to fail
341+ fn test_stdin_bad_tmpdir_fallback ( ) {
342+ // When TMPDIR is invalid, tac falls back to reading stdin directly into memory
343343 new_ucmd ! ( )
344- . env ( "TMPDIR" , "/proc " )
344+ . env ( "TMPDIR" , "/nonexistent/dir " )
345345 . arg ( "-" )
346- . arg ( "prime_per_line.txt" )
347346 . pipe_in ( "a\n b\n c\n " )
348- . fails ( )
349- . stderr_contains ( "stdin" )
350- . stdout_is_fixture ( "prime_per_line.expected" ) ;
347+ . succeeds ( )
348+ . stdout_is ( "c\n b\n a\n " ) ;
351349}
Original file line number Diff line number Diff line change @@ -11,3 +11,5 @@ curl -L ${repo}/raw/refs/heads/master/tests/csplit/csplit-io-err.sh > tests/cspl
1111# Avoid incorrect PASS
1212curl -L ${repo} /raw/refs/heads/master/tests/runcon/runcon-compute.sh > tests/runcon/runcon-compute.sh
1313curl -L ${repo} /raw/refs/heads/master/tests/tac/tac-continue.sh > tests/tac/tac-continue.sh
14+ # Add tac-continue.sh to root tests (it requires root to mount tmpfs)
15+ sed -i ' s|tests/split/l-chunk-root.sh.*|tests/split/l-chunk-root.sh\t\t\t\\\n tests/tac/tac-continue.sh\t\t\t\\|' tests/local.mk
You can’t perform that action at this time.
0 commit comments