Browse Source

minor changes ignorlist doesnt work anymore

Willie 2 months ago
parent
commit
1d8bf312ca
3 changed files with 21 additions and 8 deletions
  1. 1 1
      build.cmd
  2. 19 6
      cmd/main.go
  3. 1 1
      go.mod

+ 1 - 1
build.cmd

@@ -1,3 +1,3 @@
 del GoHash.exe
 go build -o GoHash.exe -ldflags="-s -w" cmd/main.go
-copy GoHash.exe G:\
+copy GoHash.exe v:\

+ 19 - 6
cmd/main.go

@@ -8,6 +8,7 @@ import (
 	"log"
 	"os"
 	"path/filepath"
+	"slices"
 	"sort"
 	"strings"
 	"sync"
@@ -257,8 +258,7 @@ func compareFolder(folder string) {
 				values = make([]string, 0)
 			}
 			filepath := fmt.Sprintf("%s/%s", hashFile.Path, filename)
-			pos := sort.SearchStrings(ignoreLines, filepath)
-			if pos == len(ignoreLines) {
+			if !contains(filepath) {
 				_, err := os.Stat(filepath)
 				if err == nil {
 					values = append(values, filepath)
@@ -320,7 +320,7 @@ func compareFolder(folder string) {
 			fmt.Println(err)
 			return
 		}
-		err = ioutil.WriteFile(report, b, 0644)
+		err = os.WriteFile(report, b, 0644)
 		if err != nil {
 			panic(err)
 		}
@@ -356,11 +356,24 @@ func compareFolder(folder string) {
 	}
 }
 
+func contains(filepath string) bool {
+	return slices.Contains(ignoreLines, strings.ToLower(filepath))
+}
+
 func loadIgnoreFile(filename string) {
-	content, err := ioutil.ReadFile(filename)
+	content, err := os.ReadFile(filename)
 	if err == nil {
-		ignoreLines = strings.Split(string(content), "\n")
-		sort.Strings(ignoreLines)
+		lines := strings.Split(string(content), "\n")
+		ignoreLines = make([]string, 0)
+		for _, line := range lines {
+			line = strings.TrimSpace(line)
+			line = strings.ToLower(line)
+			line, _ = strings.CutSuffix(line, "\r")
+			if line != "" {
+				ignoreLines = append(ignoreLines, line)
+			}
+		}
+		slices.Sort(ignoreLines)
 	}
 }
 

+ 1 - 1
go.mod

@@ -2,7 +2,7 @@ module wkla.no-ip.biz/gogs/Willie/GoHash
 
 // github.com/willie/gohash
 
-go 1.17
+go 1.21
 
 require (
 	code.cloudfoundry.org/bytefmt v0.0.0-20211005130812-5bb3c17173e5