(ctx context.Context, mp format.MutableParameters, pp *pendingPackInfo)
| 124 | } |
| 125 | |
| 126 | func (sm *SharedManager) preparePackDataContent(ctx context.Context, mp format.MutableParameters, pp *pendingPackInfo) (index.Builder, error) { |
| 127 | packFileIndex := index.Builder{} |
| 128 | haveContent := false |
| 129 | |
| 130 | for _, info := range pp.currentPackItems { |
| 131 | if info.PackBlobID == pp.packBlobID { |
| 132 | haveContent = true |
| 133 | |
| 134 | contentlog.Log3(ctx, sm.log, "add-to-pack", |
| 135 | contentparam.ContentID("cid", info.ContentID), |
| 136 | logparam.UInt32("len", info.PackedLength), |
| 137 | logparam.Bool("del", info.Deleted)) |
| 138 | } else { |
| 139 | contentlog.Log4(ctx, sm.log, "move-to-pack", |
| 140 | contentparam.ContentID("cid", info.ContentID), |
| 141 | blobparam.BlobID("sourcePack", info.PackBlobID), |
| 142 | logparam.UInt32("len", info.PackedLength), |
| 143 | logparam.Bool("del", info.Deleted)) |
| 144 | } |
| 145 | |
| 146 | packFileIndex.Add(info) |
| 147 | } |
| 148 | |
| 149 | if len(packFileIndex) == 0 { |
| 150 | return nil, nil |
| 151 | } |
| 152 | |
| 153 | if !haveContent { |
| 154 | // we wrote pack preamble but no actual content, revert it |
| 155 | pp.currentPackData.Reset() |
| 156 | return packFileIndex, nil |
| 157 | } |
| 158 | |
| 159 | if pp.finalized { |
| 160 | return packFileIndex, nil |
| 161 | } |
| 162 | |
| 163 | pp.finalized = true |
| 164 | |
| 165 | if sm.paddingUnit > 0 { |
| 166 | if missing := sm.paddingUnit - (pp.currentPackData.Length() % sm.paddingUnit); missing > 0 { |
| 167 | if err := writeRandomBytesToBuffer(pp.currentPackData, missing); err != nil { |
| 168 | return nil, errors.Wrap(err, "unable to prepare content postamble") |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | err := sm.appendPackFileIndexRecoveryData(mp, packFileIndex, pp.currentPackData) |
| 174 | |
| 175 | return packFileIndex, err |
| 176 | } |
| 177 | |
| 178 | func getPackedContentIV(output []byte, contentID ID) []byte { |
| 179 | h := contentID.Hash() |
no test coverage detected