MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / ensureFile

Function ensureFile

cmd/wsh/cmd/wshcmd-file-util.go:31–49  ·  view source on GitHub ↗
(fileData wshrpc.FileData)

Source from the content-addressed store, hash-verified

29}
30
31func ensureFile(fileData wshrpc.FileData) (*wshrpc.FileInfo, error) {
32 info, err := wshclient.FileInfoCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: fileTimeout})
33 err = convertNotFoundErr(err)
34 if err == fs.ErrNotExist {
35 err = wshclient.FileCreateCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: fileTimeout})
36 if err != nil {
37 return nil, fmt.Errorf("creating file: %w", err)
38 }
39 info, err = wshclient.FileInfoCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: fileTimeout})
40 if err != nil {
41 return nil, fmt.Errorf("getting file info: %w", err)
42 }
43 return info, err
44 }
45 if err != nil {
46 return nil, fmt.Errorf("getting file info: %w", err)
47 }
48 return info, nil
49}
50
51func streamWriteToFile(fileData wshrpc.FileData, reader io.Reader) error {
52 // First truncate the file with an empty write

Callers 1

fileAppendRunFunction · 0.85

Calls 3

FileInfoCommandFunction · 0.92
FileCreateCommandFunction · 0.92
convertNotFoundErrFunction · 0.85

Tested by

no test coverage detected