Skip to content

Commit 3a6c36f

Browse files
committed
Following changes:
* Upgrade to Go 1.19 and upgrade library versions * Use github.com/deckarep/golang-set/v2 instead of custom implementation * Flag --shellscript-at-path * Documentation improvements
1 parent cff3524 commit 3a6c36f

File tree

16 files changed

+196
-135
lines changed

16 files changed

+196
-135
lines changed

.github/workflows/build-and-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: Setup Golang
1313
uses: actions/setup-go@v2
1414
with:
15-
go-version: 1.18
15+
go-version: 1.19
1616
- name: Build code
1717
run: go build
1818
- name: Test code

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
*.sh
44
*.txt
55
*.out
6-
/test_cases_*
6+
/test_cases_*
7+
.DS_Store

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.18-alpine3.15 as builder
1+
FROM golang:1.19-alpine3.16 as builder
22

33
RUN apk --no-cache add build-base
44

@@ -14,7 +14,7 @@ RUN go build
1414

1515
RUN go test -v ./...
1616

17-
FROM alpine:3.15
17+
FROM alpine:3.16
1818

1919
RUN apk --no-cache add bash rsync
2020

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ photos, etc.) _that are reorganized frequently_.
1313
`rsync-sidekick` is a safe and simple tool that is designed to run **before** `rsync` is run.
1414

1515
## What does this do?
16+
1617
`rsync-sidekick` propagates following changes (or any combination) from _source directory_ to _destination directory_:
1718

1819
1. Change in file modification timestamp
@@ -33,7 +34,7 @@ Note:
3334

3435
## How to install?
3536

36-
1. Install Go version at least **1.18**
37+
1. Install Go version at least **1.19**
3738
* On Ubuntu: `snap install go`
3839
* On Mac: `brew install go`
3940
* For anything else: [Go downloads page](https://go.dev/dl/)
@@ -76,14 +77,16 @@ where,
7677
[destination-dir] Destination directory
7778
7879
flags: (all optional)
79-
-x, --exclusions string path to file containing newline separated list of file/directory names to be excluded
80-
(even if this is not set, files/directories such these will still be ignored: $RECYCLE.BIN, desktop.ini, Thumbs.db etc.)
81-
-h, --help display help
82-
--list list files along their metadata for given directory
83-
-s, --shellscript instead of applying changes directly, generate a shell script
84-
(this flag is useful if you want 'dry run' this tool or want to run the shell script as a different user)
85-
-v, --verbose generates extra information, even a file dump (caution: makes it slow!)
86-
--version show version
80+
-x, --exclusions string path to file containing newline separated list of file/directory names to be excluded
81+
(even if this is not set, files/directories such these will still be ignored: $RECYCLE.BIN, desktop.ini, Thumbs.db etc.)
82+
-h, --help display help
83+
--list list files along their metadata for given directory
84+
-s, --shellscript instead of applying changes directly, generate a shell script
85+
(this flag is useful if you want 'dry run' this tool or want to run the shell script as a different user)
86+
-p, --shellscript-at-path string similar to --shellscript option but you can specify output script path
87+
(this flag cannot be specified if --shellscript option is specified)
88+
-v, --verbose generates extra information, even a file dump (caution: makes it slow!)
89+
--version show application version (v1.5.0) and exit
8790
8891
More details here: https://github.com/m-manu/rsync-sidekick
8992
```

action/action.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type SyncAction interface {
1818

1919
const cmdSeparator = "\u0001"
2020

21+
// escape escapes the path for use in a unix command
2122
func escape(path string) string {
2223
escaped := path
2324
escaped = strings.ReplaceAll(escaped, "\\", "\\\\") // This replace should be first

bytesutil/human_readable_size.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ const (
2222
EXBI = PEBI * KIBI // 1024 power 6 (2 power 60)
2323
)
2424

25-
// BinaryFormat formats a byte size to a human readable string in binary format.
25+
// BinaryFormat formats a byte size to a human-readable string in binary format.
2626
// Uses binary prefixes. See: https://en.m.wikipedia.org/wiki/Binary_prefix
2727
//
2828
// For example,
29-
// fmt.Println(bytesutil.BinaryFormat(2140))
29+
//
30+
// fmt.Println(bytesutil.BinaryFormat(2140))
31+
//
3032
// prints
31-
// 2.09 KiB
33+
//
34+
// 2.09 KiB
3235
func BinaryFormat(size int64) string {
3336
if size < 0 {
3437
return ""
@@ -49,13 +52,16 @@ func BinaryFormat(size int64) string {
4952
}
5053
}
5154

52-
// DecimalFormat formats a byte size to a human readable string in decimal format.
55+
// DecimalFormat formats a byte size to a human-readable string in decimal format.
5356
// Uses metric prefixes. See: https://en.m.wikipedia.org/wiki/Metric_prefix
5457
//
5558
// For example,
56-
// fmt.Println(bytesutil.DecimalFormat(2140))
59+
//
60+
// fmt.Println(bytesutil.DecimalFormat(2140))
61+
//
5762
// prints
58-
// 2.14KB
63+
//
64+
// 2.14KB
5965
func DecimalFormat(size int64) string {
6066
if size < 0 {
6167
return ""

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
module github.com/m-manu/rsync-sidekick
22

3-
go 1.18
3+
go 1.19
44

55
require (
6+
github.com/deckarep/golang-set/v2 v2.3.0
67
github.com/spf13/pflag v1.0.5
7-
github.com/stretchr/testify v1.8.1
8-
golang.org/x/text v0.5.0
8+
github.com/stretchr/testify v1.8.2
9+
golang.org/x/text v0.9.0
910
)
1011

1112
require (

go.sum

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
22
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
33
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/deckarep/golang-set/v2 v2.3.0 h1:qs18EKUfHm2X9fA50Mr/M5hccg2tNnVqsiBImnyDs0g=
5+
github.com/deckarep/golang-set/v2 v2.3.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
46
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
57
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
68
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
@@ -10,10 +12,10 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
1012
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
1113
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
1214
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
13-
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
14-
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
15-
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
16-
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
15+
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
16+
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
17+
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
18+
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
1719
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1820
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1921
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

lib/set.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

lib/utils.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package lib
22

33
import (
4+
set "github.com/deckarep/golang-set/v2"
45
"io/fs"
56
"os"
67
"path/filepath"
@@ -31,27 +32,23 @@ func IsReadableFile(path string) bool {
3132
return fileInfo.Mode().IsRegular()
3233
}
3334

34-
// WriteSliceToFile writes a slice to a file
35+
// WriteSliceToFile writes a slice of strings to a file
3536
func WriteSliceToFile(slice []string, fileName string) {
3637
sliceAsString := strings.Join(slice, "\n")
3738
_ = os.WriteFile(fileName, []byte(sliceAsString), fs.ModePerm)
3839
}
3940

40-
// LineSeparatedStrToMap converts a line-separated string to a map with keys and empty values
41-
func LineSeparatedStrToMap(lineSeparatedString string) (set Set[string], firstFew []string) {
42-
set = NewSet[string](20)
41+
// LineSeparatedStrToMap converts a line-separated string to a Set of values
42+
func LineSeparatedStrToMap(lineSeparatedString string) (entries set.Set[string], firstFew []string) {
43+
entries = set.NewThreadUnsafeSetWithSize[string](20)
4344
firstFew = []string{}
4445
for _, e := range strings.Split(lineSeparatedString, "\n") {
45-
set.Add(e)
46+
entries.Add(strings.TrimSpace(e))
4647
firstFew = append(firstFew, e)
4748
}
4849
if len(firstFew) > 3 {
4950
firstFew = firstFew[0:3]
5051
}
51-
for e := range set {
52-
if strings.TrimSpace(e) == "" {
53-
delete(set, e)
54-
}
55-
}
52+
entries.Remove("")
5653
return
5754
}

0 commit comments

Comments
 (0)