MCPcopy Create free account
hub / github.com/Z3ratu1/geacon_plus / CopyFile

Function CopyFile

command/fileSystem.go:307–349  ·  view source on GitHub ↗
(b []byte)

Source from the content-addressed store, hash-verified

305}
306
307func CopyFile(b []byte) error {
308 srcB, dstB, err := parseCommandCopy(b)
309 src := string(srcB)
310 dst := string(dstB)
311 src = strings.ReplaceAll(src, "\\", "/")
312 dst = strings.ReplaceAll(dst, "\\", "/")
313 srcFile, err := os.Open(src)
314 defer func(srcFile *os.File) {
315 err := srcFile.Close()
316 if err != nil {
317
318 }
319 }(srcFile)
320 if err != nil {
321 return err
322 }
323 dstFile, err := os.OpenFile(dst, os.O_RDWR|os.O_CREATE, os.ModePerm)
324 defer func(dstFile *os.File) {
325 err := dstFile.Close()
326 if err != nil {
327
328 }
329 }(dstFile)
330 if err != nil {
331 return err
332 }
333 buf := make([]byte, 4096)
334 for {
335 n, err := srcFile.Read(buf)
336 if err != nil && err != io.EOF {
337 return err
338 }
339 if n == 0 {
340 break
341 }
342
343 if _, err := dstFile.Write(buf[:n]); err != nil {
344 return err
345 }
346 }
347 packet.PushResult(packet.CALLBACK_OUTPUT, []byte("copy success"))
348 return nil
349}
350
351func MakeDir(dir string) error {
352 dir = strings.ReplaceAll(dir, "\\", "/")

Callers 1

mainFunction · 0.92

Calls 2

PushResultFunction · 0.92
parseCommandCopyFunction · 0.85

Tested by

no test coverage detected