MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / CreateFileByEcho

Method CreateFileByEcho

cli/pkg/common/sshremote.go:303–320  ·  view source on GitHub ↗

创建文件,如果存在就附加内容

(filepath string, content string)

Source from the content-addressed store, hash-verified

301
302// 创建文件,如果存在就附加内容
303func (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// 检查并创建文件夹
323func (sshRemote *SSHRemote) CheckAndCreateDir(dir string) error {

Callers 1

Calls 2

ConvertFilePathMethod · 0.95
ExeSSHCommandMethod · 0.95

Tested by

no test coverage detected