sign 10 at once, repoadd 1 at once but new goroutine each time

This commit is contained in:
ferrreo 2023-09-05 10:54:55 +01:00
parent 58357ad68a
commit 57600fe132
2 changed files with 83 additions and 16 deletions

BIN
ppp

Binary file not shown.

View File

@ -136,17 +136,38 @@ func repoAdd(path string, args string) {
panic(err) panic(err)
} }
for _, file := range files { addQueue := make(chan string, 1)
if strings.HasSuffix(file, ".deb") { var wg sync.WaitGroup
fmt.Printf("adding to repo %s \n", file) for i := 0; i < 1; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for {
select {
case path, ok := <-addQueue:
if !ok {
return
}
ch := make(chan bool)
go func() {
add(ch, path, args)
}()
<-ch
default:
// No more files to add, exit the goroutine
return
}
}
}()
}
cmd := exec.Command("reprepro", args, path+file) for _, file := range files {
err := cmd.Run() addQueue <- path + file
if err != nil {
panic(err)
}
}
} }
close(addQueue)
wg.Wait()
} }
func signFiles(path string) { func signFiles(path string) {
@ -162,16 +183,62 @@ func signFiles(path string) {
panic(err) panic(err)
} }
signQueue := make(chan string, 10)
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for {
select {
case path, ok := <-signQueue:
if !ok {
return
}
ch := make(chan bool)
go func() {
sign(ch, path)
}()
<-ch
default:
// No more files to sign, exit the goroutine
return
}
}
}()
}
for _, file := range files { for _, file := range files {
if strings.HasSuffix(file, ".deb") { signQueue <- path + file
fmt.Printf("Signing %s \n", file) }
cmd := exec.Command("dpkg-sig", "--sign", "builder", path+file)
close(signQueue)
wg.Wait()
}
func sign(ch chan bool, path string) {
if strings.HasSuffix(path, ".deb") {
fmt.Printf("Signing %s \n", path)
cmd := exec.Command("dpkg-sig", "--sign", "builder", path)
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil {
panic(err) panic(err)
} }
} }
ch <- true
}
func add(ch chan bool, path string, args string) {
if strings.HasSuffix(path, ".deb") {
fmt.Printf("Adding to repo %s \n", path)
cmd := exec.Command("reprepro", args, path)
err := cmd.Run()
if err != nil {
panic(err)
} }
}
ch <- true
} }
func download(packages map[string]packageInfo, url string, output string) { func download(packages map[string]packageInfo, url string, output string) {