( ctx context.Context, conn workspacesdk.AgentConn, path string, name string, storeFile StoreFileFunc, )
| 74 | } |
| 75 | |
| 76 | func storeWorkspaceAttachment( |
| 77 | ctx context.Context, |
| 78 | conn workspacesdk.AgentConn, |
| 79 | path string, |
| 80 | name string, |
| 81 | storeFile StoreFileFunc, |
| 82 | ) (AttachmentMetadata, int, error) { |
| 83 | if conn == nil { |
| 84 | return AttachmentMetadata{}, 0, xerrors.New("workspace connection is not configured") |
| 85 | } |
| 86 | if strings.TrimSpace(path) == "" { |
| 87 | return AttachmentMetadata{}, 0, xerrors.New("path is required") |
| 88 | } |
| 89 | reader, _, err := conn.ReadFile(ctx, path, 0, maxAttachmentSize+1) |
| 90 | if err != nil { |
| 91 | return AttachmentMetadata{}, 0, err |
| 92 | } |
| 93 | defer reader.Close() |
| 94 | |
| 95 | data, err := io.ReadAll(io.LimitReader(reader, maxAttachmentSize+1)) |
| 96 | if err != nil { |
| 97 | return AttachmentMetadata{}, 0, err |
| 98 | } |
| 99 | if strings.TrimSpace(name) == "" { |
| 100 | path = strings.TrimRight(path, "/\\") |
| 101 | if idx := strings.LastIndexAny(path, "/\\"); idx >= 0 { |
| 102 | name = path[idx+1:] |
| 103 | } else { |
| 104 | name = path |
| 105 | } |
| 106 | } |
| 107 | attachment, err := storeAttachmentData(ctx, storeFile, name, path, data) |
| 108 | if err != nil { |
| 109 | return AttachmentMetadata{}, 0, err |
| 110 | } |
| 111 | return attachment, len(data), nil |
| 112 | } |
| 113 | |
| 114 | func storeScreenshotAttachment( |
| 115 | ctx context.Context, |
no test coverage detected