From c33f9e0545b1c4fd0a22f5c2f09d7e8f0fd2d8bf Mon Sep 17 00:00:00 2001 From: Noel Cower Date: Tue, 21 Apr 2020 20:33:54 -0700 Subject: [PATCH] Satisfy linter and remove unneeded code - changeDir doesn't do anything special. I suspect it once did, but no longer the case. - Remove startupDir since it's not used. - Add a few explicit error result discards. --- mtar.go | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/mtar.go b/mtar.go index 96fe040..80bf60d 100644 --- a/mtar.go +++ b/mtar.go @@ -163,7 +163,6 @@ var ( startupTime = time.Now() hdrFormat = tar.FormatPAX - startupDir string skipSrcGlobs []Matcher skipDestGlobs []Matcher skipUserInfo bool @@ -179,7 +178,7 @@ func (p *Args) Shift() (s string, ok bool) { } func usage() { - io.WriteString(os.Stderr, + _, _ = io.WriteString(os.Stderr, `Usage: mtar [-h|--help] [FILE|OPTION] Writes a tar file to standard output. @@ -279,10 +278,6 @@ func main() { log.SetFlags(0) log.SetPrefix("mtar: ") - var err error - startupDir, err = os.Getwd() - failOnError("getwd", err) - // Using some pretty weird CLI arguments here so incoming weird as hell arg loop ahead if len(os.Args) <= 1 || os.Args[1] == "-h" || os.Args[1] == "--help" { usage() @@ -380,11 +375,11 @@ func main() { if s, ok = argv.Shift(); !ok { log.Fatal("-C: missing directory") } - failOnError("cd", changeDir(s)) + failOnError("cd", os.Chdir(s)) continue case strings.HasPrefix(s, "-C"): // cd - failOnError("cd", changeDir(s[2:])) + failOnError("cd", os.Chdir(s[2:])) // Add files default: @@ -401,7 +396,7 @@ func main() { opts := newFileOpts() if idx := strings.IndexByte(dest, ':'); idx > -1 { - err = opts.parse(dest[idx+1:]) + err := opts.parse(dest[idx+1:]) failOnError("cannot parse options for "+src, err) dest = dest[:idx] } @@ -622,7 +617,7 @@ func concatenateTarStream(w *tar.Writer, r *bufio.Reader) error { func addRecursive(w *tar.Writer, src, prefix string, opts *FileOpts) { src = strings.TrimRight(src, "/") src = filepath.Clean(src) + "/" - filepath.Walk(src, func(p string, info os.FileInfo, err error) error { + _ = filepath.Walk(src, func(p string, info os.FileInfo, err error) error { if info.IsDir() && !strings.HasSuffix(p, "/") { p += "/" } @@ -635,14 +630,6 @@ func addRecursive(w *tar.Writer, src, prefix string, opts *FileOpts) { }) } -func changeDir(dir string) error { - const pathsep = string(filepath.Separator) - if !filepath.IsAbs(dir) { - dir = filepath.Join(startupDir, dir) - } - return os.Chdir(dir) -} - func failOnError(prefix string, err error) { if err != nil { log.Fatalf("%s: %v", prefix, err) -- 2.45.2