MCPcopy Create free account
hub / github.com/dagger/dagger / EncodePersistedObject

Method EncodePersistedObject

core/file.go:211–261  ·  view source on GitHub ↗
(ctx context.Context, cache dagql.PersistedObjectCache)

Source from the content-addressed store, hash-verified

209}
210
211func (file *File) EncodePersistedObject(ctx context.Context, cache dagql.PersistedObjectCache) (dagql.PersistedObjectEncoding, error) {
212 if file == nil {
213 return dagql.PersistedObjectEncoding{}, fmt.Errorf("encode persisted file: nil file")
214 }
215 filePath := ""
216 if file.File != nil {
217 if peekedPath, ok := file.File.Peek(); ok {
218 filePath = peekedPath
219 }
220 }
221 services, err := encodePersistedServiceBindings(cache, "file", file.Services)
222 if err != nil {
223 return dagql.PersistedObjectEncoding{}, err
224 }
225 payload := persistedFilePayload{
226 File: filePath,
227 Platform: file.Platform,
228 Services: services,
229 }
230 if file.Snapshot != nil {
231 if snapshot, ok := file.Snapshot.Peek(); ok && snapshot != nil {
232 payload.Form = persistedFileFormSnapshot
233 payloadJSON, err := json.Marshal(payload)
234 if err != nil {
235 return dagql.PersistedObjectEncoding{}, fmt.Errorf("marshal persisted file payload: %w", err)
236 }
237 return dagql.PersistedObjectEncoding{
238 JSON: payloadJSON,
239 SnapshotLinks: []dagql.PersistedSnapshotRefLink{{
240 RefKey: snapshot.SnapshotID(),
241 Role: "snapshot",
242 }},
243 }, nil
244 }
245 }
246 if file.Lazy != nil {
247 payload.Form = persistedFileFormLazy
248 lazyKind, lazyJSON, err := encodePersistedFileLazy(ctx, cache, file.Lazy)
249 if err != nil {
250 return dagql.PersistedObjectEncoding{}, err
251 }
252 payload.LazyKind = lazyKind
253 payload.LazyJSON = lazyJSON
254 payloadJSON, err := json.Marshal(payload)
255 if err != nil {
256 return dagql.PersistedObjectEncoding{}, fmt.Errorf("marshal persisted file payload: %w", err)
257 }
258 return encodePersistedObjectRawJSON(payloadJSON), nil
259 }
260 return dagql.PersistedObjectEncoding{}, fmt.Errorf("%w: encode persisted file: missing snapshot and lazy op", dagql.ErrPersistStateNotReady)
261}
262
263//nolint:dupl // symmetric with decodePersistedDirectoryWithSnapshotRole in directory.go; sharing hides type specifics
264func decodePersistedFileWithSnapshotRole(ctx context.Context, dag *dagql.Server, resultID uint64, payload json.RawMessage, snapshotRole string) (*File, error) {

Callers

nothing calls this directly

Calls 6

encodePersistedFileLazyFunction · 0.85
PeekMethod · 0.80
MarshalMethod · 0.65
SnapshotIDMethod · 0.65

Tested by

no test coverage detected