MCPcopy Create free account
hub / github.com/aptly-dev/aptly / ReadStanza

Method ReadStanza

deb/format.go:264–313  ·  view source on GitHub ↗

ReadStanza reeads one stanza from control file

()

Source from the content-addressed store, hash-verified

262
263// ReadStanza reeads one stanza from control file
264func (c *ControlFileReader) ReadStanza() (Stanza, error) {
265 stanza := make(Stanza, 32)
266 lastField := ""
267 lastFieldMultiline := c.isInstaller
268
269 for c.scanner.Scan() {
270 line := c.scanner.Text()
271
272 // Current stanza ends with empty line
273 if line == "" {
274 if len(stanza) > 0 {
275 return stanza, nil
276 }
277 continue
278 }
279
280 if line[0] == ' ' || line[0] == '\t' || c.isInstaller {
281 if lastFieldMultiline {
282 stanza[lastField] += line + "\n"
283 } else {
284 stanza[lastField] += " " + strings.TrimSpace(line)
285 }
286 } else {
287 parts := strings.SplitN(line, ":", 2)
288 if len(parts) != 2 {
289 return nil, ErrMalformedStanza
290 }
291 lastField = canonicalCase(parts[0])
292 lastFieldMultiline = isMultilineField(lastField, c.isRelease)
293 if lastFieldMultiline {
294 // Trim trailing whitespace from the inline value so that
295 // "Package-List: " does not add empty line
296 inlineVal := strings.TrimRight(parts[1], " \t")
297 stanza[lastField] = inlineVal
298 if inlineVal != "" {
299 stanza[lastField] += "\n"
300 }
301 } else {
302 stanza[lastField] = strings.TrimSpace(parts[1])
303 }
304 }
305 }
306 if err := c.scanner.Err(); err != nil {
307 return nil, err
308 }
309 if len(stanza) > 0 {
310 return stanza, nil
311 }
312 return nil, nil
313}

Callers 15

TestReadStanzaMethod · 0.95
TestReadWriteStanzaMethod · 0.95
TestLongFieldsMethod · 0.95
BenchmarkReadStanzaMethod · 0.95
TestMultiDistPoolMethod · 0.95
TestPublishMethod · 0.95
TestPublishAppStreamMethod · 0.95
VerifyAndParseMethod · 0.95

Calls 3

canonicalCaseFunction · 0.85
isMultilineFieldFunction · 0.85
ScanMethod · 0.65

Tested by 15

TestReadStanzaMethod · 0.76
TestReadWriteStanzaMethod · 0.76
TestLongFieldsMethod · 0.76
BenchmarkReadStanzaMethod · 0.76
TestMultiDistPoolMethod · 0.76
TestPublishMethod · 0.76
TestPublishAppStreamMethod · 0.76
SetUpTestMethod · 0.64