From e2113964d546c7ece9848cc4d697d6714ca7407d Mon Sep 17 00:00:00 2001 From: zouxu Date: Mon, 1 Jan 2024 16:11:25 +0800 Subject: [PATCH 1/2] bug: client is nil --- sftpfs/sftp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sftpfs/sftp.go b/sftpfs/sftp.go index eadf1e07..c73752e5 100644 --- a/sftpfs/sftp.go +++ b/sftpfs/sftp.go @@ -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 { From a269d78f6d8e98a6227f3711b3c6df0725fe4197 Mon Sep 17 00:00:00 2001 From: zouxu Date: Sun, 30 Jun 2024 08:46:18 +0800 Subject: [PATCH 2/2] os symlink use rel path --- os.go | 7 ++++++- symlink_test.go | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/os.go b/os.go index f1366321..b48724ee 100644 --- a/os.go +++ b/os.go @@ -16,6 +16,7 @@ package afero import ( "os" + "path/filepath" "time" ) @@ -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) { diff --git a/symlink_test.go b/symlink_test.go index 77dd742f..004d8f43 100644 --- a/symlink_test.go +++ b/symlink_test.go @@ -132,7 +132,7 @@ 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) { @@ -140,6 +140,7 @@ func TestReadlinkIfPossible(t *testing.T) { } 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()