MCPcopy Create free account
hub / github.com/blobcache/blobcache / modifyGLFS

Function modifyGLFS

src/blobcachecmd/glfs.go:284–312  ·  view source on GitHub ↗
(ctx context.Context, s blobcache.Service, volh blobcache.Handle, f func(ag *glfs.Machine, dst schema.WO, src schema.RO, root glfs.Ref) (*glfs.Ref, error))

Source from the content-addressed store, hash-verified

282}
283
284func modifyGLFS(ctx context.Context, s blobcache.Service, volh blobcache.Handle, f func(ag *glfs.Machine, dst schema.WO, src schema.RO, root glfs.Ref) (*glfs.Ref, error)) error {
285 tx, err := bcsdk.BeginTx(ctx, s, volh, blobcache.TxParams{
286 Modify: true,
287 })
288 if err != nil {
289 return err
290 }
291 defer tx.Abort(ctx)
292 ag := glfs.NewMachine()
293 // load and parse root
294 var rootData []byte
295 if err := tx.Load(ctx, &rootData); err != nil {
296 return err
297 }
298 root, err := bcglfs.ParseRef(rootData)
299 if err != nil {
300 return err
301 }
302 // modify
303 root2, err := f(ag, tx, tx, *root)
304 if err != nil {
305 return err
306 }
307 // TODO: delete old refs
308 if err := tx.Save(ctx, bcglfs.MarshalRef(root2)); err != nil {
309 return err
310 }
311 return tx.Commit(ctx)
312}

Callers 1

glfs.goFile · 0.85

Calls 7

BeginTxFunction · 0.92
ParseRefFunction · 0.92
MarshalRefFunction · 0.92
AbortMethod · 0.65
LoadMethod · 0.65
SaveMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected