common patchsets
This commit is contained in:
parent
2e4f89d813
commit
ced3d76c11
|
@ -0,0 +1,56 @@
|
|||
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
|
||||
// This file was autogenerated with autogenpb v0.0.75 2025-08-18_04:51:43_UTC
|
||||
// go install go.wit.com/apps/autogenpb@latest
|
||||
//
|
||||
// define which structs (messages) you want to use in the .proto file
|
||||
// Then sort.pb.go and marshal.pb.go files are autogenerated
|
||||
//
|
||||
// autogenpb uses it and has an example .proto file with instructions
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"google.golang.org/protobuf/encoding/prototext"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// human readable JSON
|
||||
func (v *Blocks) FormatJSON() string {
|
||||
return protojson.Format(v)
|
||||
}
|
||||
|
||||
// marshal json
|
||||
func (v *Blocks) MarshalJSON() ([]byte, error) {
|
||||
return protojson.Marshal(v)
|
||||
}
|
||||
|
||||
// unmarshal json
|
||||
func (v *Blocks) UnmarshalJSON(data []byte) error {
|
||||
return protojson.Unmarshal(data, v)
|
||||
}
|
||||
|
||||
// apparently this isn't stable, but it's awesomely better
|
||||
// https://protobuf.dev/reference/go/faq/#unstable-text
|
||||
// it's brilliant for config files!
|
||||
func (v *Blocks) FormatTEXT() string {
|
||||
v.fixUuid()
|
||||
return prototext.Format(v)
|
||||
}
|
||||
|
||||
// unmarshalTEXT. This reads the .text config file back in after the user edits it
|
||||
func (v *Blocks) UnmarshalTEXT(data []byte) error {
|
||||
return prototext.Unmarshal(data, v)
|
||||
}
|
||||
|
||||
// marshal to wire. This is called winning.
|
||||
func (v *Blocks) Marshal() ([]byte, error) {
|
||||
v.fixUuid()
|
||||
return proto.Marshal(v)
|
||||
}
|
||||
|
||||
// unmarshal from wire. You have won.
|
||||
func (v *Blocks) Unmarshal(data []byte) error {
|
||||
return proto.Unmarshal(data, v)
|
||||
}
|
|
@ -0,0 +1,304 @@
|
|||
// Code modified by go.wit.com/apps/autogenpb DO NOT EDIT.
|
||||
//
|
||||
// user defined Mutex locks were auto added
|
||||
//
|
||||
// autogenpb version & build time: v0.0.75 2025-08-18_04:51:43_UTC
|
||||
// autogenpb auto generates Sort(), Unique() and Marshal() functions
|
||||
// go install go.wit.com/apps/autogenpb@latest
|
||||
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.33.0
|
||||
// protoc v3.21.12
|
||||
// source: block.proto
|
||||
|
||||
package main // autogenpb changed the package name
|
||||
|
||||
import (
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
type Block struct {
|
||||
sync.RWMutex // auto-added by go.wit.com/apps/autogenpb
|
||||
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` // `autogenpb:sort` `autogenpb:unique`
|
||||
Major uint32 `protobuf:"varint,2,opt,name=major,proto3" json:"major,omitempty"`
|
||||
Minor uint32 `protobuf:"varint,3,opt,name=minor,proto3" json:"minor,omitempty"`
|
||||
SizeBytes uint64 `protobuf:"varint,4,opt,name=size_bytes,json=sizeBytes,proto3" json:"size_bytes,omitempty"`
|
||||
Removable bool `protobuf:"varint,5,opt,name=removable,proto3" json:"removable,omitempty"`
|
||||
ReadOnly bool `protobuf:"varint,6,opt,name=read_only,json=readOnly,proto3" json:"read_only,omitempty"`
|
||||
Type string `protobuf:"bytes,7,opt,name=type,proto3" json:"type,omitempty"` // e.g., "disk", "part", "rom", "loop"
|
||||
Mountpoints []string `protobuf:"bytes,8,rep,name=mountpoints,proto3" json:"mountpoints,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Block) Reset() {
|
||||
*x = Block{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_block_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Block) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Block) ProtoMessage() {}
|
||||
|
||||
func (x *Block) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_block_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Block.ProtoReflect.Descriptor instead.
|
||||
func (*Block) Descriptor() ([]byte, []int) {
|
||||
return file_block_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *Block) GetName() string {
|
||||
if x != nil {
|
||||
return x.Name
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Block) GetMajor() uint32 {
|
||||
if x != nil {
|
||||
return x.Major
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Block) GetMinor() uint32 {
|
||||
if x != nil {
|
||||
return x.Minor
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Block) GetSizeBytes() uint64 {
|
||||
if x != nil {
|
||||
return x.SizeBytes
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *Block) GetRemovable() bool {
|
||||
if x != nil {
|
||||
return x.Removable
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *Block) GetReadOnly() bool {
|
||||
if x != nil {
|
||||
return x.ReadOnly
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *Block) GetType() string {
|
||||
if x != nil {
|
||||
return x.Type
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Block) GetMountpoints() []string {
|
||||
if x != nil {
|
||||
return x.Mountpoints
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Blocks struct {
|
||||
sync.RWMutex // auto-added by go.wit.com/apps/autogenpb
|
||||
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"` // `autogenpb:uuid:abe10848-cf2b-4440-b5a8-0aaa2ce50aad`
|
||||
Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` // `autogenpb:version:v0.0.1`
|
||||
Blocks []*Block `protobuf:"bytes,3,rep,name=Blocks,proto3" json:"Blocks,omitempty"` // THIS MUST BE Block and then Blocks
|
||||
}
|
||||
|
||||
func (x *Blocks) Reset() {
|
||||
*x = Blocks{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_block_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *Blocks) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*Blocks) ProtoMessage() {}
|
||||
|
||||
func (x *Blocks) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_block_proto_msgTypes[1]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use Blocks.ProtoReflect.Descriptor instead.
|
||||
func (*Blocks) Descriptor() ([]byte, []int) {
|
||||
return file_block_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
func (x *Blocks) GetUuid() string {
|
||||
if x != nil {
|
||||
return x.Uuid
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Blocks) GetVersion() string {
|
||||
if x != nil {
|
||||
return x.Version
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Blocks) GetBlocks() []*Block {
|
||||
if x != nil {
|
||||
return x.Blocks
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_block_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_block_proto_rawDesc = []byte{
|
||||
0x0a, 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x6d,
|
||||
0x61, 0x69, 0x6e, 0x22, 0xd7, 0x01, 0x0a, 0x05, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x12, 0x0a,
|
||||
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d,
|
||||
0x65, 0x12, 0x14, 0x0a, 0x05, 0x6d, 0x61, 0x6a, 0x6f, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d,
|
||||
0x52, 0x05, 0x6d, 0x61, 0x6a, 0x6f, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x6d, 0x69, 0x6e, 0x6f, 0x72,
|
||||
0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x6d, 0x69, 0x6e, 0x6f, 0x72, 0x12, 0x1d, 0x0a,
|
||||
0x0a, 0x73, 0x69, 0x7a, 0x65, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28,
|
||||
0x04, 0x52, 0x09, 0x73, 0x69, 0x7a, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x1c, 0x0a, 0x09,
|
||||
0x72, 0x65, 0x6d, 0x6f, 0x76, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52,
|
||||
0x09, 0x72, 0x65, 0x6d, 0x6f, 0x76, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x65,
|
||||
0x61, 0x64, 0x5f, 0x6f, 0x6e, 0x6c, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x72,
|
||||
0x65, 0x61, 0x64, 0x4f, 0x6e, 0x6c, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18,
|
||||
0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x6d,
|
||||
0x6f, 0x75, 0x6e, 0x74, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x18, 0x08, 0x20, 0x03, 0x28, 0x09,
|
||||
0x52, 0x0b, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x73, 0x22, 0x5b, 0x0a,
|
||||
0x06, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75, 0x69, 0x64, 0x18,
|
||||
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x75, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x76,
|
||||
0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65,
|
||||
0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x23, 0x0a, 0x06, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x18,
|
||||
0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x42, 0x6c, 0x6f,
|
||||
0x63, 0x6b, 0x52, 0x06, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_block_proto_rawDescOnce sync.Once
|
||||
file_block_proto_rawDescData = file_block_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_block_proto_rawDescGZIP() []byte {
|
||||
file_block_proto_rawDescOnce.Do(func() {
|
||||
file_block_proto_rawDescData = protoimpl.X.CompressGZIP(file_block_proto_rawDescData)
|
||||
})
|
||||
return file_block_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_block_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
|
||||
var file_block_proto_goTypes = []interface{}{
|
||||
(*Block)(nil), // 0: main.Block
|
||||
(*Blocks)(nil), // 1: main.Blocks
|
||||
}
|
||||
var file_block_proto_depIdxs = []int32{
|
||||
0, // 0: main.Blocks.Blocks:type_name -> main.Block
|
||||
1, // [1:1] is the sub-list for method output_type
|
||||
1, // [1:1] is the sub-list for method input_type
|
||||
1, // [1:1] is the sub-list for extension type_name
|
||||
1, // [1:1] is the sub-list for extension extendee
|
||||
0, // [0:1] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_block_proto_init() }
|
||||
func file_block_proto_init() {
|
||||
if File_block_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_block_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Block); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_block_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*Blocks); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_block_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 2,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
GoTypes: file_block_proto_goTypes,
|
||||
DependencyIndexes: file_block_proto_depIdxs,
|
||||
MessageInfos: file_block_proto_msgTypes,
|
||||
}.Build()
|
||||
File_block_proto = out.File
|
||||
file_block_proto_rawDesc = nil
|
||||
file_block_proto_goTypes = nil
|
||||
file_block_proto_depIdxs = nil
|
||||
}
|
|
@ -0,0 +1,281 @@
|
|||
// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
|
||||
// This file was autogenerated with autogenpb v0.0.75 2025-08-18_04:51:43_UTC
|
||||
// go install go.wit.com/apps/autogenpb@latest
|
||||
//
|
||||
// define which structs (messages) you want to use in the .proto file
|
||||
// Then sort.pb.go and marshal.pb.go files are autogenerated
|
||||
//
|
||||
// autogenpb uses it and has an example .proto file with instructions
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"iter"
|
||||
"sort"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// a simple global lock
|
||||
var blockMu sync.RWMutex
|
||||
|
||||
func (x *Blocks) fixUuid() {
|
||||
if x == nil {
|
||||
return
|
||||
}
|
||||
if x.Uuid == "abe10848-cf2b-4440-b5a8-0aaa2ce50aad" {
|
||||
return
|
||||
}
|
||||
x.Uuid = "abe10848-cf2b-4440-b5a8-0aaa2ce50aad"
|
||||
x.Version = "v0.0.1 go.wit.com/apps/utils/fixup"
|
||||
}
|
||||
|
||||
func NewBlocks() *Blocks {
|
||||
x := new(Blocks)
|
||||
x.Uuid = "abe10848-cf2b-4440-b5a8-0aaa2ce50aad"
|
||||
x.Version = "v0.0.1 go.wit.com/apps/utils/fixup"
|
||||
return x
|
||||
}
|
||||
|
||||
// START SORT
|
||||
|
||||
// DEFINE THE Blocks SCANNER.
|
||||
// itializes a new scanner.
|
||||
func newBlocksScanner(things []*Blocks) *BlocksScanner {
|
||||
return &BlocksScanner{things: things}
|
||||
}
|
||||
|
||||
type BlocksScanner struct {
|
||||
sync.Mutex
|
||||
|
||||
things []*Blocks
|
||||
index int
|
||||
}
|
||||
|
||||
func (it *BlocksScanner) Scan() bool {
|
||||
if it.index >= len(it.things) {
|
||||
return false
|
||||
}
|
||||
it.Lock()
|
||||
it.index++
|
||||
it.Unlock()
|
||||
return true
|
||||
}
|
||||
|
||||
// Next() returns the next thing in the array
|
||||
func (it *BlocksScanner) Next() *Blocks {
|
||||
if it.things[it.index-1] == nil {
|
||||
fmt.Println("Next() error in BlocksScanner", it.index)
|
||||
}
|
||||
return it.things[it.index-1]
|
||||
}
|
||||
|
||||
// END DEFINE THE SCANNER
|
||||
|
||||
// DEFINE THE Block SCANNER.
|
||||
// itializes a new scanner.
|
||||
func newBlockScanner(things []*Block) *BlockScanner {
|
||||
return &BlockScanner{things: things}
|
||||
}
|
||||
|
||||
type BlockScanner struct {
|
||||
sync.Mutex
|
||||
|
||||
things []*Block
|
||||
index int
|
||||
}
|
||||
|
||||
func (it *BlockScanner) Scan() bool {
|
||||
if it.index >= len(it.things) {
|
||||
return false
|
||||
}
|
||||
it.Lock()
|
||||
it.index++
|
||||
it.Unlock()
|
||||
return true
|
||||
}
|
||||
|
||||
// Next() returns the next thing in the array
|
||||
func (it *BlockScanner) Next() *Block {
|
||||
if it.things[it.index-1] == nil {
|
||||
fmt.Println("Next() error in BlockScanner", it.index)
|
||||
}
|
||||
return it.things[it.index-1]
|
||||
}
|
||||
|
||||
// END DEFINE THE SCANNER
|
||||
|
||||
// sort struct by Name
|
||||
type sortBlockName []*Block
|
||||
|
||||
func (a sortBlockName) Len() int { return len(a) }
|
||||
func (a sortBlockName) Less(i, j int) bool { return a[i].Name < a[j].Name }
|
||||
func (a sortBlockName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
|
||||
// safely returns a slice of pointers to the FRUIT protobufs
|
||||
func (x *Blocks) allBlocks() []*Block {
|
||||
x.RLock()
|
||||
defer x.RUnlock()
|
||||
|
||||
// Create a new slice to hold pointers to each FRUIT
|
||||
var tmp []*Block
|
||||
tmp = make([]*Block, len(x.Blocks))
|
||||
for i, p := range x.Blocks {
|
||||
tmp[i] = p // Copy pointers for safe iteration
|
||||
}
|
||||
|
||||
return tmp
|
||||
}
|
||||
|
||||
// safely returns a slice of pointers to the Block protobufs
|
||||
func (x *Blocks) selectAllBlocks() []*Block {
|
||||
x.RLock()
|
||||
defer x.RUnlock()
|
||||
|
||||
// Create a new slice to hold pointers to each Block
|
||||
var tmp []*Block
|
||||
tmp = make([]*Block, len(x.Blocks))
|
||||
for i, p := range x.Blocks {
|
||||
tmp[i] = p // Copy pointers for safe iteration
|
||||
}
|
||||
|
||||
return tmp
|
||||
}
|
||||
func (x *Blocks) SortByName() *BlockScanner {
|
||||
// copy the pointers as fast as possible.
|
||||
things := x.selectAllBlocks()
|
||||
|
||||
// todo: try slices.SortFunc() instead to see what happens
|
||||
sort.Sort(sortBlockName(things))
|
||||
// slices.SortFunc(things, func(a, b *Blocks) bool {
|
||||
// return a.Name < b.Name // Sort by ??. let the compiler work it out??
|
||||
// })
|
||||
return newBlockScanner(things)
|
||||
}
|
||||
|
||||
// 'for x := range' syntax using the awesome golang 1.24 'iter'
|
||||
func (x *Blocks) IterByName() iter.Seq[*Block] {
|
||||
items := x.selectAllBlocks()
|
||||
sort.Sort(sortBlockName(items))
|
||||
// log.Println("Made Iter.Seq[] with length", len(items))
|
||||
return func(yield func(*Block) bool) {
|
||||
for _, v := range items {
|
||||
if !yield(v) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// END SORT
|
||||
|
||||
func (x *Blocks) Len() int {
|
||||
x.RLock()
|
||||
defer x.RUnlock()
|
||||
|
||||
return len(x.Blocks)
|
||||
}
|
||||
|
||||
// just a simple Append() shortcut (but still uses the mutex lock)
|
||||
func (x *Blocks) Append(y *Block) {
|
||||
x.Lock()
|
||||
defer x.Unlock()
|
||||
|
||||
x.Blocks = append(x.Blocks, y)
|
||||
}
|
||||
|
||||
func (x *Blocks) All() *BlockScanner {
|
||||
BlockPointers := x.selectAllBlocks()
|
||||
|
||||
scanner := newBlockScanner(BlockPointers)
|
||||
return scanner
|
||||
}
|
||||
|
||||
// Iterate 'for x := range' syntax using the awesome golang 1.24 'iter'
|
||||
func (x *Blocks) IterAll() iter.Seq[*Block] {
|
||||
items := x.selectAllBlocks()
|
||||
// log.Println("Made All() Iter.Seq[] with length", len(items))
|
||||
return func(yield func(*Block) bool) {
|
||||
for _, v := range items {
|
||||
if !yield(v) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
func (x *Blocks) Delete(y *Block) bool {
|
||||
x.Lock()
|
||||
defer x.Unlock()
|
||||
|
||||
for i, _ := range x.Blocks {
|
||||
if x.Blocks[i] == y {
|
||||
x.Blocks[i] = x.Blocks[len(x.Blocks)-1]
|
||||
x.Blocks = x.Blocks[:len(x.Blocks)-1]
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// lookup a Blocks by the Name
|
||||
func (x *Blocks) FindByName(s string) *Block {
|
||||
if x == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
x.RLock()
|
||||
defer x.RUnlock()
|
||||
|
||||
for i, _ := range x.Blocks {
|
||||
if x.Blocks[i].Name == s {
|
||||
return x.Blocks[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// returns a Block if Name matches, otherwise create
|
||||
func (x *Blocks) InsertByName(y string) *Block {
|
||||
x.Lock()
|
||||
defer x.Unlock()
|
||||
|
||||
for _, z := range x.Blocks {
|
||||
if z.Name == y {
|
||||
return z
|
||||
}
|
||||
}
|
||||
|
||||
z := new(Block)
|
||||
z.Name = y
|
||||
x.Blocks = append(x.Blocks, z)
|
||||
return z
|
||||
}
|
||||
|
||||
func (x *Blocks) DeleteByName(s string) bool {
|
||||
x.Lock()
|
||||
defer x.Unlock()
|
||||
|
||||
for i, _ := range x.Blocks {
|
||||
if x.Blocks[i].Name == s {
|
||||
x.Blocks[i] = x.Blocks[len(x.Blocks)-1]
|
||||
x.Blocks = x.Blocks[:len(x.Blocks)-1]
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *Blocks) AppendByName(y *Block) bool {
|
||||
x.Lock()
|
||||
defer x.Unlock()
|
||||
|
||||
for _, p := range x.Blocks {
|
||||
if p.Name == y.Name {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
x.Blocks = append(x.Blocks, y)
|
||||
return true
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
module go.wit.com/apps/utils/fixup
|
||||
|
||||
go 1.24.1
|
||||
|
||||
require (
|
||||
github.com/diskfs/go-diskfs v1.7.0
|
||||
go.wit.com/dev/alexflint/arg v1.6.2
|
||||
go.wit.com/gui v0.22.47
|
||||
go.wit.com/lib/debugger v0.22.31
|
||||
go.wit.com/lib/gadgets v0.22.30
|
||||
go.wit.com/lib/gui/logsettings v0.22.30
|
||||
go.wit.com/lib/gui/shell v0.22.30
|
||||
go.wit.com/lib/protobuf/virtpb v0.2.40
|
||||
go.wit.com/log v0.22.17
|
||||
google.golang.org/protobuf v1.36.8
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/alexflint/go-scalar v1.2.0 // indirect
|
||||
github.com/anchore/go-lzo v0.1.0 // indirect
|
||||
github.com/djherbis/times v1.6.0 // indirect
|
||||
github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab // indirect
|
||||
github.com/go-cmd/cmd v1.4.3 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/klauspost/compress v1.17.4 // indirect
|
||||
github.com/pierrec/lz4/v4 v4.1.17 // indirect
|
||||
github.com/pkg/xattr v0.4.9 // indirect
|
||||
github.com/sirupsen/logrus v1.9.4-0.20230606125235-dd1b4c2e81af // indirect
|
||||
github.com/ulikunitz/xz v0.5.11 // indirect
|
||||
go.wit.com/lib/protobuf/guipb v0.0.12 // indirect
|
||||
go.wit.com/widget v1.1.30 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
)
|
|
@ -0,0 +1,60 @@
|
|||
github.com/alexflint/go-scalar v1.2.0 h1:WR7JPKkeNpnYIOfHRa7ivM21aWAdHD0gEWHCx+WQBRw=
|
||||
github.com/alexflint/go-scalar v1.2.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o=
|
||||
github.com/anchore/go-lzo v0.1.0 h1:NgAacnzqPeGH49Ky19QKLBZEuFRqtTG9cdaucc3Vncs=
|
||||
github.com/anchore/go-lzo v0.1.0/go.mod h1:3kLx0bve2oN1iDwgM1U5zGku1Tfbdb0No5qp1eL1fIk=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/diskfs/go-diskfs v1.7.0 h1:vonWmt5CMowXwUc79jWyGrf2DIMeoOjkLlMnQYGVOs8=
|
||||
github.com/diskfs/go-diskfs v1.7.0/go.mod h1:LhQyXqOugWFRahYUSw47NyZJPezFzB9UELwhpszLP/k=
|
||||
github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=
|
||||
github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0=
|
||||
github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab h1:h1UgjJdAAhj+uPL68n7XASS6bU+07ZX1WJvVS2eyoeY=
|
||||
github.com/elliotwutingfeng/asciiset v0.0.0-20230602022725-51bbb787efab/go.mod h1:GLo/8fDswSAniFG+BFIaiSPcK610jyzgEhWYPQwuQdw=
|
||||
github.com/go-cmd/cmd v1.4.3 h1:6y3G+3UqPerXvPcXvj+5QNPHT02BUw7p6PsqRxLNA7Y=
|
||||
github.com/go-cmd/cmd v1.4.3/go.mod h1:u3hxg/ry+D5kwh8WvUkHLAMe2zQCaXd00t35WfQaOFk=
|
||||
github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg=
|
||||
github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
|
||||
github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
|
||||
github.com/pierrec/lz4/v4 v4.1.17 h1:kV4Ip+/hUBC+8T6+2EgburRtkE9ef4nbY3f4dFhGjMc=
|
||||
github.com/pierrec/lz4/v4 v4.1.17/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
||||
github.com/pkg/xattr v0.4.9 h1:5883YPCtkSd8LFbs13nXplj9g9tlrwoJRjgpgMu1/fE=
|
||||
github.com/pkg/xattr v0.4.9/go.mod h1:di8WF84zAKk8jzR1UBTEWh9AUlIZZ7M/JNt8e9B6ktU=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sirupsen/logrus v1.9.4-0.20230606125235-dd1b4c2e81af h1:Sp5TG9f7K39yfB+If0vjp97vuT74F72r8hfRpP8jLU0=
|
||||
github.com/sirupsen/logrus v1.9.4-0.20230606125235-dd1b4c2e81af/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
|
||||
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
|
||||
go.wit.com/dev/alexflint/arg v1.6.2 h1:5TSmo0qJnfSY82MrjjtxFOoX7EkTmMs/hsmOcCFxNmU=
|
||||
go.wit.com/dev/alexflint/arg v1.6.2/go.mod h1:3MrBCZBVbb5vea1NpJ8pdwGoDXIAIOHcZqj0fGuRUrM=
|
||||
go.wit.com/gui v0.22.48 h1:TeTcbUERZOG5ceZdUaP+zDNq/UIR3O9BV7Pq6fiJk2s=
|
||||
go.wit.com/gui v0.22.48/go.mod h1:ulugUrJlDrt2tIoJYHoRJQY18+upZ0bF0gYNj3089Tc=
|
||||
go.wit.com/lib/debugger v0.22.32 h1:4roMzwtEuf2gDKrjAajcWBNtw1IbRcbx53ku8lbuWRU=
|
||||
go.wit.com/lib/debugger v0.22.32/go.mod h1:MygpfhNJjsflAJXNCXmnWXvGlF4AwzS/WYaumuxUEro=
|
||||
go.wit.com/lib/gadgets v0.22.31 h1:8EpUzzihkU/aGQ5SCC19tNEvbXvVeUPy4MVjh7OfN94=
|
||||
go.wit.com/lib/gadgets v0.22.31/go.mod h1:70MjaQfRVQCB9IR52tQMStLCpacwYi6wFZ1LyfqwH48=
|
||||
go.wit.com/lib/gui/logsettings v0.22.31 h1:mppe1vdTPmkgl21w7LI7jK02XeHPHzfyHQ5lZFjp7uE=
|
||||
go.wit.com/lib/gui/logsettings v0.22.31/go.mod h1:tehGMljXQUTkfYNTc9/Vz6qa1ennmYvFCfu0FrgWbpo=
|
||||
go.wit.com/lib/gui/shell v0.22.30 h1:d9Gjgry3P4bZCVz8WeOVodkp7IIerCl+74kfMPOV6qA=
|
||||
go.wit.com/lib/gui/shell v0.22.30/go.mod h1:BWVNCsK4gyo085YJnTz+zqe/8N8tGKSMrCHfGWna4JE=
|
||||
go.wit.com/lib/protobuf/guipb v0.0.12 h1:Yxf0eCVRU4R+w33SulLSnkDMi6KiW/mL7O5nHEelVFU=
|
||||
go.wit.com/lib/protobuf/guipb v0.0.12/go.mod h1:eD5DG8UozJli7Q6BDoIVNThJjcaTfsOi9AGwlk5gOUk=
|
||||
go.wit.com/lib/protobuf/virtpb v0.2.41 h1:8i++yWpzIra8kdtcwGps9uxJ3womGSbOVC39zhJsleU=
|
||||
go.wit.com/lib/protobuf/virtpb v0.2.41/go.mod h1:lUGcQ9wR0w0dwKd0rqb/AiGimZAz33G82ulQlrKTk1A=
|
||||
go.wit.com/log v0.22.17 h1:rAnrUPbQ/k34Fxqq4buKofvwKRvODcV4/qiXJREiqD4=
|
||||
go.wit.com/log v0.22.17/go.mod h1:XE4lTfAibWgwBJksIk7u3IEJ8xcBvNhnlewYAQGj2Ew=
|
||||
go.wit.com/widget v1.1.30 h1:O/dIG7QtDrZkR5P6f8JAMyevBiMXSun9vL6F0KFAWV8=
|
||||
go.wit.com/widget v1.1.30/go.mod h1:wj7TpAr2gk7Poa+v8XQkH1aidnTdgAa/a8GxrMtcztw=
|
||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc=
|
||||
google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
|
||||
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
|
||||
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
Loading…
Reference in New Issue