Browse Source

removing pkg

Wilfried Klaas 2 years ago
parent
commit
135cf68514
2 changed files with 58 additions and 1 deletions
  1. 0 1
      .gitignore
  2. 58 0
      pkg/hash/hash.go

+ 0 - 1
.gitignore

@@ -1,6 +1,5 @@
 
 *.exe
-pkg
 src/github.com
 __debug_bin
 report.txt

+ 58 - 0
pkg/hash/hash.go

@@ -0,0 +1,58 @@
+package hash
+
+import (
+	"encoding/json"
+	"io/ioutil"
+	"path/filepath"
+	"time"
+)
+
+// Fdhashes struct for holding all informations about one folder.
+type Fdhashes struct {
+	Path   string
+	Hashes map[string]string
+	Times  map[string]time.Time
+	Dirty  bool
+}
+
+func LoadHashfile(fileStr string) (*Fdhashes, error) {
+	dir, _ := filepath.Split(fileStr)
+	dir = filepath.ToSlash(filepath.Clean(dir))
+	var data Fdhashes
+	file, err := ioutil.ReadFile(fileStr)
+	if err != nil {
+		return nil, err
+	}
+	err = json.Unmarshal([]byte(file), &data)
+	if err != nil {
+		return nil, err
+	}
+	if data.Path != dir {
+		data.Path = dir
+		data.Dirty = true
+	}
+	return &data, nil
+}
+
+/*
+func LoadHashfile(fileStr string) Fdhashes {
+	dir, _ := filepath.Split(fileStr)
+	dir = filepath.ToSlash(filepath.Clean(dir))
+	data := Fdhashes{Path: dir, Hashes: make(map[string]string), Times: make(map[string]time.Time), Dirty: false}
+	if !rewrite {
+		file, err := ioutil.ReadFile(fileStr)
+		if err != nil {
+			panic(err)
+		}
+		err = json.Unmarshal([]byte(file), &data)
+		if err != nil {
+			log.Printf("can't read file %s", fileStr)
+		}
+	}
+	if data.Path != dir {
+		data.Path = dir
+		data.Dirty = true
+	}
+	return data
+}
+*/