diff options
| -rw-r--r-- | package.proto | 83 | ||||
| -rw-r--r-- | printDebInfo.go | 45 |
2 files changed, 87 insertions, 41 deletions
diff --git a/package.proto b/package.proto index fdb99d7..ddb0ae5 100644 --- a/package.proto +++ b/package.proto @@ -6,54 +6,55 @@ import "google/protobuf/timestamp.proto"; // Import the well-known type for Time // Note: 'autogenpb' treats all .proto variable names as case insensitive -// DebInfo has the information displayed by "dpkg -I moon-buggy.deb" // The order here is the order they will be written into the // /home/mirrors/debian/sid/main/binary-riscv64/Packages file message DebInfo { - string Package = 1; // `autogenpb:unique` `autogenpb:sort` - string Filename = 2; // `autogenpb:unique` `autogenpb:sort` - string Namespace = 3; // path to the sources (go.wit.com/apps/zookeeper) - string Version = 4; // version: 0.0.3 - string Architecture = 5; // - string Depends = 6; // - string Maintainer = 7; // - string Homepage = 8; // - string Description = 9; // - string Packager = 10; // - string Source = 11; // - string Size = 12; // - string Conflicts = 13; // - string BuildDepends = 14; // - string URL = 15; // - string SHA1 = 16; // probably not used anymore - string MD5SUM = 17; // deprecate - string SHA256 = 18; // - string SHA512 = 19; // + string Package = 1; // `autogenpb:unique` `autogenpb:sort` + string Filename = 2; // `autogenpb:unique` `autogenpb:sort` + string Namespace = 3; // path to the sources (go.wit.com/apps/zookeeper) + string Version = 4; // version: 0.0.3 + string Architecture = 5; // + string Depends = 6; // + string BuildDepends = 7; // + string Conflicts = 8; // + string Maintainer = 9; // + string Packager = 10; // + string URL = 11; // + string Homepage = 12; // deprecate + string Source = 13; // + string DebCtime = 14; // + string BuildDate = 15; // + string GitHash = 16; // + string GitDate = 17; // + string InstalledSize = 18; // + string MD5SUM = 19; // + string SHA256 = 20; // + string Description = 21; // } message Package { - string Package = 1; // `autogenpb:unique` `autogenpb:sort` - string Filename = 2; // `autogenpb:unique` `autogenpb:sort` - string Namespace = 3; // namespace path to the sources (go.wit.com/apps/zookeeper) - string Version = 4; // - string Architecture = 5; // - DebInfo debInfo = 6; // the information given by "dpkg -I pingus.deb" - bool installed = 7; // if installed on your machine, this should be set to true - google.protobuf.Timestamp ctime = 8; // the ctime of the file on the mirrors - google.protobuf.Timestamp buildDate = 9; // when the package was built - google.protobuf.Timestamp gitDate = 10; // the tiem of the last git commit - google.protobuf.Timestamp gitHash = 11; // the git hash it was built from - map<string, string> custom = 12; // for custom strings + string Package = 1; // `autogenpb:unique` `autogenpb:sort` + string Filename = 2; // `autogenpb:unique` `autogenpb:sort` + string Namespace = 3; // namespace path to the sources (go.wit.com/apps/zookeeper) + string Version = 4; // + string Architecture = 5; // + DebInfo debInfo = 6; // the information given by "dpkg -I pingus.deb" + bool installed = 7; // if installed on your machine, this should be set to true + google.protobuf.Timestamp ctime = 8; // the ctime of the file on the mirrors + google.protobuf.Timestamp buildDate = 9; // when the package was built + google.protobuf.Timestamp gitDate = 10; // the tiem of the last git commit + string gitHash = 11; // the git hash it was built from + map<string, string> custom = 12; // for custom strings } -message Packages { // `autogenpb:marshal` `autogenpb:gui` `autogenpb:http` - string uuid = 1; // `autogenpb:uuid:2f26cc03-ea30-4481-a333-ad0acc86e1d3` - string version = 2; // `autogenpb:version:v0.0.3` - repeated Package packages = 3; - string filename = 4; // `autogenpb:save` -- this enables autogenerated pb.Load() and pb.Save() - bool changed = 5; // only writes to disk on Save() if changed == true - string gpgKeyID = 6; // the gpg key used to sign the debian mirror Package files - string baseDir = 7; // where your mirrors repo starts "/home/mirrors/debian" - repeated string Errors = 8; // where your mirrors repo starts "/home/mirrors/debian" +message Packages { // `autogenpb:marshal` `autogenpb:gui` `autogenpb:http` + string uuid = 1; // `autogenpb:uuid:2f26cc03-ea30-4481-a333-ad0acc86e1d3` + string version = 2; // `autogenpb:version:v0.0.4` + repeated Package packages = 3; + string filename = 4; // `autogenpb:save` -- this enables autogenerated pb.Load() and pb.Save() + bool changed = 5; // only writes to disk on Save() if changed == true + string gpgKeyID = 6; // the gpg key used to sign the debian mirror Package files + string baseDir = 7; // where your mirrors repo starts "/home/mirrors/debian" + repeated string Errors = 8; // expirement. probably a dumb one } diff --git a/printDebInfo.go b/printDebInfo.go index e87a3d2..267b03c 100644 --- a/printDebInfo.go +++ b/printDebInfo.go @@ -182,3 +182,48 @@ func main() { ") } */ + +// func printDebInfoStrings(pb proto.Message, fallback bool) (string, error) { +func GetDebInfoFields(pb proto.Message) ([]string, error) { + var debInfo []string + // 1. Get the reflection interface for the top-level message. + msg := pb.ProtoReflect() + descriptor := msg.Descriptor() + + // 2. Find the FieldDescriptor for the nested "debInfo" message. + // Note: Protobuf field names like "deb_info" are often canonicalized + // to "debInfo" in Go code, but reflection should use the name from the .proto file. + // We'll check for both common variations for robustness. + + debInfoFieldDesc := descriptor.Fields().ByName("debInfo") + if debInfoFieldDesc == nil { + debInfoFieldDesc = descriptor.Fields().ByName("deb_info") + } + + if debInfoFieldDesc == nil { + // return controlfile, fmt.Errorf("field 'debInfo' or 'deb_info' not found in message %s", descriptor.FullName()) + return nil, fmt.Errorf("field 'debInfo' or 'deb_info' not found in message %s", descriptor.FullName()) + } + + // 3. Get the actual nested message object from the parent. + debInfoValue := msg.Get(debInfoFieldDesc) + debInfoMsg := debInfoValue.Message() + + // 4. Check if the nested message is valid and has been set. + if !debInfoMsg.IsValid() { + // fmt.Printf("--- Field '%s' in [%s] is not set. --- \n", debInfoFieldDesc.Name(), descriptor.FullName()) + return nil, fmt.Errorf("debInfoMsg.InValid()") + } + + // 5. Now, iterate over the fields of the nested debInfo message. + debInfoDescriptor := debInfoMsg.Descriptor() + fields := debInfoDescriptor.Fields() + + for i := 0; i < fields.Len(); i++ { + fieldDesc := fields.Get(i) + debInfo = append(debInfo, string(fieldDesc.Name())) + // debInfo = append(debInfo, fieldDesc.Name()) + } + + return debInfo, nil +} |
