Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: client is nil #413

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion os.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package afero

import (
"os"
"path/filepath"
"time"
)

Expand Down Expand Up @@ -105,7 +106,11 @@ func (OsFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
}

func (OsFs) SymlinkIfPossible(oldname, newname string) error {
return os.Symlink(oldname, newname)
relpath, err := filepath.Rel(filepath.Dir(newname), oldname)
if err != nil {
return &os.LinkError{Op: "symlink", Old: oldname, New: newname, Err: err}
}
return os.Symlink(relpath, newname)
}

func (OsFs) ReadlinkIfPossible(name string) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion sftpfs/sftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (s Fs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error
return nil, err
}
err = sshfsFile.Chmod(perm)
return &File{fd: sshfsFile}, err
return &File{fd: sshfsFile, client: s.client}, err
}

func (s Fs) Remove(name string) error {
Expand Down
3 changes: 2 additions & 1 deletion symlink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,15 @@ func TestReadlinkIfPossible(t *testing.T) {
}

testRead := func(r LinkReader, name string, output *string) {
_, err := r.ReadlinkIfPossible(name)
str, err := r.ReadlinkIfPossible(name)
if (err != nil) && (output == nil) {
t.Fatalf("Error reading link, expected success, got error: %v", err)
} else if (err == nil) && (output != nil) {
t.Fatalf("Error reading link, succeeded when expecting error: %v", *output)
} else if err != nil && err.Error() != *output && !strings.HasSuffix(err.Error(), *output) {
t.Fatalf("Error reading link, expected error '%v', instead received '%v'", *output, err)
}
t.Logf("str: %v", str)
}

notSupported := ErrNoReadlink.Error()
Expand Down