From 3ff042c7d8e246ea6118706a827f7418480a9281 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sun, 30 Aug 2015 22:14:31 -0700 Subject: [PATCH 1/5] give ipfs get symlink support License: MIT Signed-off-by: Jeromy --- extractor.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/extractor.go b/extractor.go index 7a526f5..eeeb741 100644 --- a/extractor.go +++ b/extractor.go @@ -2,6 +2,7 @@ package tar import ( "archive/tar" + "fmt" "io" "os" gopath "path" @@ -39,15 +40,21 @@ func (te *Extractor) Extract(reader io.Reader) error { break } - if header.Typeflag == tar.TypeDir { + switch header.Typeflag { + case tar.TypeDir: if err := te.extractDir(header, i); err != nil { return err } - continue - } - - if err := te.extractFile(header, tarReader, i, rootExists, rootIsDir); err != nil { - return err + case tar.TypeReg: + if err := te.extractFile(header, tarReader, i, rootExists, rootIsDir); err != nil { + return err + } + case tar.TypeSymlink: + if err := te.extractSymlink(header); err != nil { + return err + } + default: + return fmt.Errorf("unrecognized tar header type: %d", header.Typeflag) } } return nil @@ -79,6 +86,10 @@ func (te *Extractor) extractDir(h *tar.Header, depth int) error { return nil } +func (te *Extractor) extractSymlink(h *tar.Header) error { + return os.Symlink(h.Linkname, te.outputPath(h.Name)) +} + func (te *Extractor) extractFile(h *tar.Header, r *tar.Reader, depth int, rootExists bool, rootIsDir bool) error { path := te.outputPath(h.Name) From fa12e38c0e42fadfbadcb7d337a65ba58497cf98 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Mon, 6 Mar 2017 22:58:23 -0800 Subject: [PATCH 2/5] fix progress bar on ipfs get License: MIT Signed-off-by: Jeromy --- extractor.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/extractor.go b/extractor.go index eeeb741..ebbedd5 100644 --- a/extractor.go +++ b/extractor.go @@ -11,7 +11,8 @@ import ( ) type Extractor struct { - Path string + Path string + Progress func(int64) int64 } func (te *Extractor) Extract(reader io.Reader) error { @@ -111,10 +112,30 @@ func (te *Extractor) extractFile(h *tar.Header, r *tar.Reader, depth int, rootEx } defer file.Close() - _, err = io.Copy(file, r) + err = copyWithProgress(file, r, te.Progress) if err != nil { return err } return nil } + +func copyWithProgress(to io.Writer, from io.Reader, cb func(int64) int64) error { + buf := make([]byte, 4096) + for { + n, err := from.Read(buf) + if err != nil { + if err == io.EOF { + return nil + } + return err + } + + cb(int64(n)) + _, err = to.Write(buf[:n]) + if err != nil { + return err + } + } + +} From 66ff8ed6d3e230bba1e681370812680214acba09 Mon Sep 17 00:00:00 2001 From: zramsay Date: Wed, 31 May 2017 16:56:11 -0400 Subject: [PATCH 3/5] apply the megacheck tool to improve code quality License: MIT Signed-off-by: Zach Ramsay --- extractor.go | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/extractor.go b/extractor.go index ebbedd5..b84926b 100644 --- a/extractor.go +++ b/extractor.go @@ -79,12 +79,7 @@ func (te *Extractor) extractDir(h *tar.Header, depth int) error { te.Path = path } - err := os.MkdirAll(path, 0755) - if err != nil { - return err - } - - return nil + return os.MkdirAll(path, 0755) } func (te *Extractor) extractSymlink(h *tar.Header) error { @@ -112,12 +107,7 @@ func (te *Extractor) extractFile(h *tar.Header, r *tar.Reader, depth int, rootEx } defer file.Close() - err = copyWithProgress(file, r, te.Progress) - if err != nil { - return err - } - - return nil + return copyWithProgress(file, r, te.Progress) } func copyWithProgress(to io.Writer, from io.Reader, cb func(int64) int64) error { From 044e908329fdb8d961ba21879aa41b27f0d6b80d Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 7 Mar 2018 23:26:54 +0100 Subject: [PATCH 4/5] tar: fix Go 1.10 breakage License: MIT Signed-off-by: Jakub Sztandera --- extractor.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/extractor.go b/extractor.go index b84926b..fddf808 100644 --- a/extractor.go +++ b/extractor.go @@ -114,18 +114,19 @@ func copyWithProgress(to io.Writer, from io.Reader, cb func(int64) int64) error buf := make([]byte, 4096) for { n, err := from.Read(buf) + if n != 0 { + cb(int64(n)) + _, err2 := to.Write(buf[:n]) + if err2 != nil { + return err2 + } + } if err != nil { if err == io.EOF { return nil } return err } - - cb(int64(n)) - _, err = to.Write(buf[:n]) - if err != nil { - return err - } } } From fbae495a51d5e7c3c26a6b7a89e1f40d70a0a7dd Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Wed, 21 Mar 2018 17:47:23 +0100 Subject: [PATCH 5/5] gx publish 0.0.1 --- .gx/lastpubver | 1 + package.json | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 .gx/lastpubver create mode 100644 package.json diff --git a/.gx/lastpubver b/.gx/lastpubver new file mode 100644 index 0000000..429b04f --- /dev/null +++ b/.gx/lastpubver @@ -0,0 +1 @@ +0.0.1: QmWeQHAnxPZkRDUez5ANmexbHWhzfNMKN8NXimvAUZeAbZ diff --git a/package.json b/package.json new file mode 100644 index 0000000..ff52845 --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "author": "whyrusleeping", + "bugs": { + "url": "https://github.com/whyrusleeping/tar-utils" + }, + "gx": { + "dvcsimport": "github.com/whyrusleeping/tar-utils" + }, + "gxVersion": "0.12.1", + "language": "go", + "license": "MIT", + "name": "tar-utils", + "releaseCmd": "git commit -a -m \"gx publish $VERSION\"", + "version": "0.0.1" +} +