创建文件,如果存在就附加内容
(filepath string, content string)
| 301 | |
| 302 | // 创建文件,如果存在就附加内容 |
| 303 | func (sshRemote *SSHRemote) CreateFileByEcho(filepath string, content string) error { |
| 304 | |
| 305 | filepath = sshRemote.ConvertFilePath(filepath) |
| 306 | |
| 307 | /* // 检查并创建文件夹 |
| 308 | dir := path.Dir(filepath) |
| 309 | err := sshRemote.CheckAndCreateDir(dir) |
| 310 | if err != nil { |
| 311 | return err |
| 312 | } */ |
| 313 | |
| 314 | // 创建文件 |
| 315 | content = strings.ReplaceAll(content, "\"", "\\\"") |
| 316 | command := fmt.Sprintf(`sudo echo "%v" >> %v`, content, filepath) |
| 317 | _, err := sshRemote.ExeSSHCommand(command) |
| 318 | |
| 319 | return err |
| 320 | } |
| 321 | |
| 322 | // 检查并创建文件夹 |
| 323 | func (sshRemote *SSHRemote) CheckAndCreateDir(dir string) error { |
no test coverage detected