From 4e8d2794f2e3f498394d2edec63cf9e3221f5efe Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Sun, 30 Jun 2024 13:37:37 -0700 Subject: [PATCH 1/3] update linter and 1 go mod --- .github/workflows/codetests.yml | 4 ++-- .golangci.yml | 12 ++---------- go.mod | 2 +- go.sum | 22 +++------------------- start.go | 18 +++++++++--------- 5 files changed, 17 insertions(+), 41 deletions(-) diff --git a/.github/workflows/codetests.yml b/.github/workflows/codetests.yml index 3868524..bd0de16 100644 --- a/.github/workflows/codetests.yml +++ b/.github/workflows/codetests.yml @@ -36,7 +36,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: v1.54 + version: v1.59 # Runs golangci-lint on linux against linux and windows. golangci-linux: strategy: @@ -54,4 +54,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: v1.54 + version: v1.59 diff --git a/.golangci.yml b/.golangci.yml index 6104fd7..1a2df62 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,16 +5,8 @@ linters: enable-all: true disable: # deprecated - - maligned - - scopelint - - interfacer - - golint - - exhaustivestruct - - nosnakecase - - structcheck - - deadcode - - varcheck - - ifshort + - gomnd + - execinquery # unused - nlreturn - exhaustruct diff --git a/go.mod b/go.mod index a6af05c..69b15c0 100644 --- a/go.mod +++ b/go.mod @@ -24,6 +24,6 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/ulikunitz/xz v0.5.12 // indirect go4.org v0.0.0-20230225012048-214862532bf5 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/text v0.16.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index aa0a1f4..a887d6d 100644 --- a/go.sum +++ b/go.sum @@ -21,10 +21,6 @@ github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1 github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= github.com/bodgit/plumbing v1.3.0 h1:pf9Itz1JOQgn7vEOE7v7nlEfBykYqvUYioC61TwWCFU= github.com/bodgit/plumbing v1.3.0/go.mod h1:JOTb4XiRu5xfnmdnDJo6GmSbSbtSyufrsyZFByMtKEs= -github.com/bodgit/sevenzip v1.4.5 h1:HFJQ+nbjppfyf2xbQEJBbmVo+o2kTg1FXV4i7YOx87s= -github.com/bodgit/sevenzip v1.4.5/go.mod h1:LAcAg/UQzyjzCQSGBPZFYzoiHMfT6Gk+3tMSjUk3foY= -github.com/bodgit/sevenzip v1.5.0 h1:QESwnPUnhqftOgbi6wIiWm1WEkrT4puHukt5a2psEcw= -github.com/bodgit/sevenzip v1.5.0/go.mod h1:+E74G6pfBX8IMaVybsKMgGTTTBcbHU8ssPTJ9mLUr38= github.com/bodgit/sevenzip v1.5.1 h1:rVj0baZsooZFy64DJN0zQogPzhPrT8BQ8TTRd1H4WHw= github.com/bodgit/sevenzip v1.5.1/go.mod h1:Q3YMySuVWq6pyGEolyIE98828lOfEoeWg5zeH6x22rc= github.com/bodgit/windows v1.0.1 h1:tF7K6KOluPYygXa3Z2594zxlkbKPAOvqr97etrGNIz4= @@ -72,7 +68,6 @@ github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= @@ -82,14 +77,6 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X github.com/kdomanski/iso9660 v0.4.0 h1:BPKKdcINz3m0MdjIMwS0wx1nofsOjxOq8TOr45WGHFg= github.com/kdomanski/iso9660 v0.4.0/go.mod h1:OxUSupHsO9ceI8lBLPJKWBTphLemjrCQY8LPXM7qSzU= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.17.5 h1:d4vBd+7CHydUqpFBgUEKkSdtSugf9YFmSkvUYPquI5E= -github.com/klauspost/compress v1.17.5/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= -github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI= -github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= -github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg= -github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= -github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= -github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -115,14 +102,10 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/therootcompany/xz v1.0.1 h1:CmOtsn1CbtmyYiusbfmhmkpAAETj0wBIH6kCYaX+xzw= github.com/therootcompany/xz v1.0.1/go.mod h1:3K3UH1yCKgBneZYhuQUvJ9HPD19UEXEI0BWbMn8qNMY= -github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8= -github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc= github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= @@ -191,6 +174,7 @@ golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -218,8 +202,8 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/start.go b/start.go index 3eddac2..296293c 100644 --- a/start.go +++ b/start.go @@ -1,7 +1,7 @@ package xtractr import ( - "fmt" + "errors" "os" ) @@ -50,14 +50,14 @@ type Xtractr struct { // Custom errors returned by this module. var ( - ErrQueueStopped = fmt.Errorf("extractor queue stopped, cannot extract") - ErrNoCompressedFiles = fmt.Errorf("no compressed files found") - ErrUnknownArchiveType = fmt.Errorf("unknown archive file type") - ErrInvalidPath = fmt.Errorf("archived file contains invalid path") - ErrInvalidHead = fmt.Errorf("archived file contains invalid header file") - ErrQueueRunning = fmt.Errorf("extractor queue running, cannot start") - ErrNoConfig = fmt.Errorf("call NewQueue() to initialize a queue") - ErrNoLogger = fmt.Errorf("xtractr.Config.Logger must be non-nil") + ErrQueueStopped = errors.New("extractor queue stopped, cannot extract") + ErrNoCompressedFiles = errors.New("no compressed files found") + ErrUnknownArchiveType = errors.New("unknown archive file type") + ErrInvalidPath = errors.New("archived file contains invalid path") + ErrInvalidHead = errors.New("archived file contains invalid header file") + ErrQueueRunning = errors.New("extractor queue running, cannot start") + ErrNoConfig = errors.New("call NewQueue() to initialize a queue") + ErrNoLogger = errors.New("xtractr.Config.Logger must be non-nil") ) // NewQueue returns a new Xtractr Queue you can send Xtract jobs into. From e6d91613dfe546ba21179355dc51757c9b0041bb Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Sun, 30 Jun 2024 15:38:26 -0700 Subject: [PATCH 2/3] special type for archive list --- files.go | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/files.go b/files.go index a65e493..5b68cc3 100644 --- a/files.go +++ b/files.go @@ -11,6 +11,10 @@ import ( "strings" ) +// ArchiveList is the value returned when searchying for compressed files. +// The map is directory to list of archives in that directory. +type ArchiveList map[string][]string + type archive struct { // Extension is passed to strings.HasSuffix. Extension string @@ -174,11 +178,11 @@ func (e Exclude) Has(test string) bool { // so if the rar archive does not have "part" followed by a number in the name, then it will be // considered an independent archive. Some packagers seem to use different naming schemes, // so this may need to be updated as time progresses. Use the input to Filter to adjust the output. -func FindCompressedFiles(filter Filter) map[string][]string { +func FindCompressedFiles(filter Filter) ArchiveList { return findCompressedFiles(filter.Path, &filter, 0) } -func findCompressedFiles(path string, filter *Filter, depth int) map[string][]string { +func findCompressedFiles(path string, filter *Filter, depth int) ArchiveList { if filter.MaxDepth > 0 && filter.MaxDepth < depth { return nil } @@ -192,7 +196,7 @@ func findCompressedFiles(path string, filter *Filter, depth int) map[string][]st if info, err := dir.Stat(); err != nil { return nil // unreadable folder? } else if !info.IsDir() && isArchiveFile(path) { - return map[string][]string{path: {path}} // passed in an archive file; send it back out. + return ArchiveList{path: {path}} // passed in an archive file; send it back out. } fileList, err := dir.Readdir(-1) @@ -230,13 +234,8 @@ func checkR00ForRarFile(fileList []os.FileInfo, r00file string) bool { // getCompressedFiles checks file suffixes to find archives to decompress. // This pays special attention to the widely accepted variance of rar formats. -func getCompressedFiles( //nolint:cyclop - path string, - filter *Filter, - fileList []os.FileInfo, - depth int, -) map[string][]string { - files := map[string][]string{} +func getCompressedFiles(path string, filter *Filter, fileList []os.FileInfo, depth int) ArchiveList { //nolint:cyclop + files := ArchiveList{} for _, file := range fileList { switch lowerName := strings.ToLower(file.Name()); { @@ -444,3 +443,23 @@ func AllExcept(onlyThese []string) Exclude { return output } + +// Count returns the number of unique archives in the archive list. +func (a ArchiveList) Count() (count int) { + for _, files := range a { + count += len(files) + } + + return count +} + +// Random returns a random file listing from the archive list. +// If the list only contains one directory, then that is the one returned. +// If the archive list is empty or nil, returns nil. +func (a ArchiveList) Random() []string { + for _, files := range a { + return files + } + + return nil +} From b3091f767a0ef57d90d2c91dd1ad72c574b45297 Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Sun, 30 Jun 2024 15:57:58 -0700 Subject: [PATCH 3/3] nonamedreturns --- files.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/files.go b/files.go index 5b68cc3..f05cceb 100644 --- a/files.go +++ b/files.go @@ -445,7 +445,9 @@ func AllExcept(onlyThese []string) Exclude { } // Count returns the number of unique archives in the archive list. -func (a ArchiveList) Count() (count int) { +func (a ArchiveList) Count() int { + var count int + for _, files := range a { count += len(files) }