1
0
Fork 0
mirror of https://github.com/vbatts/freezing-octo-hipster.git synced 2024-11-21 22:45:39 +00:00

slackware-sync: cleanup

This commit is contained in:
Vincent Batts 2016-11-29 12:40:18 -05:00
parent 37f4637216
commit dab7b38f81
2 changed files with 11 additions and 15 deletions

View file

@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"log"
"net/url"
"os"
"os/exec"
@ -22,10 +23,8 @@ var (
func main() {
flag.Parse()
var config GeneralConfig
_, err := toml.DecodeFile(*flConfigFile, &config)
if err != nil {
fmt.Println(err)
os.Exit(1)
if _, err := toml.DecodeFile(*flConfigFile, &config); err != nil {
log.Fatal(err)
}
if len(*flSyncDir) > 0 {
@ -35,10 +34,8 @@ func main() {
config.Threads = *flThreads
}
_, err = EnsureDirExists(config.SyncDir)
if err != nil {
fmt.Println(err)
os.Exit(1)
if _, err = EnsureDirExists(config.SyncDir); err != nil {
log.Fatal(err)
}
workers := make(chan int, config.Threads)
@ -53,19 +50,18 @@ func main() {
continue
}
dest := path.Join(config.SyncDir, uri.Host, uri.Path)
_, err = EnsureDirExists(dest)
if err != nil {
if _, err = EnsureDirExists(dest); err != nil {
fmt.Fprintln(os.Stderr, err)
continue
}
wg.Add(1)
rsyncFunc := func() {
if *flThreads > 1 {
if config.Threads > 1 {
workers <- 1
}
defer func() {
if *flThreads > 1 {
if config.Threads > 1 {
<-workers
}
wg.Done()
@ -76,12 +72,11 @@ func main() {
cmd.Stdout = os.Stdout
}
err = cmd.Run()
if err != nil {
if err = cmd.Run(); err != nil {
fmt.Fprintf(os.Stderr, "%q: %s", name, err)
}
}
if *flThreads > 1 {
if config.Threads > 1 {
go rsyncFunc()
} else {
rsyncFunc()

View file

@ -1,3 +1,4 @@
threads = 2
sync_dir = "/mnt/storage/slackware"
[mirrors]