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

View file

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