tar: Remove timing, log and unused functions
@@ -11,12 +11,9 @@ import (
"compress/gzip"
"fmt"
"io"
- "log"
"os"
- "path"
"path/filepath"
"strings"
- "time"
)
// TODO(bradfitz): this was copied from x/build/cmd/buildlet/buildlet.go
@@ -30,30 +27,20 @@ func Untar(r io.Reader, dir string) error {
}
func untar(r io.Reader, dir string) (err error) {
- t0 := time.Now()
- nFiles := 0
madeDir := map[string]bool{}
- defer func() {
- td := time.Since(t0)
- if err == nil {
- log.Printf("extracted tarball into %s: %d files, %d dirs (%v)", dir, nFiles, len(madeDir), td)
- } else {
- log.Printf("error extracting tarball into %s after %d files, %d dirs, %v: %v", dir, nFiles, len(madeDir), td, err)
- }
- }()
+
zr, err := gzip.NewReader(r)
if err != nil {
return fmt.Errorf("requires gzip-compressed body: %v", err)
}
tr := tar.NewReader(zr)
- loggedChtimesError := false
+
for {
f, err := tr.Next()
if err == io.EOF {
break
}
if err != nil {
- log.Printf("tar reading error: %v", err)
return fmt.Errorf("tar error: %v", err)
}
if !validRelPath(f.Name) {
@@ -91,26 +78,6 @@ func untar(r io.Reader, dir string) (err error) {
if n != f.Size {
return fmt.Errorf("only wrote %d bytes to %s; expected %d", n, abs, f.Size)
}
- modTime := f.ModTime
- if modTime.After(t0) {
- // Clamp modtimes at system time. See
- // golang.org/issue/19062 when clock on
- // buildlet was behind the gitmirror server
- // doing the git-archive.
- modTime = t0
- }
- if !modTime.IsZero() {
- if err := os.Chtimes(abs, modTime, modTime); err != nil && !loggedChtimesError {
- // benign error. Gerrit doesn't even set the
- // modtime in these, and we don't end up relying
- // on it anywhere (the gomote push command relies
- // on digests only), so this is a little pointless
- // for now.
- log.Printf("error changing modtime: %v (further Chtimes errors suppressed)", err)
- loggedChtimesError = true // once is enough
- }
- }
- nFiles++
case mode.IsDir():
if err := os.MkdirAll(abs, 0755); err != nil {
return err
@@ -123,17 +90,6 @@ func untar(r io.Reader, dir string) (err error) {
return nil
}
-func validRelativeDir(dir string) bool {
- if strings.Contains(dir, `\`) || path.IsAbs(dir) {
- return false
- }
- dir = path.Clean(dir)
- if strings.HasPrefix(dir, "../") || strings.HasSuffix(dir, "/..") || dir == ".." {
- return false
- }
- return true
-}
-
func validRelPath(p string) bool {
if p == "" || strings.Contains(p, `\`) || strings.HasPrefix(p, "/") || strings.Contains(p, "../") {
return false
