Skip to content

Commit

Permalink
Merge pull request ipfs/go-ipfs-files#22 from ipfs/feat/symlink-size
Browse files Browse the repository at this point in the history
feat: correctly report the size of symlinks

This commit was moved from ipfs/go-ipfs-files@a54eafa
  • Loading branch information
Stebalien committed Sep 26, 2019
2 parents 49818ba + 280ebca commit 92aa596
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 22 deletions.
27 changes: 7 additions & 20 deletions files/linkfile.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
package files

import (
"io"
"os"
"strings"
)

type Symlink struct {
Target string
stat os.FileInfo

reader io.Reader
reader strings.Reader
}

func NewLinkFile(target string, stat os.FileInfo) File {
return &Symlink{
Target: target,
stat: stat,
reader: strings.NewReader(target),
}
func NewLinkFile(target string) File {
lf := &Symlink{Target: target}
lf.reader.Reset(lf.Target)
return lf
}

func (lf *Symlink) Close() error {
if c, ok := lf.reader.(io.Closer); ok {
return c.Close()
}

return nil
}

Expand All @@ -34,15 +25,11 @@ func (lf *Symlink) Read(b []byte) (int, error) {
}

func (lf *Symlink) Seek(offset int64, whence int) (int64, error) {
if s, ok := lf.reader.(io.Seeker); ok {
return s.Seek(offset, whence)
}

return 0, ErrNotSupported
return lf.reader.Seek(offset, whence)
}

func (lf *Symlink) Size() (int64, error) {
return 0, ErrNotSupported
return lf.reader.Size(), nil
}

func ToSymlink(n Node) *Symlink {
Expand Down
2 changes: 1 addition & 1 deletion files/multipartfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (w *multipartWalker) nextFile() (Node, error) {
return nil, err
}

return NewLinkFile(string(out), nil), nil
return NewLinkFile(string(out)), nil
default:
return &ReaderFile{
reader: part,
Expand Down
2 changes: 1 addition & 1 deletion files/serialfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewSerialFile(path string, hidden bool, stat os.FileInfo) (Node, error) {
if err != nil {
return nil, err
}
return NewLinkFile(target, stat), nil
return NewLinkFile(target), nil
default:
return nil, fmt.Errorf("unrecognized file type for %s: %s", path, mode.String())
}
Expand Down

0 comments on commit 92aa596

Please sign in to comment.