From d119cfdeba31cda682e12016bcbf8a7d5acee048 Mon Sep 17 00:00:00 2001 From: blacknon Date: Wed, 14 Aug 2024 21:28:42 +0900 Subject: [PATCH] update. --- go.sum | 2 - .../blacknon/go-sshlib/nfs_forward.go | 19 ++++++++ .../blacknon/go-sshlib/nfs_sftpfs.go | 47 +++++++++++-------- vendor/modules.txt | 2 +- 4 files changed, 48 insertions(+), 22 deletions(-) diff --git a/go.sum b/go.sum index 88d4ef5a..cc10c25c 100644 --- a/go.sum +++ b/go.sum @@ -16,8 +16,6 @@ github.com/blacknon/go-nfs-sshlib v0.0.3 h1:tq83kTZibrr99/GCn0pqkJhmBTDMupL/eMI3 github.com/blacknon/go-nfs-sshlib v0.0.3/go.mod h1:jaCmHgFoj8j08rGrBnhJ4nFO7nUWs4xFrUd2vEPwyx8= github.com/blacknon/go-prompt v0.2.7 h1:dVdTqVplKvpT/k4bB9BlbcBYl/k6amYX5tvjYBmuKkI= github.com/blacknon/go-prompt v0.2.7/go.mod h1:zNBmC/BPAyr+3ey1oRhPxuXJS9zz1lEmJpwaoQroe3w= -github.com/blacknon/go-sshlib v0.1.16 h1:de5KXEYalMzknPWwSbKEr/Z3CxgOfMyiQC5+sfzYwLg= -github.com/blacknon/go-sshlib v0.1.16/go.mod h1:upfnjVHf/Lh7ysT3dU1ziHKtzRQ1J62JyrShZ7FlNSI= github.com/blacknon/go-x11auth v0.1.0 h1:SnljCPWcvglWeGAlKc1RAPMHnOfMpM9+GrTGEUQ1lqQ= github.com/blacknon/go-x11auth v0.1.0/go.mod h1:SKOCa19LluXHyB+OaLYobquzceE0SWxVW7e/qU5xGBM= github.com/blacknon/textcol v0.0.1 h1:x9h7yLPGyr8Pdz12XJ30h7Iz5mJlKd0CzfGYxhrmnk8= diff --git a/vendor/github.com/blacknon/go-sshlib/nfs_forward.go b/vendor/github.com/blacknon/go-sshlib/nfs_forward.go index 54e4fd55..5653817d 100644 --- a/vendor/github.com/blacknon/go-sshlib/nfs_forward.go +++ b/vendor/github.com/blacknon/go-sshlib/nfs_forward.go @@ -5,7 +5,9 @@ package sshlib import ( + "fmt" "net" + "strings" nfs "github.com/blacknon/go-nfs-sshlib" nfshelper "github.com/blacknon/go-nfs-sshlib/helpers" @@ -26,6 +28,14 @@ func (c *Connect) NFSForward(address, port, basepoint string) (err error) { return } + // create abs path + homepoint, err := client.RealPath(".") + if err != nil { + return + } + basepoint = getRemoteAbsPath(homepoint, basepoint) + fmt.Println(basepoint) + sftpfsPlusChange := NewChangeSFTPFS(client, basepoint) handler := nfshelper.NewNullAuthHandler(sftpfsPlusChange) @@ -58,3 +68,12 @@ func (c *Connect) NFSReverseForward(address, port, sharepoint string) (err error return } + +func getRemoteAbsPath(wdpath, path string) (result string) { + result = strings.Replace(path, "~", wdpath, 1) + if !strings.HasPrefix(result, "/") { + result = wdpath + "/" + result + } + + return result +} diff --git a/vendor/github.com/blacknon/go-sshlib/nfs_sftpfs.go b/vendor/github.com/blacknon/go-sshlib/nfs_sftpfs.go index 45ae926a..09760931 100644 --- a/vendor/github.com/blacknon/go-sshlib/nfs_sftpfs.go +++ b/vendor/github.com/blacknon/go-sshlib/nfs_sftpfs.go @@ -5,6 +5,7 @@ package sshlib import ( + "fmt" "os" "path/filepath" "strconv" @@ -47,30 +48,38 @@ type SFTPFS struct { // Create func (fs *SFTPFS) Create(filename string) (billy.File, error) { - _, err := fs.Stat(filename) - if err == nil { - return nil, os.ErrExist - } - - dir := filepath.Dir(filename) - err = fs.MkdirAll(dir, os.ModeDir) - if err != nil { - return nil, err - } - - f, err := fs.Client.Create(filename) - if err != nil { - return nil, err - } - return &sftpFile{File: f}, nil + return fs.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0644) } // OpenFile func (fs *SFTPFS) OpenFile(filename string, flag int, perm os.FileMode) (billy.File, error) { - // TODO: create dirをする - // https://github.com/src-d/go-billy/blob/master/osfs/os.go#L31-L54 + // if flag&os.O_CREATE != 0 { + // if err := fs.createDir(filename); err != nil { + // return nil, err + // } + // } + + // f, err := fs.Client.OpenFile(filename, flag) + // if err != nil { + // return nil, err + // } + + return fs.openFile(filename, flag, perm, fs.createDir) + + // return &sftpFile{File: f}, nil +} + +func (fs *SFTPFS) openFile(fn string, flag int, perm os.FileMode, createDir func(string) error) (billy.File, error) { + if flag&os.O_CREATE != 0 { + if createDir == nil { + return nil, fmt.Errorf("createDir func cannot be nil if file needs to be opened in create mode") + } + if err := createDir(fn); err != nil { + return nil, err + } + } - f, err := fs.Client.OpenFile(filename, flag) + f, err := fs.Client.OpenFile(fn, flag) if err != nil { return nil, err } diff --git a/vendor/modules.txt b/vendor/modules.txt index 3fc60ccb..8c6d8a5a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -25,7 +25,7 @@ github.com/blacknon/crypto11 github.com/blacknon/go-nfs-sshlib github.com/blacknon/go-nfs-sshlib/file github.com/blacknon/go-nfs-sshlib/helpers -# github.com/blacknon/go-sshlib v0.1.16 +# github.com/blacknon/go-sshlib v0.1.16 => ../go-sshlib ## explicit; go 1.22.4 github.com/blacknon/go-sshlib # github.com/blacknon/go-x11auth v0.1.0