MCPcopy
hub / github.com/wavetermdev/waveterm / remoteCopyFileInternal

Function remoteCopyFileInternal

pkg/wshrpc/wshremote/wshremote_file.go:75–108  ·  view source on GitHub ↗

remoteCopyFileInternal copies FROM local (this host) TO local (this host) Only supports copying files, not directories

(srcUri, destUri string, srcPathCleaned, destPathCleaned string, destHasSlash bool, overwrite bool)

Source from the content-addressed store, hash-verified

73// remoteCopyFileInternal copies FROM local (this host) TO local (this host)
74// Only supports copying files, not directories
75func remoteCopyFileInternal(srcUri, destUri string, srcPathCleaned, destPathCleaned string, destHasSlash bool, overwrite bool) error {
76 srcFileStat, err := os.Stat(srcPathCleaned)
77 if err != nil {
78 return fmt.Errorf("cannot stat file %q: %w", srcPathCleaned, err)
79 }
80 if srcFileStat.IsDir() {
81 return fmt.Errorf("copying directories is not supported")
82 }
83 if srcFileStat.Size() > RemoteFileTransferSizeLimit {
84 return fmt.Errorf("file %q size %d exceeds transfer limit of %d bytes", srcPathCleaned, srcFileStat.Size(), RemoteFileTransferSizeLimit)
85 }
86
87 destFilePath, err := prepareDestForCopy(destPathCleaned, filepath.Base(srcPathCleaned), destHasSlash, overwrite)
88 if err != nil {
89 return err
90 }
91
92 srcFile, err := os.Open(srcPathCleaned)
93 if err != nil {
94 return fmt.Errorf("cannot open file %q: %w", srcPathCleaned, err)
95 }
96 defer srcFile.Close()
97
98 destFile, err := os.OpenFile(destFilePath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, srcFileStat.Mode())
99 if err != nil {
100 return fmt.Errorf("cannot create file %q: %w", destFilePath, err)
101 }
102 defer destFile.Close()
103
104 if _, err = io.Copy(destFile, srcFile); err != nil {
105 return fmt.Errorf("cannot copy %q to %q: %w", srcUri, destUri, err)
106 }
107 return nil
108}
109
110// RemoteFileCopyCommand copies a file FROM somewhere TO here
111func (impl *ServerImpl) RemoteFileCopyCommand(ctx context.Context, data wshrpc.CommandFileCopyData) (bool, error) {

Callers 1

RemoteFileCopyCommandMethod · 0.85

Calls 8

prepareDestForCopyFunction · 0.85
StatMethod · 0.80
OpenMethod · 0.80
ModeMethod · 0.80
CopyMethod · 0.80
CloseMethod · 0.65
IsDirMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected