hnakamur / go-scp

[Unmaintained] A scp client library written in Go
MIT License
41 stars 23 forks source link

send link file should use os.Lstat #25

Open chyroc opened 2 years ago

chyroc commented 2 years ago
// SendFile copies a single local file to the remote server.
// The time and permission will be set with the value of the source file.
func (s *SCP) SendFile(srcFile, destFile string) error {
    srcFile = filepath.Clean(srcFile)
    destFile = realPath(filepath.Clean(destFile))

    return runSourceSession(s.client, destFile, false, s.SCPCommand, false, true, func(s *sourceSession) error {
        osFileInfo, err := os.Stat(srcFile)
        if err != nil {
            return fmt.Errorf("failed to stat source file: err=%s", err)
        }
...
}

use: osFileInfo, err := os.Stat(srcFile)

should replace by os.Lstat to compatible link file

chyroc commented 2 years ago

when ln -s a b and b not exist, code will return file not found error

chyroc commented 2 years ago

this is my code:

    f, _ := os.Lstat(src)
    if f.Mode()&os.ModeSymlink != 0 {
        link, err := os.Readlink(src)
        if err != nil {
            return err
        }
        // run ln -s <link> desc on remote server
...