Browse Source

loading the fdhashes file

Wilfried Klaas 2 years ago
parent
commit
5ceca97546
1 changed files with 16 additions and 1 deletions
  1. 16 1
      pkg/hash/hash.go

+ 16 - 1
pkg/hash/hash.go

@@ -3,10 +3,14 @@ package hash
 import (
 	"encoding/json"
 	"io/ioutil"
+	"os"
 	"path/filepath"
+	"strings"
 	"time"
 )
 
+const FDHASHFILENAME = ".fdhashes3"
+
 // Fdhashes struct for holding all informations about one folder.
 type Fdhashes struct {
 	Path   string
@@ -16,7 +20,18 @@ type Fdhashes struct {
 }
 
 func LoadHashfile(fileStr string) (*Fdhashes, error) {
-	dir, _ := filepath.Split(fileStr)
+	fileInfo, err := os.Stat(fileStr)
+	if err != nil {
+		return nil, err
+	}
+	if fileInfo.IsDir() {
+		fileStr = filepath.Join(fileStr, FDHASHFILENAME)
+	}
+
+	dir, name := filepath.Split(fileStr)
+	if strings.ToLower(name) != FDHASHFILENAME {
+		fileStr = filepath.Join(dir, FDHASHFILENAME)
+	}
 	dir = filepath.ToSlash(filepath.Clean(dir))
 	var data Fdhashes
 	file, err := ioutil.ReadFile(fileStr)