Open ebikt opened 5 years ago
I had a similar issue, but I wonder if a better fix would be to drop an error that can be ignored when a required field is missing. At the end of the day, dpkg will complain quite a bit, it's invalid - and i'm split on what to do. I'm going to think about this one a bit more.
Would something like the code below have been enough to work around your issue parsing invalid debs?
diff --git a/control/decode.go b/control/decode.go
index 649b48a..66cf38d 100644
--- a/control/decode.go
+++ b/control/decode.go
@@ -21,6 +21,7 @@
package control // import "pault.ag/go/debian/control"
import (
+ "errors"
"fmt"
"io"
"reflect"
@@ -103,6 +104,8 @@ func (d *Decoder) Decode(into interface{}) error {
return decode(&d.paragraphReader, reflect.ValueOf(into))
}
+var MissingField = errors.New("debian: control: Required field is missing!")
+
// Top-level decode dispatch {{{
func decode(p *ParagraphReader, into reflect.Value) error {
@@ -185,10 +188,7 @@ func decodeStruct(p Paragraph, into reflect.Value) error {
continue
} else {
if fieldType.Tag.Get("required") == "true" {
- return fmt.Errorf(
- "Required field '%s' is missing!",
- fieldType.Name,
- )
+ return MissingField
}
continue
}
Actually scratch that, this still wouldn't return the control. Nevermind. I'm still going to think about it, but I may accept this or make the required something that you can opt-in to enforce or opt-out of enforcing. Hang tight on this one
Downloaded some packages from internet, and installed them to my machines and needed my software to be able to parse them (possibly with warnings.).