Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Commit

Permalink
give ipfs get symlink support
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <[email protected]>
  • Loading branch information
whyrusleeping authored and hsanjuan committed Mar 21, 2018
1 parent beab271 commit 3ff042c
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tar

import (
"archive/tar"
"fmt"
"io"
"os"
gopath "path"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 3ff042c

Please sign in to comment.