From abbebccef0fdccd455e2090492be09e5273b5184 Mon Sep 17 00:00:00 2001 From: Chris Koch Date: Wed, 7 Feb 2024 23:38:05 +0000 Subject: [PATCH 1/2] Remove unused code Signed-off-by: Chris Koch --- uio/linewriter.go | 57 ------------------------------------------ uio/multiwriter.go | 37 --------------------------- uio/uiotest/uiotest.go | 50 ------------------------------------ 3 files changed, 144 deletions(-) delete mode 100644 uio/linewriter.go delete mode 100644 uio/multiwriter.go delete mode 100644 uio/uiotest/uiotest.go diff --git a/uio/linewriter.go b/uio/linewriter.go deleted file mode 100644 index a78835b..0000000 --- a/uio/linewriter.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2019 the u-root Authors. All rights reserved -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package uio - -import ( - "bytes" - "io" -) - -// LineWriter processes one line of log output at a time. -type LineWriter interface { - // OneLine is always called with exactly one line of output. - OneLine(b []byte) -} - -// FullLineWriter returns an io.Writer that waits for a full line of prints -// before calling w.Write on one line each. -func FullLineWriter(w LineWriter) io.WriteCloser { - return &fullLineWriter{w: w} -} - -type fullLineWriter struct { - w LineWriter - buffer []byte -} - -func (fsw *fullLineWriter) printBuf() { - bufs := bytes.Split(fsw.buffer, []byte{'\n'}) - for _, buf := range bufs { - if len(buf) != 0 { - fsw.w.OneLine(buf) - } - } - fsw.buffer = nil -} - -// Write implements io.Writer and buffers p until at least one full line is -// received. -func (fsw *fullLineWriter) Write(p []byte) (int, error) { - i := bytes.LastIndexByte(p, '\n') - if i == -1 { - fsw.buffer = append(fsw.buffer, p...) - } else { - fsw.buffer = append(fsw.buffer, p[:i]...) - fsw.printBuf() - fsw.buffer = append([]byte{}, p[i:]...) - } - return len(p), nil -} - -// Close implements io.Closer and flushes the buffer. -func (fsw *fullLineWriter) Close() error { - fsw.printBuf() - return nil -} diff --git a/uio/multiwriter.go b/uio/multiwriter.go deleted file mode 100644 index e05bc1b..0000000 --- a/uio/multiwriter.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2019 the u-root Authors. All rights reserved -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package uio - -import ( - "io" -) - -type multiCloser struct { - io.Writer - writers []io.Writer -} - -// Close implements io.Closer and closes any io.Writers that are also -// io.Closers. -func (mc *multiCloser) Close() error { - var allErr error - for _, w := range mc.writers { - if c, ok := w.(io.Closer); ok { - if err := c.Close(); err != nil { - allErr = err - } - } - } - return allErr -} - -// MultiWriteCloser is an io.MultiWriter that has an io.Closer and attempts to -// close those w's that have optional io.Closers. -func MultiWriteCloser(w ...io.Writer) io.WriteCloser { - return &multiCloser{ - Writer: io.MultiWriter(w...), - writers: w, - } -} diff --git a/uio/uiotest/uiotest.go b/uio/uiotest/uiotest.go deleted file mode 100644 index f5ae728..0000000 --- a/uio/uiotest/uiotest.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2020 the u-root Authors. All rights reserved -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package uiotest contains tests for uio functions. -package uiotest - -import ( - "io" - "testing" - "time" - - "github.com/u-root/uio/uio" -) - -// NowLog returns the current time formatted like the standard log package's -// timestamp. -func NowLog() string { - return time.Now().Format("2006/01/02 15:04:05") -} - -// TestLineWriter is an io.Writer that logs full lines of serial to tb. -func TestLineWriter(tb testing.TB, prefix string) io.WriteCloser { - tb.Helper() - if len(prefix) > 0 { - return uio.FullLineWriter(&testLinePrefixWriter{tb: tb, prefix: prefix}) - } - return uio.FullLineWriter(&testLineWriter{tb: tb}) -} - -// testLinePrefixWriter is an io.Writer that logs full lines of serial to tb. -type testLinePrefixWriter struct { - tb testing.TB - prefix string -} - -// OneLine implements a uio.LineWriter. -func (tsw *testLinePrefixWriter) OneLine(p []byte) { - tsw.tb.Logf("%s %s: %s", NowLog(), tsw.prefix, p) -} - -// testLineWriter is an io.Writer that logs full lines of serial to tb. -type testLineWriter struct { - tb testing.TB -} - -// OneLine implements a uio.LineWriter. -func (tsw *testLineWriter) OneLine(p []byte) { - tsw.tb.Logf("%s: %s", NowLog(), p) -} From 2ba503b08e3b3085a9a9af60076b1b0782a3b1f6 Mon Sep 17 00:00:00 2001 From: Chris Koch Date: Thu, 8 Feb 2024 16:53:09 +0000 Subject: [PATCH 2/2] Remove ulog.Logger.Print -- unused in u-root and dhcp. Signed-off-by: Chris Koch --- ulog/log.go | 4 ---- ulog/ulogtest/log.go | 5 ----- 2 files changed, 9 deletions(-) diff --git a/ulog/log.go b/ulog/log.go index 9430d42..9c68805 100644 --- a/ulog/log.go +++ b/ulog/log.go @@ -16,7 +16,6 @@ import "log" // It puts your information somewhere for safekeeping. type Logger interface { Printf(format string, v ...interface{}) - Print(v ...interface{}) } // Log is a Logger that prints to the log package's default logger. @@ -27,8 +26,5 @@ type emptyLogger struct{} // Printf implements Logger.Printf. func (emptyLogger) Printf(format string, v ...interface{}) {} -// Print implements Logger.Print. -func (emptyLogger) Print(v ...interface{}) {} - // Null is a logger that prints nothing. var Null Logger = emptyLogger{} diff --git a/ulog/ulogtest/log.go b/ulog/ulogtest/log.go index 28d46e6..b2be14f 100644 --- a/ulog/ulogtest/log.go +++ b/ulog/ulogtest/log.go @@ -18,8 +18,3 @@ type Logger struct { func (tl Logger) Printf(format string, v ...interface{}) { tl.TB.Logf(format, v...) } - -// Print formats according the default formats for v and prints to a unit test's log. -func (tl Logger) Print(v ...interface{}) { - tl.TB.Log(v...) -}