@@ -59,9 +59,25 @@ func metadataPath(name string) storage.Path {
59
59
return append (BundlesBasePath , name , "manifest" , "metadata" )
60
60
}
61
61
62
+ func read (ctx context.Context , store storage.Store , txn storage.Transaction , path storage.Path ) (interface {}, error ) {
63
+ value , err := store .Read (ctx , txn , path )
64
+ if err != nil {
65
+ return nil , err
66
+ }
67
+
68
+ if astValue , ok := value .(ast.Value ); ok {
69
+ value , err = ast .JSON (astValue )
70
+ if err != nil {
71
+ return nil , err
72
+ }
73
+ }
74
+
75
+ return value , nil
76
+ }
77
+
62
78
// ReadBundleNamesFromStore will return a list of bundle names which have had their metadata stored.
63
79
func ReadBundleNamesFromStore (ctx context.Context , store storage.Store , txn storage.Transaction ) ([]string , error ) {
64
- value , err := store . Read (ctx , txn , BundlesBasePath )
80
+ value , err := read (ctx , store , txn , BundlesBasePath )
65
81
if err != nil {
66
82
return nil , err
67
83
}
@@ -153,7 +169,7 @@ func eraseWasmModulesFromStore(ctx context.Context, store storage.Store, txn sto
153
169
// ReadWasmMetadataFromStore will read Wasm module resolver metadata from the store.
154
170
func ReadWasmMetadataFromStore (ctx context.Context , store storage.Store , txn storage.Transaction , name string ) ([]WasmResolver , error ) {
155
171
path := wasmEntrypointsPath (name )
156
- value , err := store . Read (ctx , txn , path )
172
+ value , err := read (ctx , store , txn , path )
157
173
if err != nil {
158
174
return nil , err
159
175
}
@@ -176,7 +192,7 @@ func ReadWasmMetadataFromStore(ctx context.Context, store storage.Store, txn sto
176
192
// ReadWasmModulesFromStore will write Wasm module resolver metadata from the store.
177
193
func ReadWasmModulesFromStore (ctx context.Context , store storage.Store , txn storage.Transaction , name string ) (map [string ][]byte , error ) {
178
194
path := wasmModulePath (name )
179
- value , err := store . Read (ctx , txn , path )
195
+ value , err := read (ctx , store , txn , path )
180
196
if err != nil {
181
197
return nil , err
182
198
}
@@ -205,7 +221,7 @@ func ReadWasmModulesFromStore(ctx context.Context, store storage.Store, txn stor
205
221
// If the bundle is not activated, this function will return
206
222
// storage NotFound error.
207
223
func ReadBundleRootsFromStore (ctx context.Context , store storage.Store , txn storage.Transaction , name string ) ([]string , error ) {
208
- value , err := store . Read (ctx , txn , rootsPath (name ))
224
+ value , err := read (ctx , store , txn , rootsPath (name ))
209
225
if err != nil {
210
226
return nil , err
211
227
}
@@ -235,7 +251,7 @@ func ReadBundleRevisionFromStore(ctx context.Context, store storage.Store, txn s
235
251
}
236
252
237
253
func readRevisionFromStore (ctx context.Context , store storage.Store , txn storage.Transaction , path storage.Path ) (string , error ) {
238
- value , err := store . Read (ctx , txn , path )
254
+ value , err := read (ctx , store , txn , path )
239
255
if err != nil {
240
256
return "" , err
241
257
}
@@ -256,7 +272,7 @@ func ReadBundleMetadataFromStore(ctx context.Context, store storage.Store, txn s
256
272
}
257
273
258
274
func readMetadataFromStore (ctx context.Context , store storage.Store , txn storage.Transaction , path storage.Path ) (map [string ]interface {}, error ) {
259
- value , err := store . Read (ctx , txn , path )
275
+ value , err := read (ctx , store , txn , path )
260
276
if err != nil {
261
277
return nil , suppressNotFound (err )
262
278
}
@@ -277,7 +293,7 @@ func ReadBundleEtagFromStore(ctx context.Context, store storage.Store, txn stora
277
293
}
278
294
279
295
func readEtagFromStore (ctx context.Context , store storage.Store , txn storage.Transaction , path storage.Path ) (string , error ) {
280
- value , err := store . Read (ctx , txn , path )
296
+ value , err := read (ctx , store , txn , path )
281
297
if err != nil {
282
298
return "" , err
283
299
}
@@ -544,14 +560,7 @@ func activateDeltaBundles(opts *ActivateOpts, bundles map[string]*Bundle) error
544
560
return err
545
561
}
546
562
547
- bs , err := json .Marshal (value )
548
- if err != nil {
549
- return fmt .Errorf ("corrupt manifest data: %w" , err )
550
- }
551
-
552
- var manifest Manifest
553
-
554
- err = util .UnmarshalJSON (bs , & manifest )
563
+ manifest , err := valueToManifest (value )
555
564
if err != nil {
556
565
return fmt .Errorf ("corrupt manifest data: %w" , err )
557
566
}
@@ -585,6 +594,30 @@ func activateDeltaBundles(opts *ActivateOpts, bundles map[string]*Bundle) error
585
594
return nil
586
595
}
587
596
597
+ func valueToManifest (v interface {}) (Manifest , error ) {
598
+ if astV , ok := v .(ast.Value ); ok {
599
+ var err error
600
+ v , err = ast .JSON (astV )
601
+ if err != nil {
602
+ return Manifest {}, err
603
+ }
604
+ }
605
+
606
+ var manifest Manifest
607
+
608
+ bs , err := json .Marshal (v )
609
+ if err != nil {
610
+ return Manifest {}, err
611
+ }
612
+
613
+ err = util .UnmarshalJSON (bs , & manifest )
614
+ if err != nil {
615
+ return Manifest {}, err
616
+ }
617
+
618
+ return manifest , nil
619
+ }
620
+
588
621
// erase bundles by name and roots. This will clear all policies and data at its roots and remove its
589
622
// manifest from storage.
590
623
func eraseBundles (ctx context.Context , store storage.Store , txn storage.Transaction , parserOpts ast.ParserOptions , names map [string ]struct {}, roots map [string ]struct {}) (map [string ]* ast.Module , error ) {
0 commit comments