|
@@ -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)
|