|
@@ -3,10 +3,14 @@ package hash
|
|
import (
|
|
import (
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
|
|
+ "os"
|
|
"path/filepath"
|
|
"path/filepath"
|
|
|
|
+ "strings"
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+const FDHASHFILENAME = ".fdhashes3"
|
|
|
|
+
|
|
// Fdhashes struct for holding all informations about one folder.
|
|
// Fdhashes struct for holding all informations about one folder.
|
|
type Fdhashes struct {
|
|
type Fdhashes struct {
|
|
Path string
|
|
Path string
|
|
@@ -16,7 +20,18 @@ type Fdhashes struct {
|
|
}
|
|
}
|
|
|
|
|
|
func LoadHashfile(fileStr string) (*Fdhashes, error) {
|
|
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))
|
|
dir = filepath.ToSlash(filepath.Clean(dir))
|
|
var data Fdhashes
|
|
var data Fdhashes
|
|
file, err := ioutil.ReadFile(fileStr)
|
|
file, err := ioutil.ReadFile(fileStr)
|