Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sortkeys #98

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
result
/bin
29 changes: 25 additions & 4 deletions tools/override/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"log"
"os"
"path/filepath"
"sort"
"strings"

"github.com/linuxdeepin/go-lib/keyfile"
Expand Down Expand Up @@ -139,6 +140,24 @@ func getValue(value string, kf *keyfile.KeyFile, section0 string) string {
return value
}

type ConfigKVUnit struct {
key string
justforlxz marked this conversation as resolved.
Show resolved Hide resolved
val string
}

func mapToSortedList(basket map[string]string) []ConfigKVUnit {
keys := make([]string, 0, len(basket))
for k := range basket {
keys = append(keys, k)
}
sort.Strings(keys)
out := []ConfigKVUnit{}
for _, k := range keys {
out = append(out, ConfigKVUnit{key: k, val: basket[k]})
}
return out
}

func combineFiles(inputFiles []string, outputFile string) (err error) {
log.Printf("inputFiles: %+v -> outputFile: %s\n", inputFiles, outputFile)
combinedKf := keyfile.NewKeyFile()
Expand All @@ -151,11 +170,13 @@ func combineFiles(inputFiles []string, outputFile string) (err error) {
return
}
sections := kf.GetSections()
sort.Strings(sections)

for _, section := range sections {
justforlxz marked this conversation as resolved.
Show resolved Hide resolved
sectionMap, _ := kf.GetSection(section)
for key, val := range sectionMap {
val = getValue(val, kf, section)
combinedKf.SetValue(section, key, val)
sectionMapPre, _ := kf.GetSection(section)
sortedList := mapToSortedList(sectionMapPre)
for i := range sortedList {
combinedKf.SetValue(section, sortedList[i].key, sortedList[i].val)
}
}
}
Expand Down
Loading