Skip to content

Commit 1626ee9

Browse files
committed
Upgraded to Go 1.18. Upgrades to dependent libraries.
1 parent f1cba29 commit 1626ee9

File tree

12 files changed

+59
-33
lines changed

12 files changed

+59
-33
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.17
15+
go-version: 1.18
1616
- name: Build code
1717
run: go build
1818
- name: Test code

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.17-alpine3.15 as builder
1+
FROM golang:1.18-alpine3.15 as builder
22

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

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ portable hard drives etc.
1212

1313
**Note**:
1414

15-
* This tool just *reads* your files and creates a 'duplicates report' file
16-
* It does **not** delete or otherwise modify your files in any way 🙂
17-
* So, it's very safe to use 👍
18-
15+
* This tool just *reads* your files and creates a 'duplicates report' file
16+
* It does **not** delete or otherwise modify your files in any way 🙂
17+
* So, it's very safe to use 👍
1918

2019
## How to install?
2120

22-
1. Install Go version at least **1.17**
21+
1. Install Go version at least **1.18**
2322
* See: [Go installation instructions](https://go.dev/doc/install)
2423
2. Run command:
2524
```bash

entity/digest_to_files.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type DigestToFiles struct {
1212
data *treemap.Map
1313
}
1414

15-
func FileDigestComparator(a, b interface{}) int {
15+
func FileDigestComparator(a, b any) int {
1616
fa := a.(FileDigest)
1717
fb := b.(FileDigest)
1818
if fa.FileSize < fb.FileSize {

fmte/fmt_english.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ func init() {
1616
}
1717

1818
// Printf is goroutine-safe fmt.Printf for English
19-
func Printf(format string, a ...interface{}) {
19+
func Printf(format string, a ...any) {
2020
mxStdOut.Lock()
2121
_, _ = p.Printf(format, a...)
2222
mxStdOut.Unlock()
2323
}
2424

2525
// PrintfErr is goroutine-safe fmt.Printf to StdErr for English
26-
func PrintfErr(format string, a ...interface{}) {
26+
func PrintfErr(format string, a ...any) {
2727
mxStdErr.Lock()
2828
_, _ = p.Fprintf(os.Stderr, format, a...)
2929
mxStdErr.Unlock()

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
module github.com/m-manu/go-find-duplicates
22

3-
go 1.17
3+
go 1.18
44

55
require (
66
github.com/emirpasic/gods v1.18.1
77
github.com/spf13/pflag v1.0.5
8-
github.com/stretchr/testify v1.7.1
9-
golang.org/x/text v0.3.7
8+
github.com/stretchr/testify v1.8.1
9+
golang.org/x/text v0.3.8
1010
)
1111

1212
require (
13-
github.com/davecgh/go-spew v1.1.0 // indirect
13+
github.com/davecgh/go-spew v1.1.1 // indirect
1414
github.com/pmezard/go-difflib v1.0.0 // indirect
15-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
15+
gopkg.in/yaml.v3 v3.0.1 // indirect
1616
)

go.sum

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
21
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
34
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
45
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
56
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
67
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
78
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
89
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
910
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
10-
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
11+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
12+
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=
12-
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
13-
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
14-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
14+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
15+
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
16+
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
17+
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
18+
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
1519
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1620
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
17-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
1821
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
22+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
23+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

main.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var defaultExclusionsStr string
4141
var flags struct {
4242
isHelp func() bool
4343
getOutputMode func() string
44-
getExcludedFiles func() map[string]struct{}
44+
getExcludedFiles func() utils.Set[string]
4545
getMinSize func() int64
4646
getParallelism func() int
4747
isThorough func() bool
@@ -55,9 +55,9 @@ func setupExclusionsOpt() {
5555
fmt.Sprintf("path to file containing newline-separated list of file/directory names to be excluded\n"+
5656
"(if this is not set, by default these will be ignored:\n%s etc.)",
5757
strings.Join(defaultExclusionsExamples, ", ")))
58-
flags.getExcludedFiles = func() map[string]struct{} {
58+
flags.getExcludedFiles = func() utils.Set[string] {
5959
excludesListFilePath := *excludesListFilePathPtr
60-
var exclusions map[string]struct{}
60+
var exclusions utils.Set[string]
6161
if excludesListFilePath == exclusionsDefaultValue {
6262
exclusions = defaultExclusions
6363
} else {
@@ -202,7 +202,7 @@ func setupFlags() {
202202

203203
func main() {
204204
defer handlePanic()
205-
runID := time.Now().Format("150405")
205+
runID := time.Now().Format("060102_150405")
206206
setupFlags()
207207
flag.Parse()
208208
if flags.isHelp() {
@@ -247,10 +247,11 @@ func createReportFileIfApplicable(runID string, outputMode string) (reportFileNa
247247
} else if outputMode == entity.OutputModeJSON {
248248
reportFileName = fmt.Sprintf("./duplicates_%s.json", runID)
249249
}
250-
_, err := os.Create(reportFileName)
250+
f, err := os.Create(reportFileName)
251251
if err != nil {
252252
fmte.PrintfErr("error: couldn't create report file: %+v\n", err)
253253
os.Exit(exitCodeReportFileCreationFailed)
254254
}
255+
f.Close()
255256
return
256257
}

service/dir_scanner.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import (
55
"fmt"
66
"github.com/m-manu/go-find-duplicates/entity"
77
"github.com/m-manu/go-find-duplicates/fmte"
8+
"github.com/m-manu/go-find-duplicates/utils"
89
"io/fs"
910
"path/filepath"
1011
"strings"
1112
)
1213

13-
func populateFilesFromDirectory(dirPathToScan string, exclusions map[string]struct{}, fileSizeThreshold int64,
14+
func populateFilesFromDirectory(dirPathToScan string, exclusions utils.Set[string], fileSizeThreshold int64,
1415
allFiles entity.FilePathToMeta) (
1516
sizeOfScannedFiles int64,
1617
err error,
@@ -21,7 +22,7 @@ func populateFilesFromDirectory(dirPathToScan string, exclusions map[string]stru
2122
return nil
2223
}
2324
// If the file/directory is in excluded allFiles list, ignore it
24-
if _, exists := exclusions[d.Name()]; exists {
25+
if exclusions.Exists(d.Name()) {
2526
if d.IsDir() {
2627
return filepath.SkipDir
2728
}

service/find_duplicates.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
// FindDuplicates finds duplicate files in a given set of directories and matching criteria
15-
func FindDuplicates(directories []string, excludedFiles map[string]struct{}, fileSizeThreshold int64, parallelism int,
15+
func FindDuplicates(directories []string, excludedFiles utils.Set[string], fileSizeThreshold int64, parallelism int,
1616
isThorough bool) (
1717
duplicates *entity.DigestToFiles, duplicateTotalCount int64, savingsSize int64,
1818
allFiles entity.FilePathToMeta, err error,

0 commit comments

Comments
 (0)