MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / CpFileWithCheck

Method CpFileWithCheck

core/utils/ssh/ssh.go:87–114  ·  view source on GitHub ↗
(src, dst string)

Source from the content-addressed store, hash-verified

85}
86
87func (c *SSHClient) CpFileWithCheck(src, dst string) error {
88 localMd5, err := c.Runf("md5sum %s | awk '{print $1}'", src)
89 if err != nil {
90 global.LOG.Debugf("load md5sum with src for %s failed, std: %s, err: %v", path.Base(src), localMd5, err)
91 localMd5 = ""
92 }
93 for i := 0; i < 3; i++ {
94 std, cpErr := c.Runf("cp %s %s", src, dst)
95 if err != nil {
96 err = fmt.Errorf("cp file %s failed, std: %s, err: %v", src, std, cpErr)
97 continue
98 }
99 if len(strings.TrimSpace(localMd5)) == 0 {
100 return nil
101 }
102 remoteMd5, errDst := c.Runf("md5sum %s | awk '{print $1}'", dst)
103 if errDst != nil {
104 global.LOG.Debugf("load md5sum with dst for %s failed, std: %s, err: %v", path.Base(src), remoteMd5, errDst)
105 return nil
106 }
107 if strings.TrimSpace(localMd5) == strings.TrimSpace(remoteMd5) {
108 return nil
109 }
110 err = errors.New("cp file failed, file is not match!")
111 }
112
113 return err
114}
115
116func (c *SSHClient) SudoHandleCmd() string {
117 if _, err := c.Run("sudo -n ls"); err == nil {

Callers

nothing calls this directly

Calls 1

RunfMethod · 0.95

Tested by

no test coverage detected