From 280ebca77993e3c8b19afb55b9fa342f8e5388d2 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 25 Sep 2019 22:49:21 -0700 Subject: [PATCH] feat: correctly report the size of symlinks Also, symlinks don't use stat. This commit was moved from ipfs/go-ipfs-files@777d1540bc2fa6c24aba7b7fd910e95e206f1667 --- files/linkfile.go | 27 +++++++-------------------- files/multipartfile.go | 2 +- files/serialfile.go | 2 +- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/files/linkfile.go b/files/linkfile.go index 409309bca..64e87625c 100644 --- a/files/linkfile.go +++ b/files/linkfile.go @@ -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 } @@ -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 { diff --git a/files/multipartfile.go b/files/multipartfile.go index d4593ad6c..0351e192b 100644 --- a/files/multipartfile.go +++ b/files/multipartfile.go @@ -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, diff --git a/files/serialfile.go b/files/serialfile.go index 75a73b57c..8e4bf592c 100644 --- a/files/serialfile.go +++ b/files/serialfile.go @@ -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()) }