]> Cypherpunks repositories - gostls13.git/commitdiff
archive/tar: centralize errors in common.go
authorJoe Tsai <joetsai@digital-static.net>
Tue, 15 Aug 2017 03:11:02 +0000 (20:11 -0700)
committerJoe Tsai <thebrokentoaster@gmail.com>
Tue, 15 Aug 2017 05:09:54 +0000 (05:09 +0000)
Move all sentinel errors to common.go since some of them are
returned by both the reader and writer and remove errInvalidHeader
since it not used.

Also, consistently use the "tar: " prefix for errors.

Change-Id: I0afb185bbf3db80dfd9595321603924454a4c2f9
Reviewed-on: https://go-review.googlesource.com/55650
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/archive/tar/common.go
src/archive/tar/reader.go
src/archive/tar/writer.go

index fb214c855d1c956d61e623ff25d49252e5ac1089..6390ca41c6846bcbe6ae5f2d62fe7399c03f9bf6 100644 (file)
@@ -25,6 +25,13 @@ import (
 // architectures. If a large value is encountered when decoding, the result
 // stored in Header will be the truncated version.
 
+var (
+       ErrHeader          = errors.New("tar: invalid tar header")
+       ErrWriteTooLong    = errors.New("tar: write too long")
+       ErrFieldTooLong    = errors.New("tar: header field too long")
+       ErrWriteAfterClose = errors.New("tar: write after close")
+)
+
 // Header type flags.
 const (
        TypeReg           = '0'    // regular file
@@ -331,9 +338,9 @@ func FileInfoHeader(fi os.FileInfo, link string) (*Header, error) {
        case fm&os.ModeNamedPipe != 0:
                h.Typeflag = TypeFifo
        case fm&os.ModeSocket != 0:
-               return nil, fmt.Errorf("archive/tar: sockets not supported")
+               return nil, fmt.Errorf("tar: sockets not supported")
        default:
-               return nil, fmt.Errorf("archive/tar: unknown file mode %v", fm)
+               return nil, fmt.Errorf("tar: unknown file mode %v", fm)
        }
        if fm&os.ModeSetuid != 0 {
                h.Mode |= c_ISUID
index 98f6ea86faab43e6505fdc12ed1a4daff40c27fe..fb7cb8891d0e795db6ca3271c9352215057ff40e 100644 (file)
@@ -9,7 +9,6 @@ package tar
 
 import (
        "bytes"
-       "errors"
        "io"
        "io/ioutil"
        "math"
@@ -18,10 +17,6 @@ import (
        "time"
 )
 
-var (
-       ErrHeader = errors.New("archive/tar: invalid tar header")
-)
-
 // A Reader provides sequential access to the contents of a tar archive.
 // A tar archive consists of a sequence of files.
 // The Next method advances to the next file in the archive (including the first),
index 3d75c398e976cde5fad76a42904767411a7adeb2..65836ec17f5e98f8e5156cf697687657c446af4f 100644 (file)
@@ -9,7 +9,6 @@ package tar
 
 import (
        "bytes"
-       "errors"
        "fmt"
        "io"
        "path"
@@ -18,13 +17,6 @@ import (
        "time"
 )
 
-var (
-       ErrWriteTooLong    = errors.New("archive/tar: write too long")
-       ErrFieldTooLong    = errors.New("archive/tar: header field too long")
-       ErrWriteAfterClose = errors.New("archive/tar: write after close")
-       errInvalidHeader   = errors.New("archive/tar: header field too long or contains invalid values")
-)
-
 // A Writer provides sequential writing of a tar archive in POSIX.1 format.
 // A tar archive consists of a sequence of files.
 // Call WriteHeader to begin a new file, and then call Write to supply that file's data,
@@ -49,7 +41,7 @@ func NewWriter(w io.Writer) *Writer { return &Writer{w: w} }
 // will implicitly flush out the file's padding.
 func (tw *Writer) Flush() error {
        if tw.nb > 0 {
-               tw.err = fmt.Errorf("archive/tar: missed writing %d bytes", tw.nb)
+               tw.err = fmt.Errorf("tar: missed writing %d bytes", tw.nb)
                return tw.err
        }
        if _, tw.err = tw.w.Write(zeroBlock[:tw.pad]); tw.err != nil {