Skip to content
This repository was archived by the owner on Mar 30, 2022. It is now read-only.

send link file should use os.Lstat #25

Open
chyroc opened this issue Oct 8, 2021 · 2 comments
Open

send link file should use os.Lstat #25

chyroc opened this issue Oct 8, 2021 · 2 comments

Comments

@chyroc
Copy link

chyroc commented Oct 8, 2021

// 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
Copy link
Author

chyroc commented Oct 8, 2021

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

@chyroc
Copy link
Author

chyroc commented Oct 8, 2021

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
...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant