Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(15)

Unified Diff: src/pkg/archive/tar/reader.go

Issue 180047: code review 180047: 1) Change default gofmt default settings for (Closed)
Patch Set: code review 180047: 1) Change default gofmt default settings for Created 15 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pkg/archive/tar/common.go ('k') | src/pkg/archive/tar/reader_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/archive/tar/reader.go
===================================================================
--- a/src/pkg/archive/tar/reader.go
+++ b/src/pkg/archive/tar/reader.go
@@ -8,14 +8,14 @@
// - pax extensions
import (
- "bytes";
- "io";
- "os";
- "strconv";
+ "bytes"
+ "io"
+ "os"
+ "strconv"
)
var (
- HeaderError os.Error = os.ErrorString("invalid tar header");
+ HeaderError os.Error = os.ErrorString("invalid tar header")
)
// A Reader provides sequential access to the contents of a tar archive.
@@ -37,35 +37,35 @@
// io.Copy(data, tr);
// }
type Reader struct {
- r io.Reader;
- err os.Error;
- nb int64; // number of unread bytes for current file entry
- pad int64; // amount of padding (ignored) after current file entry
+ r io.Reader
+ err os.Error
+ nb int64 // number of unread bytes for current file entry
+ pad int64 // amount of padding (ignored) after current file entry
}
// NewReader creates a new Reader reading from r.
-func NewReader(r io.Reader) *Reader { return &Reader{r: r} }
+func NewReader(r io.Reader) *Reader { return &Reader{r: r} }
// Next advances to the next entry in the tar archive.
func (tr *Reader) Next() (*Header, os.Error) {
- var hdr *Header;
+ var hdr *Header
if tr.err == nil {
tr.skipUnread()
}
if tr.err == nil {
hdr = tr.readHeader()
}
- return hdr, tr.err;
+ return hdr, tr.err
}
// Parse bytes as a NUL-terminated C-style string.
// If a NUL byte is not found then the whole slice is returned as a string.
func cString(b []byte) string {
- n := 0;
+ n := 0
for n < len(b) && b[n] != 0 {
n++
}
- return string(b[0:n]);
+ return string(b[0:n])
}
func (tr *Reader) octal(b []byte) int64 {
@@ -77,11 +77,11 @@
for len(b) > 0 && (b[len(b)-1] == ' ' || b[len(b)-1] == '\x00') {
b = b[0 : len(b)-1]
}
- x, err := strconv.Btoui64(cString(b), 8);
+ x, err := strconv.Btoui64(cString(b), 8)
if err != nil {
tr.err = err
}
- return int64(x);
+ return int64(x)
}
type ignoreWriter struct{}
@@ -92,14 +92,14 @@
// Skip any unread bytes in the existing file entry, as well as any alignment padding.
func (tr *Reader) skipUnread() {
- nr := tr.nb + tr.pad; // number of bytes to skip
- tr.nb, tr.pad = 0, 0;
+ nr := tr.nb + tr.pad // number of bytes to skip
+ tr.nb, tr.pad = 0, 0
if sr, ok := tr.r.(io.Seeker); ok {
if _, err := sr.Seek(nr, 1); err == nil {
return
}
}
- _, tr.err = io.Copyn(ignoreWriter{}, tr.r, nr);
+ _, tr.err = io.Copyn(ignoreWriter{}, tr.r, nr)
}
func (tr *Reader) verifyChecksum(header []byte) bool {
@@ -107,13 +107,13 @@
return false
}
- given := tr.octal(header[148:156]);
- unsigned, signed := checksum(header);
- return given == unsigned || given == signed;
+ given := tr.octal(header[148:156])
+ unsigned, signed := checksum(header)
+ return given == unsigned || given == signed
}
func (tr *Reader) readHeader() *Header {
- header := make([]byte, blockSize);
+ header := make([]byte, blockSize)
if _, tr.err = io.ReadFull(tr.r, header); tr.err != nil {
return nil
}
@@ -126,64 +126,64 @@
if bytes.Equal(header, zeroBlock[0:blockSize]) {
tr.err = os.EOF
} else {
- tr.err = HeaderError // zero block and then non-zero block
+ tr.err = HeaderError // zero block and then non-zero block
}
- return nil;
+ return nil
}
if !tr.verifyChecksum(header) {
- tr.err = HeaderError;
- return nil;
+ tr.err = HeaderError
+ return nil
}
// Unpack
- hdr := new(Header);
- s := slicer(header);
+ hdr := new(Header)
+ s := slicer(header)
- hdr.Name = cString(s.next(100));
- hdr.Mode = tr.octal(s.next(8));
- hdr.Uid = tr.octal(s.next(8));
- hdr.Gid = tr.octal(s.next(8));
- hdr.Size = tr.octal(s.next(12));
- hdr.Mtime = tr.octal(s.next(12));
- s.next(8); // chksum
- hdr.Typeflag = s.next(1)[0];
- hdr.Linkname = cString(s.next(100));
+ hdr.Name = cString(s.next(100))
+ hdr.Mode = tr.octal(s.next(8))
+ hdr.Uid = tr.octal(s.next(8))
+ hdr.Gid = tr.octal(s.next(8))
+ hdr.Size = tr.octal(s.next(12))
+ hdr.Mtime = tr.octal(s.next(12))
+ s.next(8) // chksum
+ hdr.Typeflag = s.next(1)[0]
+ hdr.Linkname = cString(s.next(100))
// The remainder of the header depends on the value of magic.
// The original (v7) version of tar had no explicit magic field,
// so its magic bytes, like the rest of the block, are NULs.
- magic := string(s.next(8)); // contains version field as well.
- var format string;
+ magic := string(s.next(8)) // contains version field as well.
+ var format string
switch magic {
- case "ustar\x0000": // POSIX tar (1003.1-1988)
+ case "ustar\x0000": // POSIX tar (1003.1-1988)
if string(header[508:512]) == "tar\x00" {
format = "star"
} else {
format = "posix"
}
- case "ustar \x00": // old GNU tar
+ case "ustar \x00": // old GNU tar
format = "gnu"
}
switch format {
case "posix", "gnu", "star":
- hdr.Uname = cString(s.next(32));
- hdr.Gname = cString(s.next(32));
- devmajor := s.next(8);
- devminor := s.next(8);
+ hdr.Uname = cString(s.next(32))
+ hdr.Gname = cString(s.next(32))
+ devmajor := s.next(8)
+ devminor := s.next(8)
if hdr.Typeflag == TypeChar || hdr.Typeflag == TypeBlock {
- hdr.Devmajor = tr.octal(devmajor);
- hdr.Devminor = tr.octal(devminor);
+ hdr.Devmajor = tr.octal(devmajor)
+ hdr.Devminor = tr.octal(devminor)
}
- var prefix string;
+ var prefix string
switch format {
case "posix", "gnu":
prefix = cString(s.next(155))
case "star":
- prefix = cString(s.next(131));
- hdr.Atime = tr.octal(s.next(12));
- hdr.Ctime = tr.octal(s.next(12));
+ prefix = cString(s.next(131))
+ hdr.Atime = tr.octal(s.next(12))
+ hdr.Ctime = tr.octal(s.next(12))
}
if len(prefix) > 0 {
hdr.Name = prefix + "/" + hdr.Name
@@ -191,16 +191,16 @@
}
if tr.err != nil {
- tr.err = HeaderError;
- return nil;
+ tr.err = HeaderError
+ return nil
}
// Maximum value of hdr.Size is 64 GB (12 octal digits),
// so there's no risk of int64 overflowing.
- tr.nb = int64(hdr.Size);
- tr.pad = -tr.nb & (blockSize - 1); // blockSize is a power of two
+ tr.nb = int64(hdr.Size)
+ tr.pad = -tr.nb & (blockSize - 1) // blockSize is a power of two
- return hdr;
+ return hdr
}
// Read reads from the current entry in the tar archive.
@@ -215,12 +215,12 @@
if int64(len(b)) > tr.nb {
b = b[0:tr.nb]
}
- n, err = tr.r.Read(b);
- tr.nb -= int64(n);
+ n, err = tr.r.Read(b)
+ tr.nb -= int64(n)
if err == os.EOF && tr.nb > 0 {
err = io.ErrUnexpectedEOF
}
- tr.err = err;
- return;
+ tr.err = err
+ return
}
« no previous file with comments | « src/pkg/archive/tar/common.go ('k') | src/pkg/archive/tar/reader_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b