(ctx context.Context, volh blobcache.Handle, txspec blobcache.TxParams)
| 48 | } |
| 49 | |
| 50 | func (sys *System) BeginTx(ctx context.Context, volh blobcache.Handle, txspec blobcache.TxParams) (*blobcache.Handle, error) { |
| 51 | logctx.Info(ctx, "begin", zap.String("method", "BeginTx"), zap.Stringer("oid", volh.OID)) |
| 52 | defer logctx.Info(ctx, "done", zap.String("method", "BeginTx"), zap.Stringer("oid", volh.OID)) |
| 53 | if err := txspec.Validate(); err != nil { |
| 54 | return nil, err |
| 55 | } |
| 56 | vol, rights, err := sys.resolveVol(volh) |
| 57 | if err != nil { |
| 58 | return nil, err |
| 59 | } |
| 60 | if !rights.Has(blobcache.Action_VOLUME_BEGIN_TX) { |
| 61 | return nil, blobcache.ErrPermission{ |
| 62 | Handle: volh, |
| 63 | Rights: rights, |
| 64 | Requires: blobcache.Action_VOLUME_BEGIN_TX, |
| 65 | } |
| 66 | } |
| 67 | if txspec.GCBlobs { |
| 68 | gcBlobRights := blobcache.ActionSet(blobcache.Action_VOLUME_TX_VISIT | blobcache.Action_VOLUME_TX_IS_VISITED) |
| 69 | if rights&gcBlobRights == 0 { |
| 70 | return nil, blobcache.ErrPermission{ |
| 71 | Handle: volh, |
| 72 | Rights: rights, |
| 73 | Requires: gcBlobRights, |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | if txspec.Modify { |
| 78 | mutatingRights := blobcache.ActionSet(blobcache.Action_VOLUME_TX_SAVE | |
| 79 | blobcache.Action_VOLUME_TX_POST | |
| 80 | blobcache.Action_VOLUME_TX_DELETE | |
| 81 | blobcache.Action_VOLUME_TX_COPY_TO | |
| 82 | blobcache.Action_VOLUME_TX_LINK_FROM | |
| 83 | blobcache.Action_VOLUME_TX_UNLINK_FROM | |
| 84 | blobcache.Action_VOLUME_TX_VISIT | |
| 85 | blobcache.Action_VOLUME_TX_VISIT_LINKS) |
| 86 | if rights&mutatingRights == 0 { |
| 87 | return nil, blobcache.ErrPermission{ |
| 88 | Handle: volh, |
| 89 | Rights: rights, |
| 90 | Requires: mutatingRights, |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | tx, err := vol.backend.BeginTx(ctx, txspec) |
| 95 | if err != nil { |
| 96 | return nil, err |
| 97 | } |
| 98 | |
| 99 | txoid := blobcache.RandomOID() |
| 100 | sys.mu.Lock() |
| 101 | if sys.txns == nil { |
| 102 | sys.txns = make(map[blobcache.OID]transaction) |
| 103 | } |
| 104 | sys.txns[txoid] = transaction{ |
| 105 | backend: tx, |
| 106 | volume: &vol, |
| 107 | } |
nothing calls this directly
no test coverage detected