瀏覽代碼

Auto stash before merge of "develop" and "origin/develop"

Klaas, Wilfried 5 年之前
父節點
當前提交
41fffcafa6
共有 3 個文件被更改,包括 17 次插入19 次删除
  1. 3 2
      .vscode/launch.json
  2. 12 15
      GoHash.go
  3. 2 2
      build.cmd

+ 3 - 2
.vscode/launch.json

@@ -4,14 +4,15 @@
     // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
     "version": "0.2.0",
     "configurations": [
+
         {
-            "name": "Launch",
+            "name": "GoHash",
             "type": "go",
             "request": "launch",
             "mode": "auto",
             "program": "${fileDirname}",
             "env": {},
-            "args": ["e:\\temp\\Backup"]
+            "args": ["F:\\noShare\\pics"]
         }
     ]
 }

+ 12 - 15
GoHash.go

@@ -95,13 +95,13 @@ func outputHash(fileStr string) {
 
 	_, ok = hashFile.Hashes[fileName]
 	doHash = !ok
-	hashFile = hashes[dir]
 	mu.Unlock()
 	if doHash {
 		hash := getSha256Hash(fileStr)
 		mu.Lock()
 		hashFile.Hashes[fileName] = hash
-		saveHashfile(hashFile, dir)
+		hashes[dir] = hashFile
+		saveHashfile(hashFile)
 		mu.Unlock()
 		log.Printf("file \"%s\" has hash \"%s\"\n", fileStr, hash)
 	}
@@ -148,22 +148,19 @@ func saveHashfile(hashFile Fdhashes, dir string) {
 	}
 }
 
-func loadHashfile(filename string) Fdhashes {
-	data := Fdhashes{Hashes: make(map[string]string)}
-	if !rewrite {
-		file, err := ioutil.ReadFile(filename)
-		if err != nil {
-			panic(err)
-		}
-		err = json.Unmarshal([]byte(file), &data)
-		if err != nil {
-			panic(err)
-		}
+func loadHashfile(fileStr string) Fdhashes {
+	file, err := ioutil.ReadFile(fileStr)
+	if err != nil {
+		panic(err)
 	}
-	data := Fdhashes{}
+	dir, _ := filepath.Split(fileStr)
+	data := Fdhashes{Path: dir, Hashes: make(map[string]string)}
 	err = json.Unmarshal([]byte(file), &data)
 	if err != nil {
-		log.Fatalf("can't read file %s", filename)
+		log.Printf("can't read file %s", fileStr)
+	}
+	if data.Path == "" {
+		data.Path = dir
 	}
 	return data
 }

+ 2 - 2
build.cmd

@@ -1,3 +1,3 @@
-set GOPATH=%cd%
+@echo off
 go build -ldflags="-s -w" 
-copy GoHash.exe f:\
+copy GoHash.exe F:\