| 282 | } |
| 283 | |
| 284 | func 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 | } |