From 540926358b7ad974f2f3258d4fe6e88249cbd777 Mon Sep 17 00:00:00 2001 From: sneak Date: Wed, 22 May 2024 13:58:36 -0700 Subject: [PATCH] latest --- Makefile | 13 +++++++++++++ README.md | 8 ++++++++ go.mod | 2 ++ go.sum | 4 ++++ sources.go | 7 +++++-- 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 README.md diff --git a/Makefile b/Makefile index cbf18f0..11e86a0 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,18 @@ +TESTHOST := nnny-sync-alpha.nebula + fmt: go fmt ./... lint: golangci-lint run + +test: + rsync -avP --exclude .git --delete ./ root@$(TESTHOST):/root/fastmirror + ssh root@$(TESTHOST) "cd /root/fastmirror && make dotest" + +dotest: + rm -f /etc/apt/sources.list.d/* + cp /root/ubuntu.sources /etc/apt/sources.list.d/ + go build -o ./fastmirror ./cmd/fastmirror + ./fastmirror + diff --git a/README.md b/README.md new file mode 100644 index 0000000..70cd132 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# WIP + +This doesn't work right yet. + +# See also + +* https://askubuntu.com/questions/428698/are-there-alternative-repositories-to-ports-ubuntu-com-for-arm + diff --git a/go.mod b/go.mod index 6d17566..8cf6ed4 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,10 @@ go 1.22.2 require ( github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect + github.com/otiai10/copy v1.14.0 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/schollz/progressbar/v3 v3.14.3 // indirect + golang.org/x/sync v0.3.0 // indirect golang.org/x/sys v0.20.0 // indirect golang.org/x/term v0.20.0 // indirect ) diff --git a/go.sum b/go.sum index af4bd7b..b4bfc5a 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1 github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= +github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= +github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= @@ -11,6 +13,8 @@ github.com/schollz/progressbar/v3 v3.14.3 h1:oOuWW19ka12wxYU1XblR4n16wF/2Y1dBLMa github.com/schollz/progressbar/v3 v3.14.3/go.mod h1:aT3UQ7yGm+2ZjeXPqsjTenwL3ddUiuZ0kfQ/2tHlyNI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= diff --git a/sources.go b/sources.go index a26f967..20aa381 100644 --- a/sources.go +++ b/sources.go @@ -9,6 +9,8 @@ import ( "path/filepath" "regexp" "strings" + + cp "github.com/otiai10/copy" ) func findSourcesFilePath() (string, error) { @@ -67,8 +69,9 @@ func createBackup(filePath string) error { if _, err := os.Stat(backupPath); err == nil { return fmt.Errorf("backup file %s already exists", backupPath) } - if err := os.Rename(filePath, backupPath); err != nil { - return fmt.Errorf("failed to create backup of %s: %v", filePath, err) + // copy the file to the backup file + if err := cp.Copy(filePath, backupPath); err != nil { + return fmt.Errorf("failed to create backup file %s: %v", backupPath, err) } log.Printf("Created backup: %s", backupPath) return nil